Friday, June 24, 2011

Monit on OpenSUSE

Monit可以偵測本機的某些服務,當有異常時,可以透過它重新啟動daemon,以下是實作在OpenSUSE的系統上。

1. 安裝monit:
# zypper in monit
2. 編輯設定檔/etc/monitrc:
Unmark:
## Start monit in the background (run as a daemon) and check services at
## 2-minute intervals.
#
set daemon 60 <- 我把它改成1分鐘。

3. 新增偵測sshd daemon:
- 開啟/etc/monitrc並新增偵測sshd的設定:
check process sshd with pidfile /var/run/sshd.init.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
4. 啟動monit:
# /etc/init.d/monit start
# chkconfig monit on
5. 測試:
- 手動將sshd stop:
# /etc/init.d/sshd stop
- 開始monitor:
suse:/var/run # /etc/init.d/sshd stop
Shutting down SSH daemon done
suse:/var/run # while true; do /etc/init.d/sshd status; sleep 1; done
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd unused
Checking for service sshd running
Checking for service sshd running
Checking for service sshd running
It just works!
Reference: http://cha.homeip.net/blog/2011/06/3134.html

No comments: