Monit 配置 PHP-FPM

10

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

15

对于其他在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

6

改为:

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

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

1

这对我来说是工作

 check process php5-fpm with pidfile /var/run/php5-fpm.pid
  start program = "/usr/sbin/service php5-fpm start" with timeout 60 seconds
  stop program = "/usr/sbin/service php5-fpm stop"
  if cpu > 60% for 2 cycles then alert
  if cpu > 90% for 5 cycles then restart
  if 3 restarts within 5 cycles then timeout
  group server

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/


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接