开源监控工具monit安装部署

· Monit 简介

Monit是一个轻量级(500KB)跨平台的用来监控Unix/linux系统的开源工具。部署简单,并且不依赖任何第三方程序、插件或者库。

Monit可以监控服务器进程、文件、文件系统、网络状态(HTTP/SMTP等协议)、远程主机、服务器资源变化等等。 并且可以设定资源变化后需要做的动作,比如服务失败后自动重启,邮件告警等等。

Monit内置了WEB UI,可以一目了然地了解监控项的情况。Monit是监控本机服务的工具,M/Monit是其配套产品用以对Monit统一管理,但是M/Monit并不是开源的,需要购买。

本文我们介绍在CentOS7上部署Monit用来监控进程状态,并实现服务失败后自动重启以及邮件告警通知的功能。监控其他资源的方法在默认配置文件中都有举例这里不一一介绍。

Monit官网:https://mmonit.com/monit

Monit手册:Monit Manual

· Monit 安装

yum -y install epel-release

yum install -y monit

·Monit 常用命令

monit -t # 配置文件检测

monit # 启动monit daemon

monit -c /etc/monitrc # 启动monit daemon时指定配置文件

monit reload # 重新加载配置文件

monit status # 查看所有监控项务状态

monit status nginx # 查看nginx服务状态

monit stop all # 停止所有服务,这里需要注意的是,如果开启了自动重启功能,停止某个被监控的服务必须用monit stop xxx,若用系统命令停止服务,Monit会自动再把服务起来。

monit stop nginx # 停止nginx服务

monit start all # 启动所有服务

monit start nginx # 启动nginx服务

monit -V # 查看版本

主配置文件: /etc/monitrc

修改开放端口和地址:

配置邮箱告警和格式:如果开启了授权码password填入的就是授权码而非用户密码!

按照实际情况进行配置。

后在配置目录包含的子配置目录中添加一个监控配置:用于监控nginx

root@test monit.d\]# vim /etc/monit.d/nginx check process nginx with pidfile /run/nginx.pid start program = "/usr/bin/systemctl start nginx" stop program = "/usr/bin/systemctl stop nginx" 填写完成后重新加载配置。 \[root@test monit.d\]# monit reload Reinitializing monit daemon 访问该服务器的IP:2812端口:nginx进程已在其中。将nginx进程于系统命令关闭后会monit会重新启动该进程。并且发送告警到填写的邮件中。 ![](https://img-blog.csdnimg.cn/img_convert/6738c952c32beca7799450fb9c702e35.png) ![](https://img-blog.csdnimg.cn/img_convert/ea80afea0275b6427b2c3c75ae8a74b9.png)

相关推荐
专家大圣18 小时前
摆脱局域网!Logseq 搭配cpolar公网访问让笔记管理更自由
linux·网络·docker·内网穿透·cpolar
代码游侠18 小时前
复习——Linux 系统编程
linux·运维·c语言·学习·算法
Starry_hello world18 小时前
Linux 线程(1)
linux
longxibo19 小时前
Ubuntu datasophon1.2.1 二开之二:解决三大监控组件安装后,启动失败:报缺失common.sh
大数据·linux·运维·ubuntu
小尧嵌入式19 小时前
Linux的shell命令
linux·运维·服务器·数据库·c++·windows·算法
OnlyEasyCode19 小时前
.net程序部署Linux运行
linux·运维·服务器
裤裤兔19 小时前
linux查看内存
linux
kobe_OKOK_19 小时前
在 Ubuntu Server 24.04 (Noble)** 上安装 **SQL Server 驱动程序
linux·运维·ubuntu
haiyanglideshi19 小时前
ubuntu上使用samba访问另一台ubuntu的数据
linux·运维·ubuntu
小嘟嘟267919 小时前
虚拟机网络问题故障定位
linux·服务器·网络