恒美微站
首页
关于我们
建站服务
主题模板
案例展示
资讯中心
联系我们
使用M/Monit对Monit监控进行可视化集中管理
首页
资讯中心
/
使用M/Monit对Monit监控进行可视化集中管理
使用M/Monit对Monit监控进行可视化集中管理
发布时间:2026/9/13 22:42:41
一前言Monit是一个开源监控管理工具类似supervisor能够监控linux系统的负载、文件、进程等。当系统负载过高、监控文件被篡改、进程异常退出时能够发送邮件报警并能够自动启动或关闭异常进程。Monit内嵌web界面能够看到当前主机上的监控项状态。M/Monit是一个集中式管理多台Monit的可视化工具也是收费工具可以免费试用30天。二规划M/Monit集中管理 192.168.0.1Monit监控机 192.168.0.2Monit监控机 192.168.0.3三安装M/Monit1安装M/Monit1234$cd/opt$wget https://mmonit.com/dist/mmonit-3.5.1-linux-x64.tar.gz$tarxf mmonit-3.5.1-linux-x64.tar.gz$cdmmonit-3.5.12配置M/Monit1:MMonit的配置文件是conf/server.xml不需要任何改动即可使用默认配置是8080端口。1Connector address*port8080processors10/2:MMonit默认使用的是包内自带的sqlite3数据库默认配置如下1234Realm urlsqlite:///db/mmonit.db?synchronousnormalheap_limit8000foreign_keysonjournal_modewalminConnections5maxConnections25reapConnections300/也可以改成mysql和postgresql数据库.以myqsl为例使用默认的sqlite可以跳过修改sqlite配置为1234Realm urlmysql://mmonit:passwd10.10.10.10/mmonitminConnections5maxConnections25reapConnections300/并导入mysql数据库1$mysql -ummonit -ppasswd /opt/mmonit-3.5.1/db/mmonit-schema.mysql3启动M/Monit1$bin/mmonit-c conf/server.xml4启动M/Monit访问 192.168.0.1:8080显示登录页。默认用户名userpassword权限adminswordfish管理员monitmonit普通用户登录进去后里面是空白的No hosts这是因为monit还没有加入进来下面配置monit四安装配置monit1安装Monit192.168.0.2 192.168.0.31234$cd/opt$wget https://mmonit.com/monit/dist/binary/5.19.0/monit-5.19.0-linux-x64.tar.gz$tarxf monit-5.19.0-linux-x64.tar.gz$cdmonit-5.19.02配置Monit12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667$vim conf/monitrc#检测周期setdaemon 30#进程文件配置setlogfile syslogsetpidfile/var/run/monit.pidsetidfile/var/.monit.idsetstatefile/var/.monit.state#事件队列seteventqueue basedir/var/monitslots 100#配置mmonit将监控数据发送至MMonit进行统一展示setmmonit http://monit:monit192.168.0.1:8080/collector#邮件服务器地址setmailserver 10.10.10.10 port 25usernamemonitcctv.compasswordmonit#自定义发送邮件格式$DATE等都是monit内置变量setmail-format{from: Monitcctv.comsubject: monit alert -- $EVENT $SERVICEmessage: $EVENT Service $SERVICEDate: $DATEAction: $ACTIONHost: $HOSTDescription: $DESCRIPTION}#设置报警收件人setalert zhangsancctv.comsetalert lisicctv.com#配置https用于web界面由于使用MMonit的界面管理也可以不配置.sethttpd port 2812 anduse address localhostallow localhostallow admin:monit#----以下为监控项以几个常见监控项为例----##检查monit配置文件更新checkfilemonitrc path/opt/monit-5.19.0/conf/monitrcifchanged sha1 checksumthenexec/opt/monit-5.19.0/bin/monit -c /opt/monit-5.19.0/conf/monitrc reload#检查系统负载check system 192.168.0.2group systemifloadavg (1min) 4thenalertifloadavg (5min) 2thenalertifcpu usage 95%for10 cyclesthenalertifmemory usage 75%thenalertifswap usage 25%thenalert#磁盘各目录空间check filesystem root with path /group systemifspace usage 90%thenalertcheck filesystem usr with path/usrgroup systemifspace usage 80%thenalertcheck filesystem var with path/vargroup systemifspace usage 90%thenalert#监控ssh服务check process sshd with pidfile/var/run/sshd.pidstart program/etc/init.d/sshd startstop program/etc/init.d/sshd stopiffailed host 127.0.0.1 port 22 protocolsshthenrestart#监控nginx不仅可以监控进程PID文件的变化还可以监控80端口check process nginx with pidfile/var/run/nginx.pidstart program /etc/init.d/nginx startwith timeout 60 secondsstop program /etc/init.d/nginx stopifchanged pidfor5 cyclesthenrestartiffailed port 80 protocol http with timeout 2 secondsthenalert3启动monit1$bin/monit-c conf/monitrc4访问MMonit192.168.0.1:8080已经能够看到192.168.0.2和192.168.0.3两台机器。点进去机器可以看到该机器的监控项包括系统监控、进程监控、文件系统、配置文件监控。大功告成此时你可以去机器上试一试手动kill掉nginx进程你会发现进程会自动被拉起。下面放两张我使用监控ELK集群的图机器多一点。