【问题标题】:Monit on CentOS causes httpd.pid not to be createdCentOS 上的 Monit 导致 httpd.pid 无法创建
【发布时间】:2011-04-28 13:14:48
【问题描述】:

解决方案是替换这一行:

check process apache with pidfile /var/run/httpd.pid

用这一行:

check process httpd with pidfile /var/run/httpd/httpd.pid

我还删除了“组 apache”。

原帖:

在 CentOS 上安装 Monit 并为 Apache (httpd) 服务设置警报后,该服务不再创建 /var/run/httpd.pid 文件。

httpd 服务IS运行正常。

最重要的是,好像这还不够,Monit 将服务状态报告为:执行失败

当然,重新启动此类服务的唯一方法是杀死它,因为“重新启动”脚本看不到任何正在运行的进程。

这些是 /etc/monit.d/monitrc 文件的内容:

set daemon  10
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: me@server.com }
set alert bugs@server.com
set httpd port 2812 and
#     SSL ENABLE
#     PEMFILE  /var/certs/monit.pem
allow user:password

check process apache with pidfile /var/run/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program  = "/etc/init.d/httpd stop"
if cpu is greater than 180% for 1 cycles then alert
if totalmem > 1200 MB for 2 cycles then restart
if children > 250 then restart

check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/sshd start"
stop program "/etc/init.d/sshd stop"
if failed port 22 protocol ssh for 5 cycles then restart
if 5 restarts within 25 cycles then timeout

“服务 httpd 重启”的输出:

Stopping httpd:                                            [FAILED]
Starting httpd: (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
                                                       [FAILED]

任何帮助将不胜感激。

【问题讨论】:

  • 你不是说“monit restart httpd”吗? “monit stop httpd”和“monit start httpd”怎么样? monit stop/start/restart sshd OK 吗?
  • 谢谢阿布内塔。做restart时,stop,用monit启动到httpd,没有消息。但服务也没有停止。我无法尝试停止 sshd,因为它会让我离开我的机器 :-)
  • 尝试使用此处的建议:stackoverflow.com/questions/3356476/debugging-monit/… 以更好地了解 monit 调用停止时发生的情况。我假设当你从命令行调用它时,monitrc 中的 stop 命令有效。关于“monit restart sshd”;我仍然建议尝试将其作为健全性检查。如果它不起作用,您将设法以某种方式回到机器中:-)
  • 问题是,由于某种原因,服务的 Monit 重新启动最终会删除进程 ID 文件,而不会创建新文件。解决方案是在重新启动服务之前将正确的 ID 回显到 ID 文件中。
  • 能否请您提供用于实现此目的的命令。我也有同样的问题。

标签: apache pid monit


【解决方案1】:

尝试将停止程序替换为/usr/sbin/httpd -k stop。它对我有用。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,但 /usr/sbin/httpd -k stop 似乎没有帮助,因为它仍然试图从 pid 文件中查找进程 ID。

    我选择了stop program = "/usr/bin/killall httpd"。我认为这不是很优雅(可能会杀死打开的请求),但这是我能找到重新启动 apache 并由 monit 重新创建 pid 文件的唯一方法。

    【讨论】:

      【解决方案3】:

      我认为 monit 正在以 'stop; 的形式重新启动; start' 并且在开始新进程之前没有等待 'stop' 完成,因此在不适当的时间删除 pid 文件。至少,这是我在修补所有这些后得出的结论。

      我发现有人通过在“停止”语句后使 monit sleep 来解决此问题。

      就我个人而言,我发现在 http 服务器关闭时将“重启”替换为“启动”效果很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多