apt-get install monit -y
啟動服務
systemctl start monit systemctl enable monit
可以利用與下指令觀察執行狀態
systemctl status monit
編輯設定檔
vi /etc/monit/monitrc
設定網監看服務(2812 port 可不改,或自行修改,因為中心只開放3389,所以,才修改之),另外,偵測系統swap若超過75%就重啟apache
set mailserver mail.tn.edu.tw, # 設定郵寄伺服器
localhost # fallback relay
set mail-format {
from: Monit <monit@$HOST>
subject: 通知 $HOST -- $EVENT $SERVICE
message:
$EVENT => $SERVICE
日期: $DATE
動作: $ACTION
主機: $HOST
說明: $DESCRIPTION
http://網址:port
}
set alert tad@tn.edu.tw # 接收所有 alerts 訊息的信箱
set httpd port 3389 and
use address 0.0.0.0 # 我要讓他可以對外連線
allow 0.0.0.0/0.0.0.0 # 開放所有IP都可以連得到
allow 帳號:密碼 # require user 'admin' with password 'monit'
check system $HOST
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if cpu usage > 95% for 10 cycles then alert
if memory usage > 75% then alert
if swap usage > 25% then alert
if swap usage > 75% for 5 cycles then exec "/usr/sbin/apachectl restart"
修改後,重啟服務
systemctl restart monit
看看是否有在監聽
netstat -ant | grep :3389
此時可自行輸入「http://網址:3389」看看是否能登入觀看。亦可下指令在終端機中觀看狀態:
monit status
加入Apache、MySQL、Rsyslog監控
ln -s /etc/monit/conf-available/apache2 /etc/monit/conf-enabled/ ln -s /etc/monit/conf-available/mysql /etc/monit/conf-enabled/ ln -s /etc/monit/conf-available/rsyslog /etc/monit/conf-enabled/
ln -s /etc/monit/monitrc.d/apache2 /etc/monit/conf.d/ ln -s /etc/monit/monitrc.d/mysql /etc/monit/conf.d/ ln -s /etc/monit/monitrc.d/rsyslog /etc/monit/conf.d/
記得重啟,使之生效
systemctl restart monit
vi /etc/monit/conf-available/apache2
加入一行到原有 if 的前面:
if memory usage > 80% for 5 cycles then restart
記得重啟,使之生效
systemctl restart monit
vi /etc/monit/conf-available/mysql
將第6行註解掉:
#if failed host localhost port 3306 protocol mysql with timeout 15 seconds for 3 times within 4 cycles then restart
記得重啟,使之生效
systemctl restart monit