詳見(jiàn):http://www.51testing.com/html/86/n-214186.html
示例,監(jiān)聽(tīng)ssh服務(wù),如果停止則自動(dòng)重啟服務(wù),步驟如下:
1、vi /etc/monit.d/sshd.monit。
2、撰寫(xiě)內(nèi)容,如下:
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 then restart
if 5 restarts within 5 cycles then timeout
3、如果要設(shè)置monit的相關(guān)參數(shù),比如多長(zhǎng)時(shí)間檢測(cè)一次,請(qǐng)修改/etc/monit.conf,示例文件如下:
set daemon 300
set logfile /var/log/monit.log
set idfile /var/monit/id
set statefile /var/monit/state
set httpd port 2812 and use address 127.0.0.1
allow 127.0.0.1
allow surfront:surfront
check system 127.0.0.1
include /etc/monit.d/*.monit
4、重啟monit服務(wù),/etc/init.d/monit restart。
5、完畢,monit的相關(guān)日志位于/var/log/monit.log。