我正在努力寻找适用于 php-fpm 的 monit 配置。
这是我尝试过的:
### Monitoring php-fpm: the parent process.
check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
group phpcgi # phpcgi group
start program = "/etc/init.d/php-fpm start"
stop program = "/etc/init.d/php-fpm stop"
## Test the UNIX socket. Restart if down.
if failed unixsocket /var/run/php-fpm.sock then restart
## If the restarts attempts fail then alert.
if 3 restarts within 5 cycles then timeout
depends on php-fpm_bin
depends on php-fpm_init
## Test the php-fpm binary.
check file php-fpm_bin with path /usr/sbin/php-fpm
group phpcgi
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
## Test the init scripts.
check file php-fpm_init with path /etc/init.d/php-fpm
group phpcgi
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
但它失败了,因为没有php-fpm.sock (Centos 6)
答案1
我正在使用 php-fpm 中的 ping.path 指令来检查它是否正常工作......
并在 nginx.conf 上进行配置(我不知道这是否是你的设置)
location /ping {
access_log off;
allow 127.0.0.1;
deny all;
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
在 monit.d 上
check process php-fpm.www with pidfile /var/run/php-fpm/php-fpm.pid
group php-fpm
start program = "/etc/init.d/php-fpm start"
stop program = "/etc/init.d/php-fpm stop"
if failed host localhost port 80 protocol http
and request '/ping'
with timeout 20 seconds for 5 cycles
then restart
## If the restarts attempts fail then alert.
if 3 restarts within 5 cycles then timeout
depends on php-fpm_bin
depends on php-fpm_init
depends on nginx
答案2
据我所知,php5-fpm 与其他进程(如 nginx)之间的唯一区别是它的 pid 文件不包含换行符。也许这就是问题所在。无论如何,我的解决方案比较丑陋,但效果也很好:我直接检查“使用 pidfile /var/run/php5-fpm.sock 进程 php-fpm”(同时尝试找到此错误的修复方法)。
答案3
您是否考虑过将 monit 的进程模式匹配与现有的守护进程启动和停止一起使用?
某种形式的matching "php-fpm"
答案4
是否有php-fpm.sock
文件/var/run/php-fpm/php-fpm.sock
?如果有,则修改此行
if failed unixsocket /var/run/php-fpm.sock then restart
智慧
if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart