标签:php-fpm
php-fpm的pool1.查看文件:
[root@weixing01 ~]# cd /usr/local/php-fpm/etc
[root@weixing01 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default
[root@weixing01 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.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.修改配置文件,增加poo:
[root@weixing01 etc]# vi !$
vi php-fpm.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
3.验证并重新加载:
[root@weixing01 etc]# /usr/local/php-fpm/sbin/php-fpm -t
[19-Mar-2018 17:23:16] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@weixing01 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
4.查看状态:
[root@weixing01 etc]# ps aux |grep php-fpm
root 1465 0.0 0.4 227288 4948 ? Ss 17:24 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 1466 0.0 0.4 227228 4696 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1467 0.0 0.4 227228 4696 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1468 0.0 0.4 227228 4696 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1469 0.0 0.4 227228 4696 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1470 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1471 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1472 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1473 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1474 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1475 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1476 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1477 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1478 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1479 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1480 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1481 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1482 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1483 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1484 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1485 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool www
php-fpm 1486 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1487 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1488 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1489 0.0 0.4 227228 4700 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1490 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1491 0.0 0.4 227228 4704 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1492 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1493 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1494 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1495 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1496 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1497 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1498 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1499 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1500 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1501 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1502 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1503 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1504 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
php-fpm 1505 0.0 0.4 227228 4708 ? S 17:24 0:00 php-fpm: pool weixing.com
root 1509 0.0 0.0 112676 984 pts/0 R+ 17:25 0:00 grep --color=auto php-fpm
5.修改其中一个配置文件:
[root@weixing01 vhost]# vi 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/weixing.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
}
6.定义多个池子,当其中一个站点请求用满时,其他站点不会受影响
7.php-fpm也支持把池子单独拆出来,修改配置文件:
[root@weixing01 vhost]# cd /usr/local/php-fpm/etc/
[root@weixing01 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default
[root@weixing01 etc]# vi 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
8.将配置文件单独拆出:将两个配置文件单独放到自己文件下
[root@weixing01 etc]# mkdir php-fpm.d
[root@weixing01 etc]# cd php-fpm.d/
[root@weixing01 php-fpm.d]# vi www.conf
[root@weixing01 php-fpm.d]# vi weixing.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
[weixing.com]
listen = /tmp/weixing.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
9.重新验证,加载,并查看状态,结果一样:
[root@weixing01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[19-Mar-2018 17:38:49] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
(reverse-i-search)`-reload‘: firewall-cmd -^Ceload
[root@weixing01 php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@weixing01 php-fpm.d]# ps aux |grep php-fpm
root 1671 0.0 0.4 227316 4964 ? Ss 17:39 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 1672 0.0 0.4 227256 4704 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1673 0.0 0.4 227256 4708 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1674 0.0 0.4 227256 4708 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1675 0.0 0.4 227256 4708 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1676 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1677 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1678 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1679 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1680 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1681 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1682 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1683 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1684 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1685 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1686 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1687 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1688 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1689 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1690 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1691 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool weixing.com
php-fpm 1692 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1693 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1694 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1695 0.0 0.4 227256 4712 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1696 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1697 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1698 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1699 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1700 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1701 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1702 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1703 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1704 0.0 0.4 227256 4716 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1705 0.0 0.4 227256 4720 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1706 0.0 0.4 227256 4720 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1707 0.0 0.4 227256 4720 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1708 0.0 0.4 227256 4720 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1709 0.0 0.4 227256 4720 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1710 0.0 0.4 227256 4720 ? S 17:39 0:00 php-fpm: pool www
php-fpm 1711 0.0 0.4 227256 4720 ? S 17:39 0:00 php-fpm: pool www
root 1717 0.0 0.0 112680 984 pts/0 S+ 17:39 0:00 grep --color=auto php-fpm
1.修改pool的配置文件:
[root@weixing01 php-fpm.d]# vi 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
2.验证并重新加载:
[root@weixing01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[19-Mar-2018 17:45:19] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@weixing01 php-fpm.d]# /etc/init.d/php-fpm reload
Reload service php-fpm done
3.写一个测试脚本:
[root@weixing01 php-fpm.d]# vim /data/wwwroot/test.com/sleep.php
<?php
echo “test slow log”;
sleep(2);
echo “done”;
?>
4.执行发现有错误:
[root@weixing01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
<br />
<b>Parse error</b>: syntax error, unexpected ‘slow‘ (T_STRING), expecting ‘,‘ or ‘;‘ in <b>/data/wwwroot/test.com/sleep.php</b> on line <b>2</b><br />
发现是配置文件标点问题,修改后执行:查看日志,发现有记录
[root@weixing01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
test slow logdone
[root@weixing01 php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log
[19-Mar-2018 17:54:53] [pool www] pid 3202
script_filename = /data/wwwroot/test.com/sleep.php
[0x00007fbb3f2d3298] sleep() /data/wwwroot/test.com/sleep.php:3
1.修改pool的配置文件:
[root@weixing01 php-fpm.d]# vi 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/
2.测试并重启:
[root@weixing01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[19-Mar-2018 18:10:53] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@weixing01 php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
3.访问测试:正常
</div></body></html>[root@weixing01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php
标签:php-fpm
原文地址:http://blog.51cto.com/13517254/2088675