首页 > 系统相关 >教你使用monit监控Linux系统

教你使用monit监控Linux系统

时间:2022-11-11 23:36:56浏览次数:48  
标签:shell etc monit failed 监控 Linux unmonitor check



 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> 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文件########################################################

120       


  set logfile /var/logs/monit.log #设置日志路径

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

192.168.0.21,               # primary mailserver 


                   

                                              

 

    


  监控服务器的磁盘使用情况

  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

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

 

  check process sshd with pidfile /var/run/sshd.pid

  start program "/etc/init.d/sshd start"



  if 5 restarts within 5 cycles then timeout

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

     

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

  group system

start program = "/etc/init.d/crond start"

  stop program = "/etc/init.d/crond stop"

      

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

 

  check file cut_nginx_log.sh with path /scripts/cut_nginx_log.sh

  group scripts

  if failed checksum then unmonitor

  if failed permission 755 then unmonitor

  if failed uid root then unmonitor

  if failed gid root then unmonitor

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

              

  check file passwd with path /etc/passwd

  group system

  if failed checksum then unmonitor

  if failed permission 644 then unmonitor

  if failed uid root then unmonitor

  if failed gid root then unmonitor

  check file group with path /etc/group

  group system

  if failed checksum then unmonitor

  if failed permission 644 then unmonitor

  if failed uid root then unmonitor

  if failed gid root then unmonitor

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

  # 监控本机的25,110端口号

  check host localhost with address 127.0.0.1


  if failed port 110 protocol pop with timeout 15 seconds then exec "/usr/bin/vpopmailctl restart"

  基本的配置就是这样子,剩下的就是根据各自的实际情况进行修改!!!,配置好从浏览器登录查看下是否成功,接下来就是轻松的喝喝茶,逛逛论坛了!! 哈哈





​​#Linux​​



标签:shell,etc,monit,failed,监控,Linux,unmonitor,check
From: https://blog.51cto.com/u_2776699/5845575

相关文章