CentOS – Instalar Monit

Monit es un servicio que puede actuar como daemon para detectar caídas de servicios. He de decir que probé de hacerlo funcionar compilando pero las prisas me impidieron completar. Este tutorial utiliza EPEL para la instalación.

# vi /etc/yum.repos.d/epel.repo

[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
# yum clean all; yum install monit; chkconfig --levels 235 monit on
# mv /etc/monit.conf /etc/monit.conf.bak
# vi /etc/monit.conf

set daemon 60
set logfile /var/log/monit.log
set mailserver localhost
set mail-format { from: alert@domain.com
subject: $SERVICE $EVENT at $DATE
message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
}
set alert admin@domain.com
include /etc/monit.d/*

Monitorizaremos ahora apache. Cada servicio como httpd o mysql tienen particularidades en relación al PID. Hay que vigilar eso

# vi /etc/monit.d/httpd

check process httpd with pidfile /var/run/httpd/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout

MySQL

# vi /etc/monit.d/mysqld

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

MongoDB

# vi /etc/monit.d/mongod

check process mongodb
  with pidfile "/var/lib/mongodb/mongod.lock"
  start program = "/sbin/service mongod start"
  stop program = "/sbin/service mongod stop"
  if failed port 28017 protocol http
    and request "/" with timeout 10 seconds then restart
  if 5 restarts within 5 cycles then timeout

Leave a Reply

Your email address will not be published. Required fields are marked *