setdaemon5# 多久检测一次# with start delay 240 # 第一次检查 延迟 多久,默认启动后就检查#set log /var/log/monit.logsetlog/XXX/log/monit.log# set pidfile /var/run/monit.pid # 没太大必要setpidfile/XXX/pid/monit.pid# set idfile /var/.monit.id 设置Monit实例的id文件路径。id文件记录了Monit实例的唯一ID(标识),id在第一次Monit启动时生成并存储。默# 认情况下,文件放置在$HOME/.monit.id#set idfile /var/lib/monit/id#set idfile /monit/idsetidfile/XXX/pid/monit.idfile# set statefile /var/.monit.state #保存监视状态的Monit状态文件的位置#set statefile /var/lib/monit/statesetstatefile/XXX/pid/monit.stateseteventqueuebasedir/XXX/pid/monit.events# 设置存储事件的基本目录slots100# 可选择限制队列大小sethttpdport8022and#这里允许公网访问 不绑定ipwithssl{pemfile:/XXX/my_ssl/domain_aio.pem# 二合一证书文件selfsigned:allow#允许自签名}allow用户名:密码include/XXX/_config/monit/include/*.conf#包含文件
常用配置
几个注意点
守护进程 优先使用pid,其次再选择 matching 进程名称
启动和关闭进程优先使用/etc/init.d/
monitrc 文件 权限必须是700 include的文件权限无所谓
控制sshd
1
2
3
4
5
6
7
check process sshd with pidfile /run/sshd.pid
start program="/etc/init.d/ssh start" with timeout 120 seconds
stop program="/usr/bin/killall sshd" with timeout 120 seconds
---- 或者 mkdir -p /run/sshd 后- ---------
check process sshd with matching "/usr/sbin/sshd"if does not exist thenexec"/usr/sbin/sshd" stop program="/usr/bin/killall sshd" with timeout 120 seconds
注意 /etc/init.d/ssh stop 无法彻底关闭sshd
控制crontab
1
2
3
check process crontab with pidfile /var/run/crond.pid
start program="/etc/init.d/cron start" with timeout 120 seconds
stop program="/etc/init.d/cron stop" with timeout 120 seconds
注意crontabl是使用 /usr/sbin/cron 而不是 /usr/bin/crontab
控制ddns-go 等没有pid的
1
2
3
check process ddns-go with matching "ddns-go"if does not exist thenexec"/usr/bin/ddns-go" stop program="/usr/bin/killall ddns-go" with timeout 120 seconds
指定用户运行redis
1
2
3
4
5
check process redis6001 with pidfile /XXX/pid/redis6001.pid
start program="/bin/su - userRedis -c '/usr/bin/redis-server /XXX/_config/redis/redis6001.conf &' " with timeout 120 seconds
stop program="/bin/su - userRedis -c '/usr/bin/redis-cli -p 6001 -a 密码 -h localhost SHUTDOWN & /usr/bin/sleep 5 &&/usr/bin/kill -9 $( lsof -t -i:6001)'" with timeout 120 seconds
控制rclone挂载
1
2
3
4
5
CHECK FILESYSTEM rclone_dev_log PATH /localPath
start program="/usr/bin/rclone mount --allow-other --daemon oss-qd:xxx/ /localPath/ --config /XXX/_config/rclone.conf" with timeout 120 seconds
stop program="/usr/bin/fusermount -u /localPath " with timeout 120 seconds