php-fpm.conf可以设置多个pool,在其中一个pool资源耗尽,会导致其他站点无法访问资源,报502错误。有必要把站点进行分离,分别使用单独的pool。
# 文件地址:/usr/local/php-fpm/etc/php-fpm.conf
[root@dl-001 etc]# vim php-fpm.conf
...
# 新增一个pool代码设置
[test]
listen = /tmp/test.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
// 这里设置另外一个虚拟主机
// 实现不同虚拟主机访问资源pool的隔离,互不影响
[root@dl-001 etc]# cat /usr/local/nginx/conf/vhost/aaa.com.conf
server
{
listen 80 default_server;
index index.html index.htm index.php
root /data/www/default;
location ~ \.php$
{
include fastcgi_params;
# 这里写对应php-fpm.conf内设置的sock
fastcgi_pass unix:/tmp/test.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/default$fastcgi_script_name;
}
}
[root@dl-001 etc]# /usr/local/php-fpm/sbin/php-fpm -t
[05-Jan-2018 19:37:17] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@dl-001 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
# 已经可以看到创建的pool --- test
[root@dl-001 etc]# ps aux | grep php-fpm
root 2895 1.7 0.3 227208 5008 ? Ss 19:37 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
...
php-fpm 2915 0.0 0.3 227148 4712 ? S 19:37 0:00 php-fpm: pool www
php-fpm 2916 1.4 0.3 227148 4708 ? S 19:37 0:00 php-fpm: pool test
...
root 2937 0.0 0.0 112680 976 pts/0 S+ 19:37 0:00 grep --color=auto php-fpm
在php-fpm.conf内添加如下代码就可以实现类似虚拟主机配置文件分离的效果。
[root@dl-001 etc]# cat 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
# 将原文件内的www、test pool模块分别写在不同的conf文件内
[root@dl-001 etc]# vim php-fpm.d/www.conf
[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@dl-001 etc]# vim php-fpm.d/test.conf
[test]
listen = /tmp/test.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@dl-001 etc]# /usr/local/php-fpm/sbin/php-fpm -t
[05-Jan-2018 20:19:10] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@dl-001 etc]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
# 这里test池在前,www池在后
[root@dl-001 etc]# ps aux | grep php-fpm
root 3068 0.2 0.3 227236 4980 ? Ss 20:20 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 3069 0.0 0.3 227176 4712 ? S 20:20 0:00 php-fpm: pool test
php-fpm 3070 0.0 0.3 227176 4712 ? S 20:20 0:00 php-fpm: pool test
php-fpm 3071 0.0 0.3 227176 4712 ? S 20:20 0:00 php-fpm: pool test
php-fpm 3075 0.0 0.3 227176 4716 ? S 20:20 0:00
...
php-fpm 3079 0.0 0.3 227176 4716 ? S 20:20 0:00 php-fpm: pool test
php-fpm 3080 0.0 0.3 227176 4716 ? S 20:20 0:00 php-fpm: pool test
php-fpm 3081 0.0 0.3 227176 4716 ? S 20:20 0:00 php-fpm: pool test
php-fpm 3089 0.0 0.3 227176 4716 ? S 20:20 0:00 php-fpm: pool www
...
php-fpm 3107 0.0 0.3 227176 4724 ? S 20:20 0:00 php-fpm: pool www
php-fpm 3108 0.0 0.3 227176 4724 ? S 20:20 0:00 php-fpm: pool www
root 3110 0.0 0.0 112680 976 pts/0 S+ 20:20 0:00 grep --color=auto php-fpm