学习linux第五十三天

php-fpm的pool

建立多个php-fpm的pool,避免php资源不够,而且所有网站都使用一个池子。造成全面宕机

 

 

[root@hanlin nginx-1.12.1]# 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
[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

[aming.com] (新增的一个池子)
listen = /tmp/aming.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

 

 

[root@hanlin nginx-1.12.1]# /etc/init.d/php-fpm reload
Reload service php-fpm done

 

[root@hanlin nginx-1.12.1]# vim /usr/local/nginx/conf/vhost/test.com.conf  (标注的就是需要更改配置的地方,如果定义多个pool的时候)
 

location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
}

access_log /tmp/test.conf.log xy;


把pool拆分出来

[root@hanlin nginx-1.12.1]#vim /usr/local/nginx/conf/nginx.conf

 

gzip_types text/plain application/x-javascript text/css text/htm

application/xml;
include vhost/*.conf; (php-fpm也可以模仿nginx的方式,来创建include)
}
[root@hanlin php-fpm.d]# 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.login
include = /etc/php-fpm.d/*.conf

[root@hanlin nginx-1.12.1]# mkdir /etc/php-fpm.d
[root@hanlin nginx-1.12.1]# cd !$
cd /etc/php-fpm.d
[root@hanlin php-fpm.d]# vim www.conf

 

[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

[root@hanlin php-fpm.d]# vim aming.com.conf 
[aming.com]

listen = /tmp/aming.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

 

[root@hanlin php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[28-Nov-2018 22:34:17] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

[root@hanlin php-fpm.d]# ls /tmp (单独创建的两个监听文件)
aming.sock
hanlin
mysql.sock
pear
php-fcgi.sock
systemd-private-6bf4548fddbb4f3eae6a4120bc93a48d-chronyd.service-jrtEVF
systemd-private-6bf4548fddbb4f3eae6a4120bc93a48d-cups.service-XoSdjr
systemd-private-6bf4548fddbb4f3eae6a4120bc93a48d-vgauthd.service-mZEYRl
systemd-private-6bf4548fddbb4f3eae6a4120bc93a48d-vmtoolsd.service-krjRR1
test.conf.log
test.conf.log-20181126

 

[root@hanlin php-fpm.d]# ls (单独创建的两个配置文件)
aming.com.conf www.conf

 

 

 

php慢执行日志 (运维排查,访问站点慢通过慢执行日志排查)

 

[root@hanlin php-fpm.d]# ls
aming.com.conf www.conf
[root@hanlin php-fpm.d]# vim www.conf 
[root@hanlin php-fpm.d]# cat /usr/local/php-fpm/
bin/ etc/ include/ lib/ php/ sbin/ var/ 

[root@hanlin php-fpm.d]# /etc/init.d/php-fpm reload 
Reload service php-fpm done
[root@hanlin php-fpm.d]# cat /usr/local/php-fpm/var/log/
php-fpm.log php-fpm.login www-slow.log 
[root@hanlin php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log 

 

 

[root@hanlin php-fpm.d]# vim /usr/local/nginx/conf/vhost/test.com.conf  (查询得知是test.com这个站点在调用/tmp/php-fcgi.sock)
 

location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
}

access_log /tmp/test.conf.log xy;


}

[root@hanlin php-fpm.d]# vim /data/wwwroot/test.com/sleep.php

<?php
echo "test slow log";
sleep(2);
echo "done";
?>
[root@hanlin php-fpm.d]# /etc/init.d/php-fpm reload 
Reload service php-fpm done
[root@hanlin php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
test slow logdone[root@hanlin php-fpm.d]# 
[root@hanlin php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log 

[28-Nov-2018 23:35:44] [pool www] pid 11054
script_filename = /data/wwwroot/test.com/sleep.php
[0x00007fd552f04280] sleep() /data/wwwroot/test.com/sleep.php:3 (查看日志得知,sleep.php第三行导致了访问异常慢)

 

open_basedir

[root@hanlin php-fpm.d]# vim www.conf 

[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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/ (限定php在指定的目录下活动)

 

 

[root@hanlin php-fpm.d]# vim /usr/local/nginx/conf/vhost/test.com.conf 
 

location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
}

access_log /tmp/test.conf.log xy;


}

[root@hanlin php-fpm.d]# /etc/init.d/php-fpm restart 
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@hanlin php-fpm.d]# curl -x127.0.0.1:80 test.com/index.html
wo shi zhongguoren
</div></body></html>[root@hanlin php-fpm.d]# curl -x127.0.0.1:80 test.com/test.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Wed, 28 Nov 2018 17:04:52 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30

 

定义php错误日志

[root@hanlin php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini 

display_errors = Off (关闭浏览器报错)

error_log = /usr/local/php-fpm/var/log/php_errors.log (定义错误日志路径,要自己创建)
error_reporting = E_ALL (定义报错级别)

 

[root@hanlin php-fpm.d]# touch /usr/local/php-fpm/var/log/php_errors.log
[root@hanlin log]# chmod 777 php_errors.log 

 

[root@hanlin log]# curl -x127.0.0.1:80 test.com/test.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Wed, 28 Nov 2018 17:16:33 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30

 

 

php-fpm进程管理

[root@hanlin /]# ls /etc/php-fpm.d/
aming.com.conf www.conf
[root@hanlin /]# vim /etc/php-fpm.d/www.conf 

 

[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic (动态进程管理,如果改成static,那就只有下面一行生效)
pm.max_children = 50 (最大子进程数)
pm.start_servers = 20 (启动服务时会启动的进程数)
pm.min_spare_servers = 5 (定义在空闲时段,子进程数的最少数量,如果达到这个数值时,php-fpm服务会自动派生新的子进程)
pm.max_spare_servers = 35 (定义在空闲时段,子进程数的最大值,如果高于这个数值就开始清理空闲的子进程。)
pm.max_requests = 500 (定义一个子进程最多处理的请求数,也就是说在一个php-fpm的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出)
rlimit_files = 1024
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/wwtest.com:/tmp/

 

 

 

 

 

 

 

 

 

转载于:https://my.oschina.net/u/3867255/blog/2964263

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值