【问题标题】:Monit configuration for php-fpm监控 php-fpm 的配置
【发布时间】:2011-10-21 08:25:35
【问题描述】:

我正在努力寻找适用于 php-fpm 的监控配置。

这是我尝试过的:

### 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)

【问题讨论】:

    标签: monit php


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      代替:

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

        【讨论】:

          【解决方案4】:

          这是一种通过 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/

          【讨论】:

            【解决方案5】:

            这对我有用

             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
            

            【讨论】:

              【解决方案6】:

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

              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
              

              【讨论】:

                猜你喜欢
                • 2013-03-06
                • 2015-02-02
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2011-12-29
                • 1970-01-01
                相关资源
                最近更新 更多