:::

14. 加入monit監控

  1. 安裝
    apt-get install monit -y
  2. 啟動服務

    systemctl start monit
    systemctl enable monit
  3. 可以利用與下指令觀察執行狀態

    systemctl status monit

主要設定

  1. 編輯設定檔

    vi /etc/monit/monitrc
  2. 設定網監看服務(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 [email protected]                       # 接收所有 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"
    
  3. 修改後,重啟服務

    systemctl restart monit
  4. 看看是否有在監聽

    netstat -ant | grep :3389
  5. 此時可自行輸入「http://網址:3389」看看是否能登入觀看。亦可下指令在終端機中觀看狀態:

    monit status
  6. 加入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/
  7. 2017年以前的版本為
    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/
  8. 記得重啟,使之生效

    systemctl restart monit

讓記憶體不足時,Apache2自動啟動

  1. 修改給Apache用的設定檔
    vi /etc/monit/conf-available/apache2
  2. 加入一行到原有 if 的前面:

    if memory usage > 80% for 5 cycles then restart
  3. 記得重啟,使之生效

    systemctl restart monit

讓MySQL可以連接得上

  1. 修改給MySQL用的設定檔
    vi /etc/monit/conf-available/mysql
  2. 將第6行註解掉:

    #if failed host localhost port 3306 protocol mysql with timeout 15 seconds for 3 times within 4 cycles then restart
  3. 記得重啟,使之生效

    systemctl restart monit

:::

書籍目錄

展開 | 闔起

快速登入


http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1000%26tbsn%3D15

計數器

今天: 1318131813181318
昨天: 2665266526652665
總計: 8074755807475580747558074755807475580747558074755