官网nginx
# 下载二进制文件 文件目录地址: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
在inittab中加入随系统启动的设置,使得monit进程若是中止,init进程会将其重启git
[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