Archive for category linux 服务器安装

pptpd 源代码安装

wget http://www.sfr-fresh.com/linux/misc/pptpd-1.3.4.tar.gz
tar ..
./configure && make && make install
cp samples/pptpd.conf /etc/.
cp samples/options.pptpd /etc/ppp/.
cp samples/chap-secrets /etc/ppp/.
cp pptpd.init /etc/rc.d/init.d/pptpd
chmod +x /etc/rc.d/init.d/pptpd
/etc/rc.d/init.d/pptpd start
编辑/etc/sysctl.conf,看一下net.ipv4.ip_forward参数是不是1。
改完一个sysctl -p一下

iptables -A INPUT -p tcp –dport 1723 -j ACCEPT

iptables -A INPUT -p tcp –dport 47 -j ACCEPT

iptables -A INPUT -p gre -j ACCEPT

iptables -t nat -A POSTROUTING -s 192.168.8.0/24 -o eth0 -j MASQUERADE

完成后输入/etc/init.d/iptables save保存,并且输入/etc/init.d/iptables restart重新启动。

我连接的时候出现了vpn 619错误,查了一下是路由器nat -t上pptp nat穿透选项的问题,但是我另外一个vpn是可以用的,所以我还需要研究一下为什么另外一个能用!

可能是服务器的机房路由器没有开启pptp的通过,我已经open ticket让他们开了,看看开了以后会不会就好了!

No Comments

varnish 设置header和forward IP设置问题

What is the purpose of the X-Varnish HTTP header?

The X-Varnish HTTP header allows you to find the correct log-entries for the transaction. For a cache hit, X-Varnish will contain both the ID of the current request and the ID of the request that populated the cache. It makes debugging Varnish a lot easier.

Does Varnish support compression?

This is a simple question with a complicated answer; see WIKI.

How do I add a HTTP header?

To add a HTTP header, unless you want to add something about the client/request, it is best done in vcl_fetch as this means it will only be processed every time the object is fetched:

sub vcl_fetch {
  # Add a unique header containing the cache servers IP address:
  remove obj.http.X-Varnish-IP;
  set    obj.http.X-Varnish-IP = server.ip;
  # Another header:
  set    obj.http.Foo = "bar";
}

How can I log the client IP address on the backend?

All I see is the IP address of the varnish server. How can I log the client IP address?

We will need to add the IP address to a header used for the backend request, and configure the backend to log the content of this header instead of the address of the connecting client (which is the varnish server).

Varnish configuration:

sub vcl_recv {
  # Add a unique header containing the client address
  remove req.http.X-Forwarded-For;
  set    req.http.X-Forwarded-For = client.ip;
  # [...]
}

For the apache configuration, we copy the “combined” log format to a new one we call “varnishcombined”, for instance, and change the client IP field to use the content of the variable we set in the varnish configuration:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined

And so, in our virtualhost, you need to specify this format instead of “combined” (or “common”, or whatever else you use):

<VirtualHost *:80>
  ServerName www.example.com
  # [...]
  CustomLog /var/log/apache2/www.example.com/access.log varnishcombined
  # [...]
</VirtualHost>

No Comments

/usr/bin/ld: cannot find -lltdl php安装错误,libmcrypt编译问题

/usr/bin/ld: cannot find -lltdl

/usr/bin/ld: cannot find -lltdl
安装php make的时候提示如下出错信息:
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1
解决方法:这是因为找不到:   libltdl库文件

ldconfig -p |grep ltdl
#/software/libmcrypt-2.5.8/libltdl
#./configure  –enable-ltdl-install
#make
#make install
以下是原文:
Then I visited
http://mcrypt.hellug.gr/mcrypt/index.html
an learned that I have to install not only libmcrypt
but also mcrypt and libmhash.
Here is the to do:
libmcrytp:
———–
download libmcrypt-xxx.tar.gz
create the following directory:  / usr / local / libmcrypt
copy the libmcrypt-xxx.tar.gz into that directory and move to it
run the following shell (>) commands:  (‘xxx’ is the version number)
> gunzip -c libmcrypt-xxx.tar.gz | tar xf -
> cd libmcrypt-xxx
> ./configure –disable-posix-threads
> make
> make check  (note:  ‘make check’ is optional)
> make install
then (update your environment) add in / etc / profile the following path:
/usr/local/libmcrypt/libmcrypt-xxxx
(note:  as I run Red Hat 7.3 I  set the line   a f t e r   the if-part
(id -u = 0 …) with: pathmunge /usr/local / libm….)
and add in / etc / ld.so.conf the following path:  /usr/local/lib
then run ldconfig:
> ldconfig
now comes the important part:
> cd /usr/local/libmcrypt/libmcrypt-xxx/libltdl
> ./configure –enable-ltdl-install
> make
> make install
(maybe not needed:  I also added a link in / usr / bin: )
(> cd /usr/bin)
(> ln -s /usr/lib/libltdl.so.3.1.0 ltdl)

No Comments

linux一些常用指令

1.按内存从大到小排列进程:
ps -eo “%C : %p : %z : %a”|sort -k5 -nr

2.查看当前有哪些进程;查看进程打开的文件:
ps -A ;lsof -p PID

3.获取当前IP地址(从中学习grep,awk,cut的作用)
ifconfig eth0 |grep “inet addr:” |awk ‘{print $2}’|cut -c 6-

4.统计每个单词出现的频率,并排序
awk ‘{arr[$1]+=1 }END{for(i in arr){print arr”\t”i}}’ 文件名 | sort -rn

5.显示10条最常用的命令
sed -e “s/| /\n/g” ~/.bash_history | cut -d ‘ ‘ -f 1 | sort | uniq -c | sort -nr | head Read the rest of this entry »

No Comments

varnish 2.x启动指令和配置

Varnish 2.0.3 has just been released. This release contains multiple changes, amongst them:

  • Support for backend timeouts
  • Multiple fixes in how we process ESI
  • restart in vcl_hit is now supported
  • Documentation has been updated
  • Expiry processing is now more scalable
  • The default session workspace is now 16k instead of 8k
  • More graceful handling of too many headers from the client or the server.
  • More expressive purges

之前一直使用的还是2.0的一个trunk的R2860版本,因为只有这个版本我从1.1.2升级上来以后没有慢的问题⊙﹏⊙。但是看着新版却一直不能用,实在是让人心里痒。于是抱着死磕到底的态度,在检查了n+1遍配置文件和修改启动参数重启了n+1遍Varnish以后终于找到了问题的所在,即启动参数的-w这个上面。那么这个参数是干什么用的呢?

    -w int[,int[,int]]           # Number of worker threads
                                 #   -w <fixed_count>
                                 #   -w min,max
                                 #   -w min,max,timeout [default: -w2,500,300]

可以看出这个参数是控制每个进程的线程数的,1.1.2版本的时候这个参数我配置的是-w30000,51200,10,貌似到了2.0版以后这个最小启动的线程数不能设定过大,于是在进行了几次调试以后最终将参数定为了-w5,51200,30

软件列表
pcre-8.02.tar.gz
varnish-2.1.tar.gz

软件存放位置
/data/software

安装过程
# /usr/sbin/groupadd www -g 48
# /usr/sbin/useradd -u 48 -g www www
# mkdir -p /data/vcache
# chmod +w /data/vcache
# chown -R www:www /data/vcache
# mkdir -p /var/log/varnish
# chmod +w /var/log/varnish
# chown -R www:www /var/log/varnish
# cd /data/software/pkg
# tar zxvf ../pcre-8.02.tar.gz
# cd pcre-8.02
# ./configure
# make && make install
# cd ..
# tar zxvf ../varnish-2.1.tar.gz
# cd varnish-2.1
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# ./configure –prefix=/usr/local/varnish
# make && make install

编辑Varnish配置文件
# vi /usr/local/varnish/vcl.conf

backend webserver {
       set backend.host = “10.10.10.8″;
       set backend.port = “80″;
}

acl purge {
       “localhost”;
       “127.0.0.1″;
       “10.10.10.0″/24;
}

sub vcl_recv {
        remove req.http.X-Forwarded-For;
        set    req.http.X-Forwarded-For = client.ip;
        if (req.request == “PURGE”) {
               if (!client.ip ~ purge) {
                       error 405 “Not allowed.”;
               }
               lookup;
       }

       if (req.http.host ~ “(a|b|c).test.com”) {
               set req.backend = webserver;
              if (req.url ~ “\.(png|gif|jpg|swf|css|js)$”) {
                       lookup;
        }
               else {
                       pass;
               }
       }

       else {
               error 404 “Test Cache Server”;
               pipe;
       }
}

sub vcl_hash {
    set req.hash += req.url;
    if (req.http.host) {
        set req.hash += req.http.host;
    } else {
        set req.hash += server.ip;
    }
    hash;
}

sub vcl_pipe {
        set req.http.connection = “close”;
        #pipe;
}

sub vcl_hit {
        if (!obj.cacheable) {
                pass;
        }
       if (req.request == “PURGE”) {
               set obj.ttl = 0s;
               error 200 “Purged.”;
       }
        deliver;
}

sub vcl_miss {
       if (req.request == “PURGE”) {
               error 404 “Not in cache.”;
       }
}

sub vcl_fetch {
               set obj.ttl = 180s;
               #set    obj.http.X-Varnish-IP = server.ip;
               set    obj.http.Varnish = “Tested by Kevin”;
}

启动Varnish
# /usr/local/varnish/sbin/varnishd -n /data/vcache -f /usr/local/varnish/etc/varnish/default.vcl -a 10.10.10.8:80 -s file,/data/vcache/varnish_cache.data,50G -u www -w2,65536,60 -T 127.0.0.1:3600 -p thread_pool_min=200 -p thread_pool_max=4000 -p thread_pools=4 -p thread_pool_add_delay=2 -p listen_depth=4096 -p lru_interval=20

启动日志记录
#/usr/local/varnish/bin/varnishncsa -n /data/vcache -w /var/log/varnish/varnish.log &

No Comments

php-fpm vs nginx vs unix socket

nginx修改
fastcgi_pass unix:/tmp/nginx.socket;

php-fpm.conf修改
listen = /tmp/nginx.socket
重启php-fpm 重启nginx 搞定。。不过不知道能有多大改善。。难说。。。。

No Comments

php-fpm vs php 5.3+ 启动指令

php-5.3.2/sapi/fpm/init.d.php-fpm

这个东西在源始代码里面,copy出来用就可以了,这个脚本可以start stop reload fpm就和5.2+的那个脚本一样了!

No Comments

编译php-fpm cgi模式

./configure –prefix=/usr/local/php –with-mysqli=/usr/local/mysql/bin/mysql_config –with-mysql=/usr/local/mysql –with-config-file-path=/usr/local/php/etc –with-curl –with-zlib –enable-ftp  –with-mcrypt –enable-inline-optimization –disable-debug –with-gd –enable-gd-native-ttf –enable-gd-jis-conv –with-iconv-dir=/usr/local –with-freetype-dir=/usr/local/lib/freetype –with-jpeg-dir=/usr/local –with-png-dir=/usr/local –with-zlib –with-libxml-dir=/usr/local/lib/libxml –enable-xml –enable-exif –enable-soap –enable-zip –with-openssl –enable-mbstring –with-mhash –with-tidy –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring

make ZEND_EXTRA_LIBS=’-liconv’

make install

No Comments

libtidy 安装

  • wget http://tidy.sourceforge.net/src/old/tidy_src_051026.tgz
  • gunzip tidy-xxxx.tgz
  • tar -xvf tidy-xxxx.tar
  • cd tidy
  • sh build/gnuauto/setup.sh
  • 按照提示装就行了!

    No Comments

    Squid3.0与2.7的配置差异

    Squid3.0最重要的新特性:

    • Code converted to C++, with significant internal restructuring and rewrites.
    • ICAP implementation (RFC 3507 and www.icap-forum.org)
    • Edge Side Includes (ESI) implementation (www.esi.org)

    更多的请参考官方说明

    来说说配置方法的不同之处(只说我自己实际使用的)

    ./configure的配置项

    ./configure –prefix=/usr/local/squid –with-large-files –enable-useragent-log –enable-referer-log –enable-linux-netfilter –enable-x-accelerator-vary –disable-internal-dns –disable-mempools –with-maxfd=65535

    3.0版本去掉了以下选项:

    –enable-dlmalloc    不再需要 Read the rest of this entry »

    No Comments

    如何关闭Squid的Cache功能!

    1、编译的时候添加null的文件系统:
    –enable-storeio=null,(Others)

    2、在squid.conf设置:
    cache_dir null /tmp

    No Comments

    squid 多ip配置

    if (! ($tokens[1] =~ "127.0.0.1")) {

    11        push(@acls, "acl ip$count myip $tokens[1]\n");
    12        push(@tcps, "tcp_outgoing_address $tokens[1] ip$count\n");
    13        $count++;
    14     }

    看懂这个,打在squid.conf里面,就搞定了!!很简单

    No Comments

    关于多ip路由的例子

    http://uddtm.com/os/linux/duoxianluyoucelue.php

    No Comments

    libmemcached 安装报错 解决

    clients/ms_conn.o: In function `ms_get_udp_request_id’:
    /root/soft/phpmodel/libmemcached-0.42/clients/ms_conn.c:194: undefined reference to `__sync_fetch_and_add_4′
    clients/ms_conn.o: In function `ms_reconn_socks’:
    /root/soft/phpmodel/libmemcached-0.42/clients/ms_conn.c:1051: undefined reference to `__sync_fetch_and_add_4′
    clients/ms_conn.o: In function `ms_reconn’:
    /root/soft/phpmodel/libmemcached-0.42/clients/ms_conn.c:919: undefined reference to `__sync_fetch_and_add_4′
    /root/soft/phpmodel/libmemcached-0.42/clients/ms_conn.c:956: undefined reference to `__sync_fetch_and_add_4′
    clients/ms_thread.o: In function `ms_setup_thread’:
    /root/soft/phpmodel/libmemcached-0.42/clients/ms_thread.c:225: undefined reference to `__sync_fetch_and_add_4′
    clients/ms_thread.o:/root/soft/phpmodel/libmemcached-0.42/clients/ms_thread.c:208: more undefined references to `__sync_fetch_and_add_4′ follow
    collect2: ld returned 1 exit status
    make[2]: *** [clients/memslap] Error 1
    make[2]: Leaving directory `/root/soft/phpmodel/libmemcached-0.42′
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/root/soft/phpmodel/libmemcached-0.42′
    make: *** [all] Error 2

    用这个语句

    ./configure -disable-64bit CFLAGS=”-O3 -march=i686″

    就可以了

    No Comments

    ss5架设

    yum -y install pam-devel openldap-devel cyrus-sasl-devel

    需要BerkeleyDb
    openladap
    ss5.tar.gz..

    一个一个编译完毕以后,修改/etc/opt/ss5.conf
    auth    0.0.0.0/0               -              u
    permit u 0.0.0.0/0 – 0.0.0.0/0 – - ulimit – -
    修改ss5.passwd文件加入
    username password
    添加ulimit 文件
    ulimit里面写上username

    mv /usr/lib/ss5/mod_socks4.so /usr/lib/ss5/mod_socks4.so.bk

    启动/etc/rc.d/init.d/ss5 restart

    No Comments

    多IP应用

    可以加一条指定源地址的路由来试试:
    假定 指定使用1.1.1.2地址, 其所在的子接口为eth1:0 则
    route add <目标网段/主机> gw <网关> dev eth1:0

    如果是多网卡绑同网段ip也一样, 将dev后面的eth1:0换成 eth1 (假定1.1.1.2绑在eth1网卡上).

    No Comments

    linux服务器查看cpu 内存相关信息

    转帖:

    测试机器的硬件信息:

    查看CPU信息(型号)
    # cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
          8  Intel(R) Xeon(R) CPU            E5410   @ 2.33GHz
    (看到有8个逻辑CPU, 也知道了CPU型号)
    Read the rest of this entry »

    No Comments

    nginx ip 传递给apache remote_add..

    http://stderr.net/apache/rpaf/download/

    编译吗。。用这个

    Read the rest of this entry »

    No Comments

    apache cassandra在php上的一些应用

    http://github.com/mjpearson/Pandra/downloads

    Dependencies

            * Cassandra >= 0.6

            * Thrift Interface (tested cassandra.thrift and pre-generated files are packaged)

            * PHP >= 5.3

            * OSSP PHP-UUID module

            – Optional

                * Model Generation – syck yaml

                * Caching – APC or Memcached (PECL)

                * Logging – Syslog, Sendmail and FirePHP
    http://incubator.apache.org/cassandra/

    No Comments

    GraphicsMagick 安装使用

    淘宝用于图片resize和水印的工具不是imagemagick而是graphicsmagick,效率据说高一些,我们来试试

    download : http://www.graphicsmagick.org/download.html

    下载.tar.gz文件 Read the rest of this entry »

    No Comments