К уже рассмотренным системам мониторинга таких как Nagios , Zabbix , Munin добавим к рассмотрению легкую систему мониторинга Monit.
Официальный сайт Monit
Последняя версия monit доступна в репозитории DAG
Установка
# yum -y install monit
Проверяем версию
# rpm -qa | grep monit monit-5.2.3-1.el5.rf
Прописываем в автозагрузку
# chkconfig monit on
Создаем папку
# mkdir /var/monit
В конфигурационном ( /etc/monit.conf )
set idfile /var/monit/id set statefile /var/monit/state include /etc/monit.d/*
Создаем главный конфигурационный файл следующего содержания
# vi /etc/monit.d/main.conf set daemon 60 # check services at minute intervals set logfile syslog facility log_daemon set mailserver localhost set eventqueue basedir /var/monit slots 100 set alert sysadm@foo.bar # receive all alerts set alert manager@foo.bar only on { timeout } # receive just service-timeout alert check system test.bezha.od.ua if loadavg (1min) > 4 then alert if loadavg (5min) > 2 then alert if memory usage > 75% then alert if swap usage > 25% then alert if cpu usage (user) > 70% then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert
Создаем файл для мониторинга сервисов
Exim (/etc/monit.d/exim.conf)
check process exim with pidfile /var/run/exim.pid start program = "/etc/init.d/exim stop" stop program = "/etc/init.d/exim start" if cpu > 60% for 2 cycles then alert if cpu > 80% for 5 cycles then restart if totalmem > 300.0 MB for 5 cycles then restart if children > 50 then restart if failed port 25 protocol smtp then restart if 5 restarts within 5 cycles then timeout group mail
Dovecot (/etc/monit.d/dovecot.conf)
check process dovecot with pidfile /var/run/dovecot/master.pid start program = "/etc/init.d/dovecot stop" stop program = "/etc/init.d/dovecot start" if cpu > 60% for 2 cycles then alert if cpu > 80% for 5 cycles then restart if totalmem > 300.0 MB for 5 cycles then restart if children > 50 then restart if failed port 110 type TCP protocol POP then restart if 5 restarts within 5 cycles then timeout group mail
Proftpd (/etc/monit.d/proftpd.conf)
check process proftpd with pidfile /var/proftpd.pid start program = "/etc/init.d/proftpd start" stop program = "/etc/init.d/proftpd stop" if failed port 21 protocol ftp then restart if 5 restarts within 5 cycles then timeout group ftp
SSH (/etc/monit.d/ssh.conf)
check process sshd with pidfile /var/run/sshd.pid 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 group server
MySQL (/etc/monit.d/mysql.conf)
check process mysqld with pidfile /var/run/mysqld/mysqld.pid start program = "/etc/init.d/mysqld start" stop program = "/etc/init.d/mysqld stop" if failed unixsocket /var/lib/mysql/mysql.sock protocol mysql then restart if failed host localhost port 3306 protocol mysql then restart if 5 restarts within 5 cycles then timeout group database
PostgreSQL (/etc/monit.d/postgresql.conf)
check process postgres with pidfile /var/run/postmaster.5432.pid start program = "/etc/init.d/postgresql start" stop program = "/etc/init.d/postgresql stop" if failed unixsocket /tmp/.s.PGSQL.5432 protocol pgsql then restart if failed host 127.0.0.1 port 5432 protocol pgsql then restart if 5 restarts within 5 cycles then timeout group database
Apache (/etc/monit.d/apache.conf)
check process apache with pidfile /var/run/httpd.pid start program = "/etc/init.d/httpd start" stop program = "/etc/init.d/httpd stop" if cpu > 60% for 2 cycles then alert if cpu > 80% for 5 cycles then restart if totalmem > 500.0 MB for 5 cycles then restart if children > 250 then restart group www
Bind (chrooted) (/etc/monit.d/bind.conf)
check process named with pidfile /var/named/chroot/var/run/named/named.pid start program = "/etc/init.d/named start" stop program = "/etc/init.d/named stop" if failed host 127.0.0.1 port 53 type tcp protocol dns then alert if failed host 127.0.0.1 port 53 type udp protocol dns then alert if 5 restarts within 5 cycles then timeout group named
Файловые системы (/etc/monit.d/fs.conf)
check device rootfs with path / start program = "/bin/mount /" stop program = "/bin/mount -o remount,ro /" if space usage > 80% for 5 times within 15 cycles then alert if space usage > 99% then stop if inode usage > 80% then alert if inode usage > 99% then stop group server check device bootfs with path /boot start program = "/bin/mount /boot" stop program = "/bin/mount -o remount,ro /boot" if space usage > 80% for 5 times within 15 cycles then alert if space usage > 99% then stop if inode usage > 80% then alert if inode usage > 99% then stop group server
Включаем Web-интерфейс в файле /etc/monit.d/main.conf
set httpd port 10001 and use address 192.168.0.100 allow 192.168.0.1/24
Перезапускаем monit
# service monit restart
Заходим в http://192.168.0.100:10001
Если необходимо мониторить несколько серверов с одного web-интерфейса необходимо воспользоваться M/Monit
Скачиваем необходимую актуальную версию
# wget http://mmonit.com/dist/mmonit-2.3.2-linux-x86.tar.gz
Распакуем
# tar -xvf mmonit-2.3.2-linux-x86.tar.gz # cd mmonit-2.3.2
Создаем папку и переносим mmonit в нее
# mkdir /usr/local/mmonit/ # mv * /usr/local/mmonit/
Создаем базу данных MySQL
# mysql -u root -p mysql> CREATE DATABASE `mmonit`; mysql> use mmonit mysql> source /usr/local/mmonit/db/mmonit-schema.mysql mysql> quit
Создаем пользователя и даем ему права на базу данных mmonit
# mysql -u root -p mysql> GRANT ALL PRIVILEGES ON mmonit.* TO 'monit'@'localhost' IDENTIFIED BY 'password'; mysql> FLUSH PRIVILEGES; mysql> QUIT;
Редактируем конфигурационный файл M/Monit (/usr/local/mmonit/conf/server.xml)
Realm url="mysql://monit:password@localhost/mmonit" minConnections="5" maxConnections="250" reapConnections="300"
Устанавливаем загрузочный скрипт
# cp /usr/local/mmonit/doc/startup/mmonit_init /etc/init.d/mmonit # chmod 755 /etc/init.d/mmonit
Запускаем M/Monit
# /etc/init.d/mmonit start Starting mmonit: mmonit.
Заходим по http://192.168.0.100:8080 логин/пароль admin/swordfish
Связываем monit с m\monit (в конфигурационном файле /etc/monit.d/main.conf)
set mmonit http://monit:monit@192.168.0.100:8080/collector set httpd port 2812 and use address 192.168.0.100 allow localhost allow 192.168.0.100 allow admin:swordfish
Для простоты понимания схема
Hosts