一:系统环境
[machao@aiye log]$ cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [machao@aiye log]$ uname -i x86_64
内存:64G
二:php-error.log路径
[machao@zhangwan22222222 log]$ cat /usr/local/php-7.0.22/etc/php-fpm.conf
[global]
error_log = /usr/local/php-7.0.22/var/log/php-fpm.log
三:检查php的errorlog日志
最近看监控,发现php-fpm,mysql的cpu过高,服务器压力过大,就想着优化下php-fpm和mysql的参数 这里:检查php-fpm的errorlog
[machao@aiye log]$ sudo tail -100 /usr/local/php-7.1.10/var/log/php-fpm.log [29-May-2018 08:55:30] WARNING: [pool www11] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children,
there are 27 idle, and 89 total children
注释:好像很忙碌,你需要增加pm.start_servers 或pm.min/max_spare_servers
四:php-fpm进程池优化
php-fpm进程池开启进程有两种方式: 一种是:static (静态的), 直接开启指定数量的php-fpm进程,不再增加或者减少 一种是:dynamic (动态的), 开始时开启一定数量的php-fpm进程, 当请求量变大时,动态的增加php-fpm进程数达到上限, 当空闲时自动释放空闲的进程数到一个下限。 (生产环境中,根据服务器实际需求来进行调整) 要用到的一些参数 ,分别是 pm,pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers pm表示使用哪种方式,有两个值可以选择。staic或者dynamic 例:pm = dynamic pm.max_children:静态方式下指开启的php-fpm进程数量, 在动态方式下限定php-fpm的最大进程数。 pm.start_servers:动态方式下的起始php-fpm进程数量。 pm.min_spare_servers:动态方式空闲状态下的最小php-fpm进程数量。ps:spare(空闲的) pm.max_spare_servers:动态方式下空闲状态的最大php-fpm进程数量。 如果pm设置为staic,那么只有pm.max_childern这个参数生效 如果pm设置为dynamic,4个参数都生效。系统会在php-fpm运行开始时启动pm.start_servers个php-fpm进程,然后根据系统的需求动态在pm.min_spare_servers和pm.max_spare_servers之间调整php-fpm进程数。 PS:要求pm.start_servers的值在pm.min_spare_servers和pm.max_spare_servers之间
五:php-fpm优化后的参数
[machao@zhangwan22222222 log]$ sudo cat /usr/local/php-7.1.10/etc/php-fpm.conf
[global]
pid = /usr/local/php-7.1.10/var/run/php-fpm.pid
error_log = /usr/local/php-7.1.10/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 100
pm.start_servers = 40
pm.min_spare_servers = 30
pm.max_spare_servers = 60
pm.max_requests = 5000
rlimit_files = 60000
listen.owner= nobody
listen.group= nobody
listen.mode = 0666
security.limit_extensions = .php .php3 .php4 .php5 .php7
[www2]
listen = /tmp/php-fcgi2.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 100
pm.start_servers = 40
pm.min_spare_servers = 30
pm.max_spare_servers = 60
pm.max_requests = 5000
rlimit_files = 60000
listen.owner= nobody
listen.group= nobody
listen.mode = 0666
[www10]
listen = /tmp/php-fcgi10.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 1000
pm.start_servers = 200
pm.min_spare_servers = 200
pm.max_spare_servers = 500
pm.max_requests = 5000
rlimit_files = 60000
listen.owner= nobody
listen.group= nobody
listen.mode = 0666