monit配置监控启动nginx php mysql redis mongodb 服务器
下面来看一个整理的monit配置监控启动nginx php mysql redis mongodb 服务器例子,我们这样监控之后可以保证服务器永不宕机,是不是非常的不错呀.
启动: monit -Ic /etc/monitrc &
crontab -e
*/600 * * * * /usr/local/bin/monit -Ic /etc/monitrc &
conf 配置:
—————nginx php mysql redis mongodb 配置 完美OK——————– # nginx check process nginx with pidfile /usr/local/nginx/logs/nginx.pid start program = [/usr/local/nginx/sbin/nginx] stop program = [/usr/bin/killall nginx] if failed host 127.0.0.1 port 80 then restart if cpu is greater than 40% for 2 cycles then alert if cpu > 60% for 5 cycles then restart if 10 restarts within 10 cycles then timeout # php5-fpm check process php-fpm with pidfile / var /run/php-fpm.pid start program = [/usr/local/php5.3/sbin/php-fpm] stop program = [/usr/bin/killall php-fpm] if failed port 9000 then restart if cpu is greater than 40% for 2 cycles then alert if cpu > 60% for 5 cycles then restart if 10 restarts within 10 cycles then timeout# php5-fpm binary. check file php5-fpm-tcp_bin with path /usr/local/php5.3/sbin/php-fpm if 10 restarts within 10 cycles then timeout if failed checksum then unmonitor if failed permission 755 then unmonitor if failed uid root then unmonitor if failed gid root then unmonitor alert root@localhost# Test the init scripts. check file php5-fpm-tcp_init with path /usr/local/php5.3/sbin/php-fpm if failed checksum then unmonitor if failed permission 755 then unmonitor if failed uid root then unmonitor if failed gid root then unmonitor alert root@localhost # mysql check process mysql with pidfile / var /lib/mysql/localhost.localdomain.pid group database start program = [/sbin/service mysql start] stop program = [/sbin/service mysql stop] if failed port 8306 then restart if 3 restarts within 10 cycles then timeout # redis check process redis with pidfile / var /run/redis.pid start program = [/usr/local/redis/redis-server /usr/local/redis/redis.conf] stop program = [/usr/bin/killall redis-server] if failed host 127.0.0.1 port 6379 then restart if cpu is greater than 40% for 2 cycles then alert if cpu > 60% for 5 cycles then restart if 10 restarts within 10 cycles then timeout # mongodb check process mongod with pidfile /usr/local/mongodb/data/mongod.lock start program = [/usr/local/mongodb/bin/mongod –dbpath=/usr/local/mongodb/data/] stop program = [/usr/bin/killall mongod] if failed port 27017 protocol http and request [/] with timeout 10 seconds then restart if 10 restarts within 10 cycles then timeout —————-end——————- /usr/local/mmonit/bin/mmonit -c /usr/local/mmonit/conf/server.xml -t /usr/local/mmonit/bin/mmonit -c /usr/local/mmonit/conf/server.xml start monit -t killall monit monit -Ic /etc/monitrc & telinit q ps aux |grep monit kill -1 1 ps aux |grep redis-server killall redis-server ll /var /run/redis.pid /usr/local/redis/redis-server /usr/local/redis/redis.conf & ps aux |grep php-fpm killall php-fpm /usr/local/php5.3/sbin/php-fpm ps aux |grep mongod killall mongod /usr/local/mongodb/bin/mongod –dbpath=/usr/local/mongodb/data/ & set mmonit http://monit:monit@142.4.48.50:8080/collector set nginx port 80 and use address 142.4.48.50 allow localhost allow 142.4.48.50