Monitoring native services with monit

[Installation]
yum install monit

[Configuration alarm]
Modify /etc/monit.conf
set daemon 60

set httpd port 1966
#Set the account password that allows access to the service
allow monitor:kaka2123
#Addresses to allow access, the following are all addresses
allow 0.0.0.0/0.0.0.0

#Set the server used by the alarm mail, the following is the QQ mailbox, and the ssl connection is used
set mailserver smtp.exmail.qq.com port 465 USERNAME "[email protected]"  PASSWORD "123456" using sslv3

#Mail format, if $Host is not set, the default is localhost
set mail-format {
  from: [email protected]
  Subject: monit alert -- $Host $EVENT $SERVICE
  message: $EVENT Service $SERVICE
          Date: $DATE
          Action:      $ACTION
          Host:        $HOST
          Description: $DESCRIPTION
  Your faithful employee,
  monit
}

#The recipient of the alert email
set alert [email protected]
set alert [email protected]

set eventqueue
basedir /var/monit

#By default, all monitoring service configuration files under /etc/monit.d will be read
# Include all files from /etc/monit.d/


[Configure the server]
Add the following files in the /etc/monit.d directory:
1. mysql.conf
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
  if failed port 3306 then alert
  ##The following statement will try to restart the service when there is a problem, if it is still not after restarting 5 times, it will alarm
  #start program = "/etc/init.d/mysqld start" with timeout 10 seconds
  #stop program  = "/etc/init.d/mysqld stop"
  #if failed port 3306 protocol mysql then alert
  #  with timeout 10 seconds
  #  then restart
  #if 3 restarts within 5 cycles then alert


2、nginx.conf
check process nginx with pidfile /var/run/nginx.pid
  start program = "/etc/init.d/nginx start" with timeout 10 seconds
  stop program  = "/etc/init.d/nginx stop"
  if failed host heylinux.com port 80 protocol http
    with timeout 10 seconds
    then restart
  if 3 restarts within 5 cycles then timeout


3、php.conf
check process php-fpm with pidfile /opt/php/var/run/php-fpm.pid
  start program = "/etc/init.d/php56.fpm start" with timeout 10 seconds
  stop program  = "/etc/init.d/php56.fpm stop"
  if cpu > 60% for 5 cycles then restart
  if loadavg(5min) greater than 4 for 5 cycles then restart
  if 3 restarts within 5 cycles then timeout


4、redis.conf
check process redis with pidfile /var/run/redis/redis.pid
  if failed port 6379 then alert


5、ssh.conf
start program "/etc/init.d/sshd start"
stop program "/etc/init.d/sshd stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout


6、oss.conf
if loadavg (1min) > 10 then alert
if loadavg (5min) > 6 then alert
if memory usage > 50% for 5 cycles then alert
if cpu usage (user) > 50% then alert
if cpu usage (system) > 50% then alert
if cpu usage (wait) > 75% then alert

##The following is the monitoring disk usage, which needs to be modified according to the actual path
check device home with path /dev/mapper/vg_9quidc-lv_home
    if space usage > 70% for 1 times within 1 cycles then alert
check device root with path /dev/mapper/vg_9quidc-lv_root
    if space usage > 70% for 1 times within 1 cycles then alert
check device sda1 with path /dev/sda1
    if space usage > 70% for 1 times within 1 cycles then alert


[Restart and view services]
> service monit restart
> monit status

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326642666&siteId=291194637