12.21 php-fpm的pool
1.添加pool:
[[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.conf
添加第二个pool:
[hao1.com]
listen = /tmp/hao1.sock
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.查看配置有没有语法错误?
[[email protected] ~]# /usr/local/php-fpm/sbin/php-fpm -t
3.重新加载配置:
[[email protected] ~]# /etc/init.d/php-fpm reload
4.查找php-fpm进程(pool hao1.com 可查到了):
[[email protected] ~]# ps aux |grep php-fpm
5.aaa.com网站设定为第二个pool(hao1.com)
[[email protected] ~]# vim /usr/local/nginx/conf/vhost/aaa.com.conf
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/hao1.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
多个pool情况下,每一个pool对应一个相关配置文件:
1.查看[www]和[hao1.com]相关下面的配置 并拷贝到剪切板备用:
[[email protected] ~]# cat /usr/local/php-fpm/etc/php-fpm.conf
2.编辑 php-fpm.conf主配置文件:
[[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.conf
添加如下一行(添加这行就可以www和hao1.com配置设定成各自独立的文件):
include = etc/php-fpm.d/*.conf
删除(删除前一定要先备份):[www]和[hao1.com]相关下面的配置
删除光标行及下面100行:100 dd
3.创建.../php-fpm.d目录(用于存放后缀.conf文件):
[[email protected] ~]# mkdir /usr/local/php-fpm/etc/php-fpm.d
4.进入.../php-fpm.d目录:
[[email protected] ~]# cd /usr/local/php-fpm/etc/php-fpm.d
5.创建www.conf文件,并添加如下内容:
[[email protected] php-fpm.d]# vim www.conf
之前备份的[www]相关配置:
[www]
listen = /tmp/php-fcgi.sock
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
6.创建hao1.com.conf文件,并添加如下内容:
[[email protected] php-fpm.d]# vim hao1.com.conf
之前备份的[hao1.com]相关配置:
[hao1.com]
listen = /tmp/hao1.sock
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.查看配置有没有语法错误?
[[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
8.重新加载配置:
[[email protected] php-fpm.d]# /etc/init.d/php-fpm reload
9.查找php-fpm进程(pool hao1.com 可查到了):
[[email protected] php-fpm.d]# ps aux |grep php-fpm
12.22 php-fpm慢执行日志
1.编辑.../www.conf文件:
[[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
添加内容(日志配置):
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
2.查看配置有没有语法错误?
[[email protected] ~]# /usr/local/php-fpm/sbin/php-fpm -t
3.重新加载配置:
[[email protected] ~]# /etc/init.d/php-fpm reload
4.查看是否生成www-slow.log日志文件:
[[email protected] ~]# ls /usr/local/php-fpm/var/log/www-slow.log
添加内容:
<?php
echo "test slow log";
sleep(2);
echo "done";
?>
5.curl访问test.com网站下,sleep.php文件(慢2秒执行)
[[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.php -I
6.查看慢执行日志内容:
[[email protected] ~]# cat /usr/local/php-fpm/var/log/www-slow.log
12.23 open_basedir
1.编辑.../php-ini配置文件,添加一行错误日志配置:
[[email protected] ~]# vim /usr/local/php-fpm/etc/php-ini
;error_log = /usr/local/php-fpm/var/log/php_errors.log
添加一行日志级别(所有),并;分号注释掉上一行:
error_reporting =E_ALL
2.创建.../php_errors.log错误日志文件:
[[email protected] ~]# touch /usr/local/php-fpm/var/log/php_errors.log
3.设定php_errors.log错误日志文件权限为777:
[[email protected] ~]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log
4.编辑.../www.conf文件:
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
添加内容:
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
5.查看配置有没有语法错误?
[[email protected] ~]# /usr/local/php-fpm/sbin/php-fpm -t
6.重启配置:
[[email protected] ~]# /etc/init.d/php-fpm restart
7.curl访问test.com网站下的php文件:
[[email protected] ~]# curl -x127.0.0.1:80 test.com/1.php -I
8.编辑.../www.conf文件,:
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
把[www] 对应的网站(test.com),改为不对应的网站地址(11.com):
9.重启配置:
[[email protected] ~]# /etc/init.d/php-fpm restart
10.curl访问test.com网站下的php文件:
[[email protected] ~]# curl -x127.0.0.1:80 test.com/1.php
11.查看错误日志(php_errors.log)
[[email protected] ~]# cat /usr/local/php-fpm/var/log/php_errors.log
12.24 php-fpm进程管理
pm = dynamic //动态进程管理,也可以是static
pm.max_children = 50 //最大子进程数,ps aux可以查看
pm.start_servers = 20 //启动服务时会启动的进程数
pm.min_spare_servers = 5 //定义在空闲时段,子进程数的最少数量,如果达到这个数值时,php-fpm服务会自动派生新的子进程。
pm.max_spare_servers = 35 //定义在空闲时段,子进程数的最大值,如果高于这个数值就开始清理空闲的子进程。
pm.max_requests = 500 //定义一个子进程最多处理的请求数,也就是说在一个php-fpm的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出。
原文地址:http://blog.51cto.com/zhuneianxiang/2088553