Monit监控软件安装

Monit监控软件安装Monit 是一款功能非常丰富的进程 文件 目录和设备的监测软件 适用于 Linux Unix 平台 官网地址 https mmonit com 在 CentOS6 4 上配置 Monit 的步骤 我们以服务器 IP 地址 10 153 126 189 为例进行配置 监控 10 153 110 12 10 153 75 78 这两台服务器 一 安装 Monit yuminstallmo

我们以服务器IP地址:10.153.126.189,为例进行配置,监控10.153.110.12, 10.153.75.78这两台服务器。

一、安装Monit:

# yum install monit –y

这一步可能会报错:

# yum install monit –y Loaded plugins: fastestmirror, security Determining fastest mirrors Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

解决方法:

vi /etc/yum.repos.d/epel.repo

编辑[epel]下的baseurl前的#号去掉,mirrorlist前添加#号。正确配置如下:

[epel] name=Extra Packages for Enterprise Linux 6 - $basearch baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

至此Monit安装完毕,接下来配置monit.conf文件

二、monit配置:

1、文件位置在/etc/monit.conf,修改常见配置:

1)检测时间、日志位置:

set daemon 120 with start delay 240 set logfile syslog facility log_daemon

每120s检测一次;启动后延时240s开始检测;

日志文件位置;

2)id文件

set idfile /var/monit/id set eventqueue basedir /var/monit

3)设置web界面:

set httpd port 1966 and SSL ENABLE PEMFILE /var/certs/monit.pem allow monituser:romania allow localhost allow 192.168.0.0/16 allow myhost.mydomain.ro

2、监控信息可以直接写到/etc/monit.conf文件中,也可以单独创建一个.cfg后缀的文件,将check… if 语句添加到里面,然后在monit.conf文件末尾加入include路径。

set daemon 30 # 每30秒查询一次服务器状态 set logfile /data/apps/monit/log/monit.log # 默认日志位于 /var/log/monit set idfile /var/.monit.id set eventqueue basedir /data/apps/monit/data slots 10000 set httpd port 2812 and # 监听2812端口 use address 10.153.126.189 # 本服务器地址,这里我们的Monit安装到了10.153.126.189这台服务器上。 allow localhost allow 10.1.0.0/255.255.0.0 allow admin : pin # 在这里设置用户名及口令。admin为用户名,冒号后为密码。 # 接下来设置要监听的服务器 # address后面的是服务器的IP地址。第二行设置port端口号。exec后为当异常情况出现后执行的脚本。可以添加多个check ... if 语句,同时监听很多台服务器 # 这里 /data/apps/monit/contrib/sms.py这个脚本负责报警 check host read_kajuan_10.153.110.12 with address 10.153.110.12 if failed port 80 with timeout 1 seconds for 2 cycles then exec "/data/apps/monit/contrib/sms.py" check host read_kajuan_10.153.75.78 with address 10.153.75.78 if failed port 80 with timeout 1 seconds for 2 cycles then exec "/data/apps/monit/contrib/sms.py" #include /etc/monit.d/*

三、常见监控:

1、根据ip+端口,监控web服务器端口存活:

check host gamecenter_api_10.153.123.2 with address 10.153.123.2 if failed port 8093 with timeout 1 seconds for 2 cycles then exec "/data/apps/monit/contrib/sms.py"

表示:在两次监控周期内,如果端口超时超过1m则报警。

2、根据pid,监控服务进程:

check process tomcat with pidfile /var/run/catalina.pid # 进程pid start program = "/etc/init.d/tomcat start" # 设置启动命令 stop program = "/etc/init.d/tomcat stop" # 设置停止命令 if 9 restarts within 10 cycles then timeout # 设置在10个监视周期内重,启了9次则超时,不再监视这个服务。原因另外说明【3】 if cpu usage > 90% for 5 cycles then alert # 如果在5个周期内该服务的cpu使用率都超过90%则提示 if failed url http://127.0.0.1:4000/ timeout 120 seconds for 5 cycles then restart # 若连续5个周期打开url都失败(120秒超时,超时也认为失败)则重启服务

设置超时后不再监视是为了让服务不要一直重启,如果连续重启多次不成功,极有可能再重启下去也不会成功的。并且tomcat的重启需要占用大量系统资源,假如一直重启下去,反而会使其它服务也无法正常运作。

3、可以对moint本身服务器进行监控:

# 系统名称,可以是IP或域名 check system www.example.com if loadavg (1min) > 4 then alert if loadavg (5min) > 2 then alert if memory usage > 75% then alert if cpu usage (user) > 70% then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert

4、实例:

# # 监控nginx # # 需要提供进程pid文件信息 check process nginx with pidfile /var/run/nginx.pid # 进程启动命令行,注:必须是命令全路径 start program = "/etc/init.d/nginx start" # 进程关闭命令行 stop program = "/etc/init.d/nginx stop" # nginx进程状态测试,监测到nginx连不上了,则自动重启 if failed host www.example.com port 80 protocol http then restart # 多次重启失败将不再尝试重启,这种就是系统出现严重错误的情况 if 3 restarts within 5 cycles then timeout # 可选,设置分组信息 group server # 可选的ssl端口的监控,如果有的话 # if failed port 443 type tcpssl protocol http # with timeout 15 seconds # then restart # # 监控apache # check process apache with pidfile /var/run/apache2.pid start program = "/etc/init.d/apache2 start" stop program = "/etc/init.d/apache2 stop" # apache吃cpu和内存比较厉害,额外添加一些关于这方面的监控设置 if cpu > 50% for 2 cycles then alert if cpu > 70% for 5 cycles then restart if totalmem > 1500 MB for 10 cycles then restart if children > 250 then restart if loadavg(5min) greater than 10 for 20 cycles then stop if failed host www.example.com port 8080 protocol http then restart if 3 restarts within 5 cycles then timeout group server # 可选,依赖于nginx depends on nginx # # 监控spawn-fcgi进程(其实就是fast-cgi进程) # check process spawn-fcgi with pidfile /var/run/spawn-fcgi.pid # spawn-fcgi一定要带-P参数才会生成pid文件,默认是没有的 start program = "/usr/bin/spawn-fcgi -a 127.0.0.1 -p 8081 -C 10 -u userxxx -g groupxxx -P /var/run/spawn-fcgi.pid -f /usr/bin/php-cgi" stop program = "/usr/bin/killall /usr/bin/php-cgi" # fast-cgi走的不是http协议,monit的protocol参数也没有cgi对应的设置,这里去掉protocol http即可。 if failed host 127.0.0.1 port 8081 then restart if 3 restarts within 5 cycles then timeout group server depends on nginx

注意:

  1. start和stop的program参数里的命令必须是全路径,否则monit不能正常启动,比如killall应该是/usr/bin/killall。
  2. 对于spawn-fcgi,很多人会用它来管理PHP的fast-cgi进程,但spawn-fcgi本身也是有可能挂掉的,所以还是需要用monit来监控spawn-fcgi。spawn-fcgi必须带-P参数才会有pid文件,而且fast-cgi走的不是http协议,monit的protocol参数也没有cgi对应的设置,一定要去掉protocol http这项设置才管用。
  3. 进程多次重启失败monit将不再尝试重启,收到这样的通知邮件表明系统出现了严重的问题,要引起足够的重视,需要赶紧人工处理。
  4. 当然monit除了管理进程之外,还可以监控文件、目录、设备等,本文不做讨论,具体配置方式可以去参考monit的官方文档。

参考:

http://www.cnblogs.com/ddr888/archive/2011/03/02/1969087.html

http://feilong.me/2011/02/monitor-core-processes-with-monit

http://www.vpser.net/manage/monit.html

http://itoedr.blog.163.com/blog/static/267/

https://www.rails365.net/articles/bu-shu-zhi-shi-yong-monit-lai-jian-kong-fu-wu-si

http://linuxjcq.blog.51cto.com//

https://segmentfault.com/a/67212

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/224760.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 上午11:12
下一篇 2026年3月17日 上午11:12


相关推荐

  • C#使用WebProxy实现代理访问webservice

    C#使用WebProxy实现代理访问webservice1.问题描述标题写的有点含糊不清,不好意思语言表达能力欠佳。。事情是这样的!事情是这样的,在A服务器上有一个webservice,B计算机和C计算机都可以ping通A服务器,但是C计算机的ip备案了而B计算机的ip没有备案,导致我写的一个小程序放在B计算机上调用A服务器的webservice的时候提示我ip非法。那么该如何让这个小程序能在B计算机上正常使用呢?答案是代理服务器!2.w…

    2022年6月21日
    68
  • mysql 10055 解决_mysql 10055 错误解决方案

    mysql 10055 解决_mysql 10055 错误解决方案Description 环境 Windows2003 IIS PHP MYSQL 服务器运行一段时间后 提示 Can tconnecttoMy localhost 10055 错误 无法重启 mysql 服务 提示端口被占 检查发现端口并没被占 重起服务器后恢复正常 但过一段时间以后 又出现此错误 查看 MYSQL 日志 并无不正常记录 Solution 此

    2026年3月20日
    3
  • LNK2001:无法解析外部符号_sprintf

    LNK2001:无法解析外部符号_sprintfLNK2001:无法解析外部符号_sprintf与LNK1104:无法打开文件“kernel32.lib”_臻訾胃的博客-CSDN博客从网上下载一个VS的demo,编译之后老是报LNK2001:无法解析外部符号_sprintf的错误,找了好久,发现在项目属性->链接器->输入->附加目录依赖项添加legacy_stdio_definitions.lib即可解决问题。但不知道legacy_stdio_definitions.lib这玩意儿干啥的,有兴趣的自己百度吧..

    2022年6月28日
    56
  • Oracle latch闩原理示意图

    Oracle latch闩原理示意图

    2021年8月16日
    82
  • B样条曲线的一些基本性质[通俗易懂]

    B样条曲线的一些基本性质[通俗易懂]1.B样条曲线的节点(knotpoint)指的是将区间划分为一段一段的分段点。节点向量(knotvector)则是由多个节点组成的向量。2.B样条曲线的次数(degree)也就是基函数的次数,而阶数(oder)则是次数加1。3.若B样条曲线由n+1个控制点(从P0到Pn),有m+1个节点(从u0到um),阶数为k+1(次数为k),则必须满足m=n+k+1。4.B样条曲线的每个控制点对应一个基函数,所有控制点与对应的基函数的乘积求和可得到B样条曲线的函数表达式。5.B样条曲线具有局部支撑性。第i+

    2022年6月18日
    77
  • 珠三角制造业降本太难?企业内部AI智能体能节省多少人力?

    珠三角制造业降本太难?企业内部AI智能体能节省多少人力?

    2026年3月19日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号