LNMP架構四
阿新 • • 發佈:2018-02-13
lena tro cal pid proc spa 一個 class script
php-fpm的pool(連接池)
我們查看php的進程時,會發現,在最後一個pool的選項,而這個就是我們在php-fpm配置文件裏寫的一個連接池。
[root@bogon linux.com]# vim /usr/local/php-fpm/etc/php-fpm.conf [root@bogon linux.com]# [root@bogon linux.com]# ps aux|grep php root 3068 0.0 0.0 227144 228 ? Ss 2月11 0:10 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 3114 0.0 0.0 229228 124 ? S 2月11 0:00 php-fpm: pool www
1.編輯php-fpm配置文件添加新pool命名為linux.com
[linux.com] listen = /tmp/linux.sock #listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024
2.檢查php配置文件,重新加載配置文件,查看php進程發現有連個pool了
為什麽要建立多個池子呢?拿www和linux.com兩個池子來說,www池子最多可以同時開50個進程,當www進程滿了就會報502錯誤,這個時候linux.com不受影響。
[root@bogon linux.com]# /usr/local/php-fpm/sbin/php-fpm -t [13-Feb-2018 10:28:14] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [root@bogon linux.com]# /etc/init.d/php-fpm reload Reload service php-fpm done [root@bogon linux.com]# ps -aux|grep php-fpm
php-fpm 18117 0.0 0.5 229228 5076 ? S 10:29 0:00 php-fpm: pool www php-fpm 18118 0.0 0.5 229228 5076 ? S 10:29 0:00 php-fpm: pool www php-fpm 18119 0.0 0.5 229228 5076 ? S 10:29 0:00 php-fpm: pool www php-fpm 18120 0.0 0.5 229228 5072 ? S 10:29 0:00 php-fpm: pool linux.com php-fpm 18121 0.0 0.5 229228 5076 ? S 10:29 0:00 php-fpm: pool linux.com php-fpm 18122 0.0 0.5 229228 5076 ? S 10:29 0:00 php-fpm: pool linux.com
3.新建pool,編輯aaa.com.conf配置文件添加支持php配置
[root@bogon vhost]# ls aaa.com.conf load.conf proxy.conf ssl.conf test.com.conf [root@bogon vhost]# vim aaa.com.conf [root@bogon vhost]#
server
{
listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/linux.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
}
4.查看nginx配置文件可以看到有個include選項,php-fpm也是支持的
[root@bogon conf]# vim nginx.conf [root@bogon conf]#
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
include vhost/*.conf;
}
5.編輯php-fpm.conf,在global標簽下添加include選項
[root@bogon conf]# vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
include = etc/php-fpm.d/*.conf
6.將www配置和linux.com配置拆分開,在etc目錄下創建php-fpm.d目錄並創建兩個配置文件www.conf和linux.conf,在配置文件中分別將拆分出來的配置寫到裏面
[root@bogon conf]# cd / [root@bogon /]# cd usr/local/php-fpm/etc/ [root@bogon etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php.ini [root@bogon etc]# mkdir php-fpm.d [root@bogon etc]# cd php-fpm.d/ [root@bogon php-fpm.d]# vi www.conf [root@bogon php-fpm.d]#
[www] listen = /tmp/php-fcgi.sock #listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024
[root@bogon php-fpm.d]# vi linux.conf
[linux.com] listen = /tmp/linux.sock #listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024
7.刪除php-fpm.conf配置文件中的www和linux.com配置
8.檢查配置,重啟php-fpm everyone ok
[root@bogon php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t [13-Feb-2018 11:39:14] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [root@bogon php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done [root@bogon php-fpm.d]#
9.檢查服務是否啟動,發現一切ok
[root@bogon php-fpm.d]# ps -aux|grep php-fpm root 23264 1.8 0.4 227232 4984 ? Ss 11:39 0:01 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 23284 0.1 0.5 229256 5080 ? S 11:40 0:00 php-fpm: pool linux.com php-fpm 23285 0.0 0.5 229256 5080 ? S 11:40 0:00 php-fpm: pool linux.com php-fpm 23286 0.0 0.5 229256 5076 ? S 11:40 0:00 php-fpm: pool www php-fpm 23287 0.0 0.5 229256 5076 ? S 11:40 0:00 php-fpm: pool www
LNMP架構四