用于php-fpm的Monit配置

时间:2011-10-21 08:25:35

标签: monit php

我很难找到适用于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

但它失败了,因为没有 php-fpm.sock (Centos 6)

6 个答案:

答案 0 :(得分:14)

对于在Centos 6上遇到此问题的其他人, php-fpm 套接字位于/var/run/php-fpm/php-fpm.sock

因此,最终配置将是这样的:

check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
  group phpcgi #change accordingly
  start program = "/etc/init.d/php-fpm start"
  stop program  = "/etc/init.d/php-fpm stop"
  if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart
  if 3 restarts within 5 cycles then timeout

答案 1 :(得分:4)

而不是:

if failed unixsocket /var/run/php-fpm.sock then restart
你可以试试:

if failed port 9000 type TCP then restart

不需要像location /ping一样编辑lighttpd / nginx配置。

我在Ubuntu上的/etc/monit/conf.d/php-fpm.conf看起来像这样:

check process php-fpm with pidfile /var/run/php5-fpm.pid
  stop program = "/sbin/start-stop-daemon --stop --pidfile /var/run/php5-fpm.pid"
  start program  = "/sbin/start-stop-daemon --start --pidfile /var/run/php5-fpm.pid --exec /usr/sbin/php5-fpm"
  if failed port 9000 type TCP then restart

答案 2 :(得分:3)

我在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;
}

答案 3 :(得分:1)

这是一种通过TCP连接检查php-fpm的方法(比简单的.pid更可靠):

# Empty FastCGI request
if failed port 8101
  # Send FastCGI packet: version 1 (0x01), cmd FCGI_GET_VALUES (0x09)
  # padding 8 bytes (0x08), followed by 8xNULLs padding
  send "\0x01\0x09\0x00\0x00\0x00\0x00\0x08\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00"
  # Expect FastCGI packet: version 1 (0x01), resp FCGI_GET_VALUES_RESULT (0x0A)
  expect "\0x01\0x0A"
  timeout 5 seconds
then restart

来源:http://richard.wallman.org.uk/2010/03/monitor-a-fastcgi-server-using-monit/

答案 4 :(得分:1)

这对我有用

Search results

答案 5 :(得分:0)

这是在我的debian 7上运行nginx和php5-fpm;

check process php5-fpm with pidfile /var/run/php5-fpm.pid
group php #change accordingly
start program = "/etc/init.d/php5-fpm start"
stop program  = "/etc/init.d/php5-fpm stop"
if failed unixsocket /tmp/php-fpm.sock then restart
if 3 restarts within 5 cycles then timeout