我正在尝试使用 Debian9 和 SystemD 尽可能好地配置 php-fpm 服务器,但我发现一个让我抓狂的问题。我尽我所能搜索和研究了所有方法,但一无所获,没有任何积极的结果。
我正在使用以下命令监控 php-fpm:
watch -n.1 "systemctl status php72"
主要问题
当我尝试拨打
kill -USR2 php-fpm-pid
它等待直到 process_control_timeout 过去(在我的情况下是 60 秒),然后立即杀死所有子进程(向子进程发送 SIGTERM)。看来 SIGQUIT 什么也没做,也没有对子进程做出任何贡献。
如果我尝试调用
systemctl kill -s USR2 php72.service
它会立即终止所有进程并在 apache 上生成错误 500。
事情发生的背景
调试日志
[26-Mar-2019 12:24:17.890902] DEBUG: pid 1837, fpm_got_signal(), line 111: received SIGUSR2
[26-Mar-2019 12:24:17.891061] NOTICE: pid 1837, fpm_got_signal(), line 112: Reloading in progress ...
[26-Mar-2019 12:24:17.891085] DEBUG: pid 1837, fpm_pctl(), line 230: switching to 'reloading' state
[26-Mar-2019 12:24:17.891225] DEBUG: pid 1837, fpm_pctl_kill_all(), line 158: [pool www72] sending signal 3 SIGQUIT to child 1839
[26-Mar-2019 12:24:17.891248] DEBUG: pid 1837, fpm_pctl_kill_all(), line 158: [pool temp-site.io] sending signal 3 SIGQUIT to child 1840
[26-Mar-2019 12:24:17.891370] DEBUG: pid 1837, fpm_pctl_kill_all(), line 167: 2 child(ren) still alive
[26-Mar-2019 12:24:17.891393] DEBUG: pid 1837, fpm_event_loop(), line 418: event module triggered 1 events
[26-Mar-2019 12:25:01.905047] DEBUG: pid 1837, fpm_got_signal(), line 75: received SIGCHLD
[26-Mar-2019 12:25:01.905186] DEBUG: pid 1837, fpm_children_bury(), line 252: [pool temp-site.io] child 1840 exited with code 0 after 52.621960 seconds from start
[26-Mar-2019 12:25:01.905231] DEBUG: pid 1837, fpm_event_loop(), line 418: event module triggered 1 events
[26-Mar-2019 12:25:17.892532] DEBUG: pid 1837, fpm_pctl_kill_all(), line 158: [pool www72] sending signal 15 SIGTERM to child 1839
[26-Mar-2019 12:25:17.892561] DEBUG: pid 1837, fpm_pctl_kill_all(), line 167: 1 child(ren) still alive
[26-Mar-2019 12:25:17.894222] DEBUG: pid 1837, fpm_got_signal(), line 75: received SIGCHLD
[26-Mar-2019 12:25:17.894264] DEBUG: pid 1837, fpm_children_bury(), line 252: [pool www72] child 1839 exited on signal 15 (SIGTERM) after 68.611847 seconds from start
[26-Mar-2019 12:25:17.894273] NOTICE: pid 1837, fpm_pctl_exec(), line 97: reloading: execvp("/path/to/php72/sbin/php-fpm", {"/path/to/php72/sbin/php-fpm", "--fpm-config", "/opt/php5-fpm/php72.conf", "--pid", "/var/run/php5/php72/php72.pid", "-F"})
[26-Mar-2019 12:25:18.296768] DEBUG: pid 1837, fpm_scoreboard_init_main(), line 39: got clock tick '100'
[26-Mar-2019 12:25:18.296832] NOTICE: pid 1837, fpm_sockets_init_main(), line 418: using inherited socket fd=8, "127.0.0.1:9720"
[26-Mar-2019 12:25:18.296839] NOTICE: pid 1837, fpm_sockets_init_main(), line 418: using inherited socket fd=9, "127.0.0.1:30739"
[26-Mar-2019 12:25:18.296852] DEBUG: pid 1837, fpm_socket_af_inet_socket_by_addr(), line 291: Found address for 127.0.0.1, socket opened on 127.0.0.1
[26-Mar-2019 12:25:18.296865] DEBUG: pid 1837, fpm_socket_af_inet_socket_by_addr(), line 291: Found address for 127.0.0.1, socket opened on 127.0.0.1
[26-Mar-2019 12:25:18.296876] DEBUG: pid 1837, fpm_event_init_main(), line 336: event module is epoll and 1 fds have been reserved
[26-Mar-2019 12:25:18.296904] NOTICE: pid 1837, fpm_init(), line 84: fpm is running, pid 1837
[26-Mar-2019 12:25:18.297702] DEBUG: pid 1837, fpm_children_make(), line 421: [pool www72] child 2086 started
[26-Mar-2019 12:25:18.298357] DEBUG: pid 1837, fpm_children_make(), line 421: [pool temp-site.io] child 2087 started
[26-Mar-2019 12:25:18.298414] DEBUG: pid 1837, fpm_pctl_heartbeat(), line 459: heartbeat have been set up with a timeout of 1666ms
[26-Mar-2019 12:25:18.298420] DEBUG: pid 1837, fpm_event_loop(), line 365: 258960 bytes have been reserved in SHM
[26-Mar-2019 12:25:18.298423] NOTICE: pid 1837, fpm_event_loop(), line 366: ready to handle connections
uname -a
Linux HOST 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux
php-fpm.conf
[global]
process_control_timeout = 60s
error_log = /var/log/fpm-php.log
log_level = debug
[www72]
user = www-data
group = www-data
listen = 127.0.0.1:9720
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_children = 200
pm.process_idle_timeout = 10s
pm.max_requests = 10000
php_admin_value[open_basedir] = "/usr/local/home/domain.com/web"
; All sites .conf
include=/opt/php-fpm/*.conf
slowlog = /var/log/php_slow.log
request_slowlog_timeout = 5s
/opt/php-fpm/time-site.io.conf
[temp-site.io]
user = tempsite
group = tempsite
listen = 127.0.0.1:30739
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_children = 20
pm.process_idle_timeout = 10s
pm.max_requests = 10000
要编译的 php 标志:
--without-apache \
--with-config-file-scan-dir \
--enable-fpm \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-xpm-dir \
--with-vpx-dir \
--with-freetype-dir \
--with-t1lib \
--enable-gd-native-ttf \
--with-openssl \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-intl \
--with-bz2 \
--with-curl \
--enable-dba=shared \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-mcrypt \
--with-mssql \
--with-unixODBC=/usr \
--with-pdo-odbc=unixODBC,/usr \
--with-pdo-dblib \
--with-pdo-pgsql \
--with-pgsql \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xmlrpc \
--with-xsl \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-soap \
--enable-sockets \
--enable-wddx \
--enable-zip \
--with-zlib \
--with-gettext \
--enable-opcache
systemctl cat php72.service
[Unit]
Description=FPM-PHP [PHP php72] TCP 9720
[Service]
ExecStartPre=-/bin/mkdir -p /var/run/php5/php72/
ExecStart=/path/to/php72/sbin/php-fpm --fpm-config /opt/php-fpm/php72.conf --pid /var/run/php5/php72/php72.pid -F
#ExecReload=/bin/kill -USR2 $MAINPID #I have tried this option on and off
PIDFile=/var/run/php5/php72/php72.pid
Restart=on-failure
[Install]
WantedBy=multi-user.target
也许这是 PHP-FPM 的一个错误?或者是我的配置错误?
- 在撰写这篇文章的过程中,我尝试将 pm 配置为按需配置,并且效果更好(没有过程,没有问题),另外,我需要将其变为动态。
我还能检查什么来查看哪里失败了?(欢迎任何帮助)