50次课 php-fpm的(pool慢执行日志open_basedir进程管理)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了50次课 php-fpm的(pool慢执行日志open_basedir进程管理)相关的知识,希望对你有一定的参考价值。
php-fpm的pool
它的pool就是它的池子
[[email protected] etc]# cd /usr/local/php-fpm/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[[email protected] 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
[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
设置多个pool
* 进入/usr/local/php-fpm/etc/下编辑php-fpm.conf
[[email protected] etc]# cd /usr/local/php-fpm/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[[email protected] etc]# vim php-fpm.conf
以上添加完成后查看是否有语法错误
[[email protected] etc]# /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2018 11:03:39] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
没有语法错误然后重启
[[email protected] etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
然后用ps看一下
[[email protected] etc]# ps aux |grep php-fpm
怎么用两个pool
进入 /usr/local/nginx/conf/vhost/目录下编辑test.com.conf
[[email protected] etc]# cd /usr/local/nginx/conf/vhost/
[[email protected] vhost]# ls
aaa.com.conf ld.conf proxy.conf ssl.conf test.com.conf
[[email protected] vhost]# vim test.com.conf
[[email protected] vhost]# vim test.com.conf
expires 7d;
valid_referers none blocked server_names *.test.com ;
if ($invalid_referer) {
return 403;
}
access_log off;
}
location ~ .*.(js|css)$
{
# expires 12h;
access_log off;
}
location /admin/
{
allow 192.168.63.100;
allow 127.0.0.1;
deny all;
}
location ~ .*(upload|image)/.*.php$
{
deny all;
}
if ($http_user_agent ~* ‘Spider/3.0|YoudaoBot|Tomato‘)
{
return 403;
}
location ~ .php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock; ##**这里定义成php-fcgi.sock**
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
}
access_log /tmp/test.com.log hanshuo;
}
然后再去定义另外一个pool
[[email protected] vhost]# ls
aaa.com.conf ld.conf proxy.conf ssl.conf test.com.conf
[[email protected] vhost]# vim aaa.com.conf
[[email protected] vhost]# vim aaa.com.conf
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/han.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
}
php也支持include进入php-fpm.conf下编辑
[[email protected] etc]# mkdir php-fpm.d ##创建php-fpm.d因为include = etc/php-fpm.d/*.conf!
[[email protected] etc]# cd php-fpm.d/ ##进入
[[email protected] php-fpm.d]# vim 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
[[email protected] php-fpm.d]# vim han.com ##然后在创建一个目录han.com
[han.com] ##写入内容
listen = /tmp/han.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
查看配置是否有错
[[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2018 11:44:58] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
*重启效果跟以前没有加include = etc/php-fpm.d/.conf是一样的**
[[email protected] php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
php-fpm慢执行日志
php-fpm的慢执行日志非常有用lamp是没有的,lnmp有,为什么分析慢执行日志,在运维工作当中经常会遇到一个问题,有人经常反馈网站访问慢了,为什么慢要知道根本原因,慢在什么地方,php网站有办法查他到底慢在哪里,用慢执行日志查看
配置php-fpm慢执行日志比如说针对www.conf
编辑/usr/local/php-fpm/etc/php-fpm.d/下的www.conf,添加一下内容
[[email protected] php-fpm.d]# 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
检测和重新加载
[[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2018 13:29:11] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[[email protected] php-fpm.d]# /etc/init.d/php-fpm reload
Reload service php-fpm done
查看有没有生成日志文件如果已生成用cat查看日志
[[email protected] php-fpm.d]# ls /usr/local/php-fpm/var/log/www-slow.log ##已生成
/usr/local/php-fpm/var/log/www-slow.log
模拟慢执行日志的php写个脚本
[[email protected] php-fpm.d]# vim /data/wwwroot/test.com/sleep.php 编辑个脚本写入下边的代码
<?php echo “test slow log”;sleep(2);echo “done”;?> ##故意休眠两秒钟
~
~
open_basedir
编辑配置文件
[[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/
启动
测试
查看错误日志
把php-fpm的错误日志定义上
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
12.24 php-fpm进程管理
以上是关于50次课 php-fpm的(pool慢执行日志open_basedir进程管理)的主要内容,如果未能解决你的问题,请参考以下文章
php-fpm的pool网站慢执行日志定义open_basedir设置php日志进程管理