1. 安装Monit监控
配置 EPEL 存储库以下载最新的 Monit 包。
# sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
使用以下命令安装 Monit:
# yum -y install monit
使用以下命令在系统引导时启动并启用 Monit:
# systemctl enable monit # sytemctl start monit
我们可以使用以下命令检查 Monit 状态:
# monit status The Monit daemon 5.14 uptime: 8m System '192.168.1.200' status Resource limit matched monitoring status Monitored load average [0.01] [0.07] [0.05] cpu 0.0%us 0.0%sy 0.0%wa memory usage 127.5 MB [16.8%] swap usage 0 B [0.0%] data collected Sun, 09 Jan 2015 14:24:09
Monit 是 Linux 操作系统的开源监控工具,可监控:
监控服务器程序以确保它们保持在线。
监控系统负载,如 CPU、内存、Swap...
监控磁盘、分区或者文件大小、校验和或者权限更改
监控硬件运行状况(硬盘、主板...)
...
此外,Monit 带有一个基本的 Web 界面,我们可以通过该界面检查系统的状态。
Monit 非常有用,因为它可以在服务失败时发送电子邮件警报,我们可以配置以尝试修复任何失败的服务。
本教程将介绍 CentOS 7/RHEL 7 上 Monit 的最基本设置和配置。
2. 配置Monit监控
默认情况下,Monit 配置为每 30 秒检查一次服务是否正在运行,在本教程中,我们将其设置为 1 分钟。
## Start Monit in the background (run as a daemon): #set daemon 60 # check services at 30 seconds intervals
要配置 Web 界面,请查找并取消注释以下行:
set httpd port 2812 use address server_ip # only accept connection from localhost allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit'
要配置 Monit 以发送警报电子邮件,请查找并取消注释行:在此示例中,我们将 Monit 配置为使用 Gmail 作为邮件服务器
## Monit by default uses the following format for alerts if the the mail-format ## statement is missing:: ## --8<- set mail-format { from: from: jack@onitroad$HOST subject: monit alert -- $EVENT $SERVICE message: $EVENT Service $SERVICE Date: $DATE Action: $ACTION Host: $HOST Description: $DESCRIPTION Your faithful employee, Monit } #using TLSV1 with timeout 30 seconds set mailserver smtp.gmail.com port 587 username "jack@onitroad" password "Your_Password" using TLSV1 with timeout 30 seconds # the person who will receive notification emails set alert jack@onitroad
完成配置后,使用以下命令测试 monit 语法;
# monit -t Control file syntax OK
要使更改生效,执行以下命令以重新加载 monit 守护程序:
# monit reload
要访问 Monit Web 界面,请打开浏览器,转到服务器的 ip http://ip.address:2812 并输入我们之前配置的凭据。
日期:2020-06-02 22:18:19 来源:oir作者:oir