1. 安裝monit:
# zypper in monit2. 編輯設定檔/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的設定:4. 啟動monit:
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
# /etc/init.d/monit start5. 測試:
# chkconfig monit on
- 手動將sshd stop:
# /etc/init.d/sshd stop
- 開始monitor:suse:/var/run # /etc/init.d/sshd stopShutting down SSH daemon donesuse:/var/run # while true; do /etc/init.d/sshd status; sleep 1; doneChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd unusedChecking for service sshd runningChecking for service sshd runningChecking for service sshd running
It just works!
Reference: http://cha.homeip.net/blog/2011/06/3134.html