目的: 定時檢查各種系統服務, 若發現異常則重啟該服務。
環境: Fedora 9
yum install monit
vi /etc/monit.conf
#每 60 秒檢查一次
set daemon 60
 
#設定檔位置
include /etc/monit.d/*
cd /etc/monit.d/
vi sshd.conf
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 host 127.0.0.1 port 22 protocol ssh then restart
vi httpd.conf
check process httpd with pidfile /var/run/httpd.pid
  start program = "/etc/init.d/httpd start"
  stop program = "/etc/init.d/httpd stop"
  if failed port 80 type tcp then restart
vi named.conf
check process named with pidfile /var/run/named.pid
  start program = "/etc/init.d/named start"
  stop program = "/etc/init.d/named stop"
  if failed port 53 type udp then restart
vi saslauthd.conf
check process saslauthd with pidfile /var/run/saslauthd/saslauthd.pid
  start program "/etc/init.d/saslauthd start"
  stop program "/etc/init.d/saslauthd stop"
vi mailarchiva.conf
check host localhost with address 127.0.0.1
  start program = "/usr/local/mailarchiva/server/startserver.sh"
  if failed port 8090 then start
chkconfig monit on && service monit start
Ref:
(Visited 419 times, 1 visits today)