背景

由于应用稳定性或者服务器资源限制等问题,应用就会出现自动挂掉的情况,此时就需要自动拉起应用。

生产环境,为了防止因为意外宕机造成服务长时间中断,一般都会设置服务进程监控拉起机制。

简介

Monit - utility for monitoring services on a Unix system

Monit 是 Unix 系统上的服务监控工具。可以用来监控和管理进程、程序、文件、目录和设备等。

优点

  • 安装配置简单,超轻量
  • 可以监控前后台进程(Supervisor 无法监控后台启动进程)
  • 除了监控进程还可以监控文件,还可以监控系统资源(CPU,内存,磁盘)使用率
  • 可以设置进程依赖,控制启动顺序

缺点

  • Monit 采用间隔轮询的方式检测,决定了它达不到 Supervisor 一样的实时感知。

安装

 1# 安装 epel 源2$ yum -y install epel-release34# 安装 monit5$ yum -y install monit67# 验证8$ monit -V9This is Monit version 5.26.0
10Built with ssl, with ipv6, with compression, with pam and with large files
11Copyright (C) 2001-2019 Tildeslash Ltd. All Rights Reserved.
12
13# 启动服务
14$ systemctl start monit
15
16# 启动 monit 守护进程
17$ monit

命令

官方手册:https://mmonit.com/monit/documentation/monit.html

命令格式: monit [options]+ [command]

1# 查看帮助信息
2$ monit -h

命令选项

常用命令

配置

yum 安装后的默认配置文件如下: 全局参数配置文件 :/etc/monitrc 服务监控配置文件目录:/etc/monit.d 日志文件:/var/log/monit.log

 1# 配置文件2$ grep -v "^#" /etc/monitrc3# 每 5 秒检查被监控服务的状态4set daemon  5              # check services at 30 seconds intervals5set log syslog67# 启用内置的 web 服务器8set httpd port 2812 and9    use address 10.0.0.2  # only accept connection from localhost (drop if you use M/Monit)
10    # 允许 localhost 连接
11    allow localhost        # allow localhost to connect to the server and
12    # 解决本地命令报错问题:Error receiving data -- Connection reset by peer
13    allow 10.0.0.2
14    # 运行外网 IP 访问
15    allow x.x.x.x
16    # web登录的用户名和密码
17    allow admin:monit      # require user 'admin' with password 'monit'
18    #with ssl {            # enable SSL/TLS and set path to server certificate
19    #    pemfile: /etc/ssl/certs/monit.pem
20    #}
21
22# 监控服务配置文件目录
23include /etc/monit.d/*

监控服务

 1# 查看 nexus 监控文件2$ cat /etc/monit.d/nexus3check process nexus4        matching "org.sonatype.nexus.karaf.NexusMain"5        start program = "/root/nexus3/nexus-3.12.1-01/bin/nexus start"6        stop program = "/root/nexus3/nexus-3.12.1-01/bin/nexus stop"7        if failed port 18081 then restart89# 查看 nexus 监控状态
10$ monit status nexus
11Monit 5.26.0 uptime: 3h 48m
12
13Process 'nexus'
14  status                       OK
15  monitoring status            Monitored
16  monitoring mode              active
17  on reboot                    start
18  pid                          15191
19  parent pid                   1
20  uid                          0
21  effective uid                0
22  gid                          0
23  uptime                       1m
24  threads                      96
25  children                     0
26  cpu                          0.2%
27  cpu total                    0.2%
28  memory                       14.3% [1.1 GB]
29  memory total                 14.3% [1.1 GB]
30  security attribute           -
31  disk read                    0 B/s [1.6 MB total]
32  disk write                   0 B/s [232.5 MB total]
33  port response time           1.756 ms to localhost:18081 type TCP/IP protocol DEFAULT
34  data collected               Wed, 13 May 2020 14:36:27
35
36# 验证 nexus 停机自动拉起
37$  kill -9 15191
38
39# 间隔时间内还未拉起
40$ monit status nexus
41Monit 5.26.0 uptime: 3h 48m
42
43Process 'nexus'
44  status                       Does not exist
45  monitoring status            Monitored
46  monitoring mode              active
47  on reboot                    start
48  data collected               Wed, 13 May 2020 14:36:42
49
50# 查看自动拉起后的 nexus 监控状态
51$ monit status nexus
52Monit 5.26.0 uptime: 3h 48m
53
54Process 'nexus'
55  status                       OK
56  monitoring status            Monitored
57  monitoring mode              active
58  on reboot                    start
59  pid                          15830
60  parent pid                   1
61  uid                          0
62  effective uid                0
63  gid                          0
64  uptime                       0m
65  threads                      52
66  children                     0
67  cpu                          64.0%
68  cpu total                    64.0%
69  memory                       4.5% [349.2 MB]
70  memory total                 4.5% [349.2 MB]
71  security attribute           -
72  disk read                    0 B/s [84 kB total]
73  disk write                   0 B/s [36.9 MB total]
74  port response time           -
75  data collected               Wed, 13 May 2020 14:36:45
76
77# 查看过程日志
78$ tailf -20 /var/log/monit.log
79......
80[CST May 13 14:35:09] error    : 'nexus' process is not running
81[CST May 13 14:35:09] info     : 'nexus' trying to restart
82[CST May 13 14:35:09] info     : 'nexus' start: '/root/nexus3/nexus-3.12.1-01/bin/nexus start'
83[CST May 13 14:35:17] info     : Reinitializing monit daemon
84[CST May 13 14:35:17] info     : Reinitializing Monit -- control file '/etc/monitrc'
85[CST May 13 14:35:17] info     : 'VM_0_2_centos' Monit reloaded
86[CST May 13 14:36:42] error    : 'nexus' process is not running
87[CST May 13 14:36:42] info     : 'nexus' trying to restart
88[CST May 13 14:36:42] info     : 'nexus' start: '/root/nexus3/nexus-3.12.1-01/bin/nexus start'
89[CST May 13 14:36:45] info     : 'nexus' process is running with pid 15830

web 控制台

web 控制台地址:http://10.0.0.2:2812/

主页面:

监控运行信息:

系统监控信息:

进程监控信息:

Linux 下 Monit 监控相关推荐

  1. linux下检测硬盘,【转载】linux下硬盘监控诊断工具SmartTools

    对于windwos下raid卡具备告警功能,当硬盘故障.raid卡告警时,可以发邮件给管理员.IBM.HP.Dell都支持.但在linux下,就没有找到相关的好工具了,今天到陈沙克的博客上到一篇关于l ...

  2. 【dubbo-2.5.x】Linux下dubbo-admin监控/管理平台部署详细教程

    前言 Dubbo-Admin是Dubbo控制台管理的工具,是Dubbo组件之一,需要Dubbo-Admin管理平台来实时对服务调用情况进行调整,比如控制分布式服务的调用权重等,通过调整调整调用权重来控 ...

  3. linux下安装监控网络流量工具Iptraf

    今天试用了下linux下的网络流量监控分析工具iptraf,按照网上的安装方法,怎么也不成功.安装参考:http://www.jcwcn.com/article-23141-1.html. 搜索&qu ...

  4. linux 下iptraf监控网卡流量

    linux 系统下 iptraf监控网卡流量,监控eth0网卡的流量如下所示: [root@web01]# iptraf -d eth0      转载于:https://blog.51cto.com ...

  5. ntop linux,Linux下开源监控软件Ntop的性能提升方案

    摘要:Ntop是一款Linux下常见的开源监控软件,它可以监测的数据包括:网络流量.使用协议.系统负载.端口情况.数据包发送时间等.正常情况下它工作的时候就像一部被动声纳,默默的接收看来自网络的各种信 ...

  6. linux下进程监控6,Linux进程监控技术—精通软件性能测试与LoadRunner最佳实战(6)...

    8.2.5  Linux操作系统进程监控技术 Linux在进程监控方面同样出色,不仅可以通过图形用户界面的管理工具,还可以用命令方式显示进程相关信息.像"Windows的任务管理器" ...

  7. linux下怎么监控网络 io swap,监控io性能,free命令,ps命令,查看网络状态,linux下抓包...

    监控io性能 [root@localhost ~]# iostat Linux 3.10.0-514.el7.x86_64 (localhost.localdomain) 2017年09月12日 _x ...

  8. Linux下自动化监控内存、存储空间!

    距离上一次更新文章已经过去一段时间了,小编在这段时间因为一些琐事,加上身体生病不能及时更新文章,今天身体逐渐恢复就急忙来更新文章,今天思梦给大家带来的就是如何自动化监控我们的服务器一些基本的配置来保证 ...

  9. linux下ganglia监控系统搭建,linux下ganglia监控系统搭建

    Ganglia监控软件主要是用来监控系统性能的软件,如:cpu .mem.硬盘利用率, I/O负载.网络流量情况等,通过曲线很容易见到每个节点的工作状态,对合理调整.分配系统资源,提高系统整体性能起到 ...

最新文章

  1. map.get(key)空指针异常_NPE空指针异常总结
  2. iptables 指定网卡_LINUX系统下的IPTABLES防火墙系统讲解(二)实战操作
  3. mysql数据库的三级模式_2016年计算机三级MySQL数据库试题
  4. mysql5.5 5.7区别_mysql 5.5 和5.7 安装的区别
  5. 怎么用javascript进行拖拽[zt]
  6. 【TDA4系列】CCS 最新版本安装与教程地址
  7. 新手学JavaScript都要学什么?
  8. cad计算机快捷键命令大全,cad快捷键命令有哪些?常用cad快捷键命令大全
  9. android如何设置透明字体颜色,Android设置字体透明度
  10. python爬虫实战---网易云音乐评论抓取
  11. 4年亏损超6亿,摩贝化学赴美上市能否输血成功?
  12. Mybatis-Plus 传入时间查询的方式
  13. 基于飞浆ERNIE3.0百亿级大模型实现中文短文本分类任务
  14. 亿级流量电商详情页系统的大型高并发与高可用缓存架构实战
  15. atlas mysql 分表,Atlas实现Mysql读写分离
  16. win7 64位下如何安装配置mysql
  17. arm wifi ap热点功能
  18. 丘成桐科学奖计算机类,丘成桐科学奖
  19. 【逐梦云服务平台研究之redis启动】
  20. 打码平台是如何运作的?再谈验证码安全

热门文章

  1. linux重要开源软件
  2. 【论文阅读】FcgFed《Feature-Contrastive Graph Federated Learning: Responsible AI in Graph Information Analy
  3. 百度富文本编辑器UEditor 图片宽度100%自适应,手机端
  4. HackBar插件绕许可
  5. 2022跨年-跨年倒计时(烟花)
  6. Android L 值不值得刷?十个问题解疑惑
  7. 中国压敏胶产业调研与投资战略报告(2022版)
  8. 数据库模式(三级模式+两级映射)
  9. 旋转矩阵中6保6_[转载]旋转矩阵中6保5公式
  10. 网络编程---Ip和端口号