歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> 教你使用monit監控Linux系統

教你使用monit監控Linux系統

日期:2017/3/2 16:33:53   编辑:Linux服務器

 Monit 是用於對系統中的進程、文件、目錄、以及設備等進行監視和管理的工具。當你所指定的server宕機或者沒有反應,monit會將該進程殺死並重啟該server。並通過郵件進行通知。Monit 包含一個內嵌的 HTTP(S) Web 界面,你可以使用浏覽器方便地查看 Monit 所監視的服務器。

  Monit的官方網站: http://www.mmonit.com

  下面將介紹monit在CentOS5.3上的安裝和配置:

  download:http://mmonit.com/monit/dist/monit-5.1.1.tar.gz

  shell > tar xzvf monit-5.1.1.tar.gz

  shell> cd monit-5.*

  shell>./configure

  shell>make

  shell> make install

  shell> rm /etc/monitrc

  shell> cp monitrc /etc/

  在inittab文件中添加下面這句話,使init守護monit進程!!

  shell> vi /etc/inittab

  mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc

  現在安裝完成了,是不是超簡單!!

  接下來就是配置了!!

  Monitrc文件########################################################

  set daemon 120 #設置monit檢查的間隔時間,單位是秒!!

  set logfile syslog facility log_daemon #用syslog來記錄log

  set logfile /var/logs/monit.log #設置日志路徑

  set idfile /var/.monit.id #設置PID文件的位置

  set mailserver 192.168.0.21, # primary mailserver 郵件服務器的IP

  set mail-format { from: [email protected] } #設置你的郵件從哪個賬號發出

  set alert [email protected] #發到我的139郵箱,用139郵箱是因為139有一個郵件到達通知功能

  set httpd port 2812 and #設置monit監聽的端口號

  use address 192.168.0.21 # 設置monit服務器的IP,可以讓你方便的http訪問

  allow admin:pass #設置用戶名和密碼

  ################################# Services ##############################

  監控服務器的磁盤使用情況

  check device system with path /dev/mapper/VolGroup00-LogVol00

  if space usage > 85% for 5 times within 15 cycles then alert

  if space usage > 95% then stop

  if inode usage > 85% then alert

  if inode usage > 95% then stop

  ######################################################

  #sshd 監控sshd進程

  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 then restart

  if 5 restarts within 5 cycles then timeout

  #######################################################

  #cron 監控crontab進程

  check process cron with pidfile /var/run/crond.pid

  group system

12下一頁

Copyright © Linux教程網 All Rights Reserved