Nginx (”engine x”) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor
nginx IP 192.168.1.100 php1 IP 192.168.1.200 php2 IP 192.168.1.201
# tar zxvf libunwind-0.99-alpha.tar.gz # cd libunwind-0.99-alpha/ # CFLAGS=-fPIC ./configure # make CFLAGS=-fPIC # make CFLAGS=-fPIC install
# tar zxvf google-perftools-0.97.tar.gz # cd google-perftools-0.97/ # ./configure # make && make install # echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf # /sbin/ldconfig
# tar -zxvf pcre-8.10.tar.gz # cd pcre-8.10 # ./configure # make && make install
# tar -zxvf nginx-0.8.53.tar.gz # cd nginx-0.8.53 # ./configure --prefix=/usr/local/nginx # make && make install
# /usr/local/nginx/sbin/nginx
# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
# echo "/usr/local/nginx/sbin/nginx">>/etc/rc.local
user nobody; worker_processes 8; pid /usr/local/nginx/logs/nginx.pid; google_perftools_profiles /var/tmp/tcmalloc; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http{ include mime.types; default_type application/octet-stream; access_log off; error_log /dev/null; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 120; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { server_name _; #default #return 500; rewrite ^/(.*)$ /50x.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include vhost/*.conf; }
upstream lbcgi { ip_hash; server 192.168.1.200:9000; server 192.168.1.201:9000; } server { listen 80; server_name www.test.com; index index.html index.htm index.php; root /var/www/bbs/; location /nginx { stub_status on; auth_basic "NginxStatus"; access_log off; } location ~ .*\.(php|php5)?$ { fastcgi_pass lbcgi; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/bbs$fastcgi_script_name; include fastcgi_params; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } # log_format access '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" $http_x_forwarded_for'; # access_log /usr/local/nginx/logs/access.log access; }
# lsof -n|grep tcmalloc
nginx 4322 www 10w REG 8,2 0 682436 /var/tmp/tcmalloc.4322 nginx 4323 www 12w REG 8,2 0 682438 /var/tmp/tcmalloc.4323 nginx 4324 www 14w REG 8,2 0 682439 /var/tmp/tcmalloc.4324 nginx 4325 www 16w REG 8,2 0 682440 /var/tmp/tcmalloc.4325 nginx 4326 www 18w REG 8,2 0 682441 /var/tmp/tcmalloc.4326 nginx 4327 www 20w REG 8,2 0 682442 /var/tmp/tcmalloc.4327 nginx 4328 www 22w REG 8,2 0 682443 /var/tmp/tcmalloc.4328 nginx 4329 www 24w REG 8,2 0 682444 /var/tmp/tcmalloc.4329
#!/bin/bash # Startup script for the nginx Web Server # chkconfig: - 85 15 # description: nginx is a World Wide Web server. It is used to serve # HTML files and CGI. # processname: nginx # pidfile: /usr/local/www/nginx/logs/nginx.pid # config: /usr/local/www/nginx/conf/nginx.conf PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH NGINX_HOME=/usr/local/www/nginx/sbin NGINX_CONF=/usr/local/www/nginx/conf if [ ! -f "$NGINX_HOME/nginx" ] then echo "nginxserver startup: cannot start" exit fi case "$1" in 'start') $NGINX_HOME/nginx -c $NGINX_CONF/nginx.conf echo "nginx start successful" ;; 'stop') killall -TERM nginx ;; esac
# chmod a+x /etc/rc.d/init.d/nginx # chkconfig --add nginx # chkconfig nginx on
# vi /etc/export
/var/www/bbs 192.168.1.200(rw,sync,no_root_squash),192.168.1.201(rw,sync,no_root_squash)
# service portmap restart # service nfs restart
# mount 192.168.1.100:/var/www/bbs /var/www/bbs
eaccelerator-0.9.6.tar.bz2 gd-2.0.35.tar.gz mysql-5.1.52.tar.gz php-5.2.14.tar.bz2 php-fpm-0.6-5.2.11.tar.gz ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz libevent-1.4.13-stable.tar.gz libiconv-1.13.1.tar.gz
bzip2-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel openssl-devel libxml2-devel gettext-devel
# tar -zxvf mysql-5.1.52.tar.gz # cd mysql-5.1.51 # groupadd mysql # useradd -g mysql -s /sbin/nologin -M mysql # ./configure --prefix=/usr/local/www/mysql --with-charset=gbk --with-extra-charsets=all --enable-thread-safe-client # make && make install
# tar -jxvf gd-2.0.35.tar.bz2 # cd gd-2.0.35 # ./configure --prefix=/usr/local/www/gd --with-png --with-freetype --with-jpeg --with-zlib --with-fontconfig # make # make install
# tar -zxvf autoconf-2.13.tar.gz # cd autoconf-2.13 # ./configure --prefix=/usr/local/www/autoconf # make # make install # export PHP_AUTOCONF=/usr/local/www/autoconf/bin/autoconf # export PHP_AUTOHEADER=/usr/local/www/autoconf/bin/autoheader
# tar zxvf libevent-1.4.13-stable.tar.gz # cd libevent-1.4.13-stable/ # ./configure --prefix=/usr/local/www/libevent # make && make install
# tar zxvf libiconv-1.13.1.tar.gz # cd libiconv-1.13.1/ # ./configure --prefix=/usr/local/www/libiconv # make && make install
# tar zxvf php-5.2.14.tar.gz # tar zxvf php-fpm-0.6~5.2.11.tar.gz # php-fpm-0.6-5.2.11/generate-fpm-patch # cd php-5.2.14/ # patch -p1 < ../fpm.patch # ./buildconf --force # ./configure --prefix=/usr/local/www/php --with-config-file-path=/usr/local/www/php --with-mysql=/usr/local/www/mysql/ --with-config-file-path=/usr/local/php --with-gd=/usr/local/www/gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-xpm-dir --with-gettext --enable-fastcgi --with-fpm --with-zlib --enable-force-cgi-redirect --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-zip --enable-mbstring --enable-pcntl --enable-sockets --enable-soap --without-pear --with-libevent=/usr/local/www/libevent/ --with-iconv-dir=/usr/local/www/libiconv # make # make install # cp php.ini-dist /usr/local/www/php/php.ini
(1)127.0.0.1:9000 修改为IP:9000 //这里写本机的ip (2)下面这两行去掉注释并修改/usr/sbin/sendmail -t -i 1 (3)nobody //去注释 (4)nobody //去注释 (5)127.0.0.1 //允许连接的PC,写前端nginx服务器的ip 192.168.1.100 (6)128 (7)20 (8)5 (9)35 (10)51200 (11)102400
# ulimit -SHn 51200 # /usr/local/www/php/bin/php-fpm start
# echo "ulimit -SHn 51200">>/etc/rc.local # echo "/usr/local/www/php/sbin/php-fpm start">>/etc/rc.local
# tar jxvf eaccelerator-0.9.5.3.tar.bz2 # cd eaccelerator-0.9.5.3 # /usr/local/www/php/bin/phpize # ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/www/php/bin/php-config # make # make install
[eaccelerator] zend_extension="/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" eaccelerator.shm_size="32" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="1800" eaccelerator.shm_prune_period="1800" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9"
# mkdir /tmp/eaccelerator # chmod 777 /tmp/eaccelerator
This program makes use of the Zend Scripting Language Engine: Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
# tar zxvf ZendOptimizer-3.3.9-linux-glibc21-i386.tar.gz # cd ZendOptimizer-3.3.9-linux-glibc23-i386 # cp data/5_2_x_comp/ZendOptimizer.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
zend_extension="/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so"
This program makes use of the Zend Scripting Language Engine: Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
# tar zxvf PDO_MYSQL-1.0.2.tgz # cd PDO_MYSQL-1.0.2/ # /usr/local/www/php/bin/phpize # ./configure --with-php-config=/usr/local/www/php/bin/php-config --with-pdo-mysql=/usr/local/www/mysql # make # make install
zend_extension="/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so"
net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 30 net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 5000 65000 net.ipv4.tcp_max_syn_backlog = 10240 net.ipv4.tcp_max_tw_buckets = 10240
* soft nofile 51200 * hard nofile 102400