Monit 是一个开源的进程监控工具,可以帮助你监控和管理 Unix/Linux 系统上的进程、文件、目录和设备等。下面是关于如何修改 Monit 配置文件的详细说明。
Monit 的主配置文件通常位于以下位置之一:
- /etc/monitrc
- /etc/monit/monitrc
- /etc/monit.conf
备份原始配置文件
sudo cp /etc/monit/monitrc /etc/monit/monitrc.bak
编辑配置文件
sudo nano /etc/monit/monitrc
重新加载配置
sudo monit reload
set daemon 30 # 每30秒检查一次
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set mailserver smtp.example.com port 587
username "your-email@example.com" password "your-password"
using tlsv1
with timeout 30 seconds
set alert admin@example.com # 接收警报的邮箱
set httpd port 2812 and
use address 0.0.0.0 # 监听所有IP
allow 0.0.0.0/0 # 允许所有IP访问
allow admin:monit # 用户名和密码
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed host 127.0.0.1 port 80 protocol http then restart
if 5 restarts within 5 cycles then timeout
check filesystem rootfs with path /
if space usage > 80% then alert
if inode usage > 80% then alert
check system localhost
if loadavg (1min) > 4 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% then alert
修改配置文件后,可以使用以下命令验证配置是否正确:
sudo monit -t
如果显示"Control file syntax OK",则配置语法正确。
sudo systemctl restart monit
# 或
sudo service monit restart
sudo monit status
希望这些信息能帮助你配置Monit。根据你的具体需求,可以调整上述示例配置。