Monitoring

無法讓Monit工作

  • June 4, 2012

我正在嘗試在本地電腦上配置 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應該創建文件。所以我開始監控

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

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

引用自:https://serverfault.com/questions/395413