Nginx负载均衡搭建胜过Apache十倍(2)
输入以下内容:
| kernel.shmmax = 134217728 |
然后执行以下命令使配置生效:
| /sbin/sysctl -p |
7、创建www用户和组,以及供blog.s135.com和www.s135.com两个虚拟主机使用的目录:
| /usr/sbin/groupadd www -g 48 /usr/sbin/useradd -u 48 -g www www mkdir -p /data0/htdocs/blog chmod +w /data0/htdocs/blog chown -R www:www /data0/htdocs/blog mkdir -p /data0/htdocs/www chmod +w /data0/htdocs/www chown -R www:www /data0/htdocs/www |
8、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
| 在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件: rm -f /usr/local/webserver/php/etc/php-fpm.conf vi /usr/local/webserver/php/etc/php-fpm.conf |
输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的<value name="display_errors">0</value>改为<value name="display_errors">1</value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页):
|
All relative paths in this config are relative to php's install prefix <section name="global_options"> Pid file Error log file Log level When this amount of php processes exited with SIGSEGV or SIGBUS ... ... in a less than this interval of time, a graceful restart will be initiated. Time limit on waiting child's reaction on signals from master Set to 'no' to debug fpm </section> <workers> <section name="pool"> Name of pool. Used in logs and stats. Address to accept fastcgi requests on. <value name="listen_options"> Set listen(2) backlog Set permissions for unix socket, if one used. Additional php.ini defines, specific to this pool of workers. Unix user of processes Unix group of processes Process manager settings Sets style of controling worker process count. Sets the limit on the number of simultaneous requests that will be served. Settings group for 'apache-like' pm style Sets the number of server processes created on startup. Sets the desired minimum number of idle server processes. Sets the desired maximum number of idle server processes. </value> </value> Time limit on waiting execution of single request Set open file desc rlimit Set max core size rlimit Chroot to this directory at the start Chdir to this directory at the start Redirect workers' stdout and stderr into main error log. How much requests each process should execute before respawn. Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect. Pass environment variables like LD_LIBRARY_PATH </section> </workers> </configuration> |

9、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程),用户为www:
| ulimit -SHn 51200 /usr/local/webserver/php/sbin/php-fpm start |
注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。
安装、配置Nginx 0.7.14
三、安装Nginx 0.7.14
1、安装Nginx所需的pcre库:
| tar zxvf pcre-7.7.tar.gz cd pcre-7.7/ ./configure make && make install cd ../ |
2、安装Nginx
| tar zxvf nginx-0.7.14.tar.gz cd nginx-0.7.14/ ./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module make && make install cd ../ |
3、创建Nginx日志目录
| mkdir -p /data1/logs chmod +w /data1/logs chown -R www:www /data1/logs |
4、创建Nginx配置文件
| ①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件: rm -f /usr/local/webserver/nginx/conf/nginx.conf vi /usr/local/webserver/nginx/conf/nginx.conf |
输入以下内容:
|
#limit_zone crawler $binary_remote_addr 10m; server #limit_conn crawler 20; location ~ .*\.(php|php5)?$ 顶(2)
踩(0)
|
