我的服务器运行 Nginx + PHP-FPM 设置时遇到一些问题。本周中欧夏令时间 02 点左右后,我们的用户看到了 503 条信息。从浏览器来看,它在一定时间后超时(经过几分钟的等待)。我检查了日志,我唯一注意到的是下面日志的第一行:
[20-Sep-2013 01:45:00] WARNING: [pool web1] server reached pm.max_children setting (25), consider raising it
[20-Sep-2013 01:45:03] NOTICE: [pool web1] child 3657 exited with code 0 after 30.161697 seconds from start
[20-Sep-2013 01:45:03] NOTICE: [pool web1] child 3672 started
[20-Sep-2013 01:45:07] NOTICE: [pool web1] child 3655 exited with code 0 after 33.749738 seconds from start
虽然超时,但我检查了内存使用情况和每个进程的计数,PHP-FPM 似乎有 26 个进程正在运行。
重新启动 PHP-FPM 会有所帮助。这是重启后的 FPM 日志:
[20-Sep-2013 07:28:41] NOTICE: Terminating ...
[20-Sep-2013 07:28:41] NOTICE: exiting, bye-bye!
[20-Sep-2013 07:30:09] NOTICE: fpm is running, pid 1905
[20-Sep-2013 07:30:09] NOTICE: ready to handle connections
[20-Sep-2013 07:30:13] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 10 total children
[20-Sep-2013 07:30:14] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 12 total children
[20-Sep-2013 07:31:10] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 12 total children
[20-Sep-2013 07:31:11] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 14 total children
[20-Sep-2013 07:31:12] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 16 total children
[20-Sep-2013 07:31:13] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 18 total children
[20-Sep-2013 07:31:14] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 20 total children
[20-Sep-2013 07:32:27] NOTICE: [pool web1] child 2079 exited with code 0 after 73.199058 seconds from start
[20-Sep-2013 07:32:27] NOTICE: [pool web1] child 2099 started
[20-Sep-2013 07:32:29] NOTICE: [pool web1] child 2080 exited with code 0 after 74.523488 seconds from start
[20-Sep-2013 07:32:29] NOTICE: [pool web1] child 2100 started
服务器信息: KVM 来宾 - Centos 6.4 x64,具有当前内核。 PHP 5.4.20 nginx/1.3.14 内存 6GiB
Here is my FPM pool config:
[web1]
listen = /var/run/php-fpm/$pool.sock
user = $pool
group = $pool
pm = dynamic
pm=static
pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.max_requests = 100
slowlog = /var/log/php-fpm/$pool-slow.log
php_admin_value[error_log] = /var/log/php-fpm/$pool-error.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 1000M
php_admin_value[upload_max_filesize] = 2000M
php_admin_value[post_max_size] = 2000M
php_admin_value[max_file_uploads] = 1000
php_admin_value[max_execution_time] = 1200
php_admin_value[session.gc_maxlifetime] = 86400
php_admin_value[max_input_time] = 1200
request_terminate_timeout = 14400s
rlimit_files = 131072
chdir = /
listen.backlog = 16384
pm.status_path = /status
env[TMP] = /var/www/vhosts/$pool/tmp
env[TMPDIR] = /var/www/vhosts/$pool/tmp
env[TEMP] = /var/www/vhosts/$pool/tmp
这是服务器无法处理流量的问题吗?由于服务器提供文件上传和下载,我有很长时间的超时。 另外,我不确定这是否是问题所在,因为我以前也见过这种情况,而且没有服务器超时。我一直在这里阅读以找到类似的问题/问题,事实上我的 FPM 配置的某些部分是从这里的推荐设置中获取的:)
任何对我的问题的见解将不胜感激。
首先,您不能同时设置多个 PM 设置,目前您有两个。
在你的情况下,我会尝试使用
pm = dynamic
选项。
然后尝试这些设置,看看是否有帮助:
pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 10
pm.max_requests = 0
如果您没有使用任何 CHROOT,则禁用
chdir = /
我也会非常宽松地使用“推荐设置”。与 FPM 一样,实际上没有“推荐”设置,因为每个服务器规格都会不同,每个服务器的负载也不同。