yum 安装
yum -y install epel-release
yum -y install monit
配置
修改文件: vim /etc/monitrc 或 vim /etc/monit.conf
- set daemon 60 //多久刷新一次
- #set log syslog
- set logfile /var/log/monit.log
- set httpd port 2812 and
- use address 172.20.10.11 //ip地址
- allow 0.0.0.0/0.0.0.0 //允许任何情况下访问
- allow admin:monit //账号密码
- #with ssl { # enable SSL/TLS and set path to server certificate
- # pemfile: /etc/ssl/certs/monit.pem
- #}
- include /etc/monit.d/*
命令
- 启动服务:systemctl start monit 或 service monit start 或 /usr/bin/monit -c /etc/monitrc
- 停止服务:systemctl stop monit
- 重启服务:systemctl restart monit
- 查看服务运行状态:systemctl status monit -l
- 查看日志: tailf /var/log/monit.log
访问: http://ip:2812
配置文件默认在etc/monitrc
配置监听选项在etc/monit.d目录下
监控nginx
- vi /etc/monit.d/nginx.monit
- check process nginx with pidfile /usr/local/nginx/nginx.pid
- start program = "/usr/local/nginx/sbin/nginx"
- stop program = "/usr/local/nginx/sbin/nginx -s stop"
- if failed host 192.168.1.11 port 8011 protocol http then restart
监控redis
- vi /etc/monit.d/memcached.monit
- check process redis with pidfile /tmp/redis.pid
- start program = "/etc/rc.d/init.d/redis start"
- stop program = "/etc/rc.d/init.d/redis stop"
- if failed host 192.168.1.10 port 6379protocol memcache then restart
监控mysql
- vi /etc/monit.d/mysqld.monit
- check process mysqld with pidfile /data/mysql/mysql.pid
- start program = "/etc/init.d/mysqld start"
- stop program = "/etc/init.d/mysqld stop"
- if failed host 192.168.1.10 port 3306 then restart
- if 5 restarts within 5 cycles then timeout
上面所pid 根据自己目录下稍作修改!!!
服务相关命令
- start all
- 启动所有的监控的服务
- stop all
- 停止所有的监控的服务
- restart all
- 重启所有的监控的服务
- monitor all
- 监控所有的服务
- unmonitor all
- 取消对所有服务的监控
- start name
- 启动指定的服务
- stop name
- 停止指定的服务
- restart name
- 重启指定的服务
- monitor name
- 监控指定的服务
- unmonitor name
- 取消对指定服务的监控