Nginx在LAMP上的扩充


Nginx在LAMP上的扩充
 
在原来搭建好LAMP的基础上安装nginx
 
[root@localhost nginx-1.0.15]# yum install libxslt-devel
 
[root@localhost ~]# tar xf pcre-8.33.tar.gz -C /usr/src/
 
[root@localhost ~]# cd /usr/src/pcre-8.33/
[root@localhost pcre-8.33]# ./configure && make && make install
 
[root@localhost nginx-1.0.15]# wget http://nginx.org/download/nginx-1.0.15.tar.gz
 
[root@localhost nginx-1.0.15]# ./configure --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --user=daemon --group=daemon --with-rtsig_module --with-select_module --with-poll_module --with-ipv6 --with-http_ssl_module --with-http_realip_module  --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_gzip_static_module --with-http_flv_module --with-http_perl_module --with-perl=/usr/bin/perl --http-log-path=/var/log/nginx/access.log --with-pcre --with-pcre=/usr/src/pcre-8.33/  --with-http_stub_status_module
 
[root@localhost nginx-1.0.15]# make && make install
 
[root@localhost conf]# vi /usr/local/nginx/conf/nginx.conf
 
 
 
 
 
user  daemon;
worker_processes  1;
error_log  /var/log/nginx/error.log  info;
pid        /var/run/nginx/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        charset gb2312;
        access_log  /var/log/nginx/access.log  main;
        location / {
            root   /www;
            index  index.html index.htm;
        }
        error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /www;
        }
       
        location ~ \.php$ {
            root           /www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www$fastcgi_script_name;
            include        fastcgi_params;
        }
      
    }
 
[root@localhost nginx]# cd sbin/
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# ./nginx 
[root@localhost sbin]# lsof -i:80
COMMAND   PID   USER   FD   TYPE DEVICE SIZE NODE NAME
nginx   14359   root    6u  IPv4  21618       TCP *:http (LISTEN)
nginx   14360 daemon    6u  IPv4  21618       TCP *:http (LISTEN)
[root@localhost sbin]# pwd
/usr/local/nginx/sbin
 
 
 
 
 
 
 
PHP安装
 
[root@localhost ~]# tar xf /softs/php-5.3.27.tar.bz2 -C /usr/src/
 
[root@localhost php-5.3.27]# ./configure --disable-ipv6 --with-libxml-dir=/usr --with-openssl=/usr --with-pcre-regex=/usr/local  --with-zlib=/usr --with-bz2=/usr --enable-calendar --with-curl=/usr --with-pcre-dir=/usr/local --enable-ftp --with-openssl-dir=/usr --with-gd=/usr/local --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-zlib-dir=/usr/local --with-xpm-dir=/usr --with-freetype-dir=/usr/local --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash=/usr/local --enable-mbstring --with-mcrypt=/usr/local --with-mysql=/usr/local/mysql --with-mysql-sock=/var/run/mysqld/mysql5.socket --with-mysqli=/usr/local/mysql/bin/mysql_config --with-snmp=/usr --enable-sockets --enable-zip   && make && make install
 
 
 
[root@localhost cgi]# ./php-cgi -a -b 127.0.0.1:9000 -c /usr/local/lib/php.ini &
[2] 9879
[1]   宸叉姝?              ./php-cgi -a -b 127.0.0.1:9000 -c /usr/local/lib/php.ini
 
[root@localhost cgi]# pwd
/usr/src/php-5.3.27/sapi/cgi
 
访问 127.0.0.1/index.php
 
现在只有一个php-cgi进程,当大量的并发请求时,这是不够的。所以我用压力测试软件http_load测试一下
 
[root@localhost softs]# wget http://icn.me/http_load_tar_gz
 
[root@localhost http_load-12mar2006]# make && make install
 
[root@localhost www]# http_load -parallel 100 -seconds 10 url.txt 
 
http://192.168.254.153/a.php: byte count wrong
http://192.168.254.153/a.php: byte count wrong
http://192.168.254.153/a.php: byte count wrong
http://192.168.254.153/a.php: byte count wrong
http://192.168.254.153/a.php: byte count wrong
30431 fetches, 100 max parallel, 5.06531e+06 bytes, in 10 seconds
166.452 mean bytes/connection
3043.1 fetches/sec, 506531 bytes/sec
msecs/connect: 0.272351 mean, 137.327 max, 0.012 min
msecs/first-response: 17.6569 mean, 3034.86 max, 0.097 min
29934 bad byte counts
HTTP response codes:
  code 200 -- 497
  code 404 -- 29934
 
当并发数为100时,挂掉了,所以我们需要差生多个php-cgi进程,这里引入一个工具spqwn-fcgi
 
[root@localhost spawn-fcgi-1.6.3]# wget http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.3.tar.gz
 
[root@localhost spawn-fcgi-1.6.3]# tar xf spawn-fcgi-1.6.3.tar.gz 
[root@localhost spawn-fcgi-1.6.3]# cd spawn-fcgi-1.6.3
[root@localhost spawn-fcgi-1.6.3]# ./configure && make && make install
 
[root@localhost src]# spawn-fcgi -f /usr/local/bin/php
spawn-fcgi: no socket given (use either -p or -s)
[root@localhost src]# spawn-fcgi -f /usr/local/bin/php-cgi -a 127.0.0.1 -u daemon -p 9000 -C 150
spawn-fcgi: child spawned successfully: PID: 11498
[root@localhost src]# ps -e | grep php | wc
    151     604    4832
 
[root@localhost www]# http_load -parallel 100 -seconds 10 url.txt 
33289 fetches, 100 max parallel, 432757 bytes, in 10 seconds
13 mean bytes/connection
3328.9 fetches/sec, 43275.7 bytes/sec
msecs/connect: 0.0322589 mean, 0.809 max, 0.024 min
msecs/first-response: 29.9192 mean, 117.142 max, 8.778 min
HTTP response codes:
  code 200 -- 33289

相关内容

    暂无相关文章