monit监控配置

官网

配置步骤

安装

# 下载二进制文件
文件目录地址:https://mmonit.com/monit/dist/binary/

# 解压下载的文件到/usr/local/monit
[root@Server-130 monit]# ls
bin  conf  COPYING  man

# 复制配置文件
[root@Server-130 monit]# cp ./conf/monitrc /etc/


# 环境变量
编辑/etc/profile文件,添加:
“
export PATH=/usr/local/monit/bin:$PATH
”

# 生效
[root@Server-130 monit]# . /etc/profile

配置

编辑配置文件

daemon  120                                         # 设置monit作为守护进程运行,并且每2分钟监视一次
set logfile /var/log/monit.log              # 设置日志文件的位置,如果要写入系统日志可以"set logfile syslog"

# monit内置了一个用于查看被监视服务状态的http服务器,需要在防火墙中开启2812
set httpd port 2812 and
#use address localhost  # only accept connection from localhost
use address 192.168.137.130
#allow localhost        # allow localhost to connect to the server and
allow 192.168.137.0/8
allow admin:monit      # require user 'admin' with password 'monit'
#allow @monit           # allow users of group 'monit' to connect (rw)
#allow @users readonly  # allow users of group 'users' to connect readonly

# 设置发送邮件的服务器及邮箱
set mailserver smtp.sina.com port 25 USERNAME "xxx@sina.com" PASSWORD "***" 

# 制定报警邮件的格式
set mail-format {
    from: linlianpengit@sina.com
    subject: $SERVICE $EVENT at $DATE
    message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
}

# 指定邮件接收者
set alert XXX@qq.com with reminder on 3 cycles

# 检测Nginx
check process Nginx with pidfile /var/run/nginx.pid
start program = "/usr/sbin/nginx -c /etc/nginx/nginx.conf"
stop program = "/usr/sbin/nginx -s stop"
if failed host 127.0.0.1 port 80 then restart
if 5 restarts within 5 cycles then timeout

# 检测Tomcat
# tomcat进程默认是不使用pid文件的,pid文件需要显式为tomcat设置,可以打开tomcat目录下的bin目录,打开catalina.sh文件,在开头(非首行)加入:CATALINA_PID=/var/run/catalina.pid
check process Tomcat with pidfile /var/run/tomcat.pid
start program = "/usr/local/apache-tomcat-7.0.70/bin/startup.sh"
stop program  = "/usr/local/apache-tomcat-7.0.70/bin/shutdown.sh"
if failed port 8080 for 5 cycles then restart
if 3 restarts within 5 cycles then timeout

测试配置文件

[root@Server-130 ~]# monit -t
Control file syntax OK

启动

[root@Server-130 ~]# monit

设置monit开机启动

在inittab中加入随系统启动的设置,使得monit进程如果停止,init进程会将其重启

[root@Server-130 ~]# echo "moni:2345:respawn:/usr/local/monit-5.10/bin/monit -Ic /etc/monitrc" >> /etc/inittab

注意

由于将monit设置成了守护进程,并且在inittab中加入了随系统启动的设置,则monit进程如果停止,init进程会将其重启,而monit又监视着其它的服务, 这意味着monit所监视的服务不能使用一般的方法来停止,因为一停止,monit又会将其启动。要停止monit所监视的服务,应该使用monit stop name这样的命令。 例如要停止tomcat:
[root@Server-130 ~]# monit stop tomcat
要停止全部monit所监视的服务可以使用:
[root@Server-130 ~]# monit stop all
启动全部,则是
[root@Server-130 ~]# monit start all

web页面

输入图片说明

转载于:https://my.oschina.net/u/588736/blog/824444

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值