无法让Monit工作

我试图在我的本地机器上configurationMonit以了解它是如何工作的,但是我有一些问题。

我想要做的是获得任何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(这只是一个随机数),我应该得到一个错误,所以应该创build文件/tmp/monit 。 所以我开始监视

 sudo service monit start sudo monit monitor apache2 

不幸的是没有创build这样的文件。 Web控制台显示apache错误 – execution failed 。 日志说'apache2' failed to start

我究竟做错了什么?

编辑正如在评论中所build议的,我用详细模式运行monit

 monit -vv monitor apache2 

(在评论中build议的确切命令失败)。 输出是

 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 

PID文件通常位于/var/run

在你的/etc/monit/monitrc你引用了一个在/usr/local/apache/logs/apache2.pid下的pidfile。

尝试改变这个来匹配/var/run中的Apache的pid文件。

它应该是以下之一:

 /var/run/httpd.pid 

要么

 /var/run/apache2.pid