编辑 monitrc, vim /etc/monitrc,取消对 include /etc/monit.d/* 的注释。
编写对 Nginx 的监控脚本
vim /etc/monit.d/nginx
1 2 3 4 5 6
## nginx check process nginx with pidfile /var/run/nginx.pid start program = "/usr/sbin/service nginx start" stop program = "/usr/sbin/service nginx stop" if failed host 127.0.0.1 port 80 type tcp then restart if 5 restarts within 5 cycles then timeout
编写对 MySQL 的监控脚本
vim /etc/monit.d/mysql
1 2 3 4 5 6
## mysql check process mysql with pidfile /var/run/mysqld/mysqld.pid start program = "/usr/sbin/service mysql start" stop program = "/usr/sbin/service mysql stop" if failed unixsocket /var/run/mysqld/mysqld.sock then restart if 5 restarts within 5 cycles then timeout
编写对 PHP-FPM 的监控脚本
vim /etc/monit.d/php-fpm
1 2 3 4 5 6
## php-fpm check process php-fpm with pidfile /var/run/php/php7.4-fpm.pid start program = "/usr/sbin/service php7.4-fpm start" stop program = "/usr/sbin/service php7.4-fpm stop" if failed unixsocket /var/run/php/zabbix.sock then restart if 5 restarts within 5 cycles then timeout
编写对 Zabbix-Server 的监控脚本
vim /etc/monit.d/zabbix-server
1 2 3 4 5 6
## zabbix_server check process zabbix_server with pidfile /var/run/zabbix/zabbix_server.pid start program = "/usr/sbin/service zabbix-server start" stop program = "/usr/sbin/service zabbix-server stop" if failed host 127.0.0.1 port 10051 type tcp then restart if 5 restarts within 5 cycles then timeout