我正在尝试在本地机器上配置 Monit 以了解其工作原理,但遇到了一些问题。
我想要做的是获取任何证据表明 Monit 已启动并正常运行和实际上是在监控一些东西。所以我的/etc/monit/monitrc
看起来像
set daemon 60
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set eventqueue
basedir /var/lib/monit/events
slots 100
set httpd port 2812 and
allow username:password
check process apache2 with pidfile /usr/local/apache/logs/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed port 6543 protocol http then exec "/usr/bin/touch /tmp/monit"
如果我理解正确的话,由于 apache 不监听端口 6543(它只是一个随机数),我应该会收到错误,因此/tmp/monit
应该创建该文件。因此我通过以下方式启动 monit:
sudo service monit start
sudo monit monitor apache2
不幸的是,没有创建这样的文件。相反,Web 控制台显示 apache - 的错误execution failed
。日志显示'apache2' failed to start
。
我究竟做错了什么?
编辑正如评论中所建议的,我以详细模式运行了 monit,方法是
monit -vv monitor apache2
(注释中建议的确切命令失败)。输出是
Runtime constants:
Control file = /etc/monit/monitrc
Log file = /var/log/monit.log
Pid file = /var/run/monit.pid
Debug = True
Log = True
Use syslog = False
Is Daemon = True
Use process engine = True
Poll time = 60 seconds with start delay 0 seconds
Expect buffer = 256 bytes
Event queue = base directory /var/lib/monit/events with 100 slots
Mail from = (not defined)
Mail subject = (not defined)
Mail message = (not defined)
Start monit httpd = True
httpd bind address = Any/All
httpd portnumber = 2812
httpd signature = True
Use ssl encryption = False
httpd auth. style = Basic Authentication
The service list contains the following entries:
Process Name = apache2
Pid file = /usr/local/apache/logs/apache2.pid
Monitoring mode = active
Start program = '/etc/init.d/apache2 start' timeout 30 second(s)
Stop program = '/etc/init.d/apache2 stop' timeout 30 second(s)
Existence = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
Pid = if changed 1 times within 1 cycle(s) then alert
Ppid = if changed 1 times within 1 cycle(s) then alert
Port = if failed localhost:6543 [HTTP via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then exec '/usr/bin/touch /tmp/prova-monit' timeout 0 cycle(s) else if succeeded 1 times within 1 cycle(s) then alert
System Name = system_andrea-Vostro-420-Series
Monitoring mode = active
答案1
PID 文件通常位于 下/var/run
。
在您的中,/etc/monit/monitrc
您引用了下的 pidfile /usr/local/apache/logs/apache2.pid
。
尝试更改它以匹配 Apache 的 pidfile /var/run
。
它应该是下列之一:
/var/run/httpd.pid
或者
/var/run/apache2.pid