Monit — мониторинг Linux сервера. Установка и настройка под CentOS
Для чего нужен Monit? Monit — самостоятельный демон, работающий от пользователя root. Он мониторит различные выбранные вами ресурсы и если что-то пошло не так, выполнить некоторые действия. Упрощенно говоря, если какой то ресурс «упал» (Апач, ФТП или Мускуль), то Монит перезапустит его.
Расскажу, как установить и приведу пример конфига.
Установка, запуск и прочее
- yum install monit
- chkconfig monit on
- service monit start
- //так же доступны команды остановки и перезапуска
- service monit stop
- service monit restart
А вот конфиг, отслеживает свободное место, работу FTP, SSH, MySQL, Apache и Nginx
- set daemon 60
- set logfile /var/log/monit.log
- set logfile syslog facility log_daemon
- set mailserver localhost
- set alert ваш@email
- set httpd port 10001 and
- allow имя:пароль
- check filesystem hdd with path /
- if space usage > 70% then alert
- if inode usage > 80% then alert
- check system $HOST
- if loadavg (1min) > 7 then alert
- if loadavg (5min) > 5 then alert
- if memory usage > 85% then alert
- if cpu usage (user) > 90% then alert
- if cpu usage (system) > 90% then alert
- if cpu usage (wait) > 80% then alert
- check process vsftpd
- matching vsftpd
- start program = "/etc/init.d/vsftpd start"
- stop program = "/etc/init.d/vsftpd stop"
- if failed port 21 protocol ftp for 32 cycles then alert
- #check process proftpd with pidfile /var/run/proftpd.pid
- #start program = "/etc/init.d/proftpd start"
- #stop program = "/etc/init.d/proftpd stop"
- #if failed port 21 protocol ftp for 32 cycles then alert
- #if 15 restarts within 15 cycles then timeout
- 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 for 7 cycles then alert
- if failed port 22 protocol ssh for 15 cycles then restart
- if 15 restarts within 15 cycles then timeout
- check process mysql with pidfile /var/run/mysqld/mysqld.pid
- start program = "/etc/init.d/mysqld start"
- stop program = "/etc/init.d/mysqld stop"
- if failed host 127.0.0.1 port 3306 for 5 cycles then alert
- if cpu usage > 30% for 10 cycles then alert
- if cpu usage > 50% for 10 cycles then alert
- if 15 restarts within 15 cycles then timeout
- check process httpd with pidfile /var/run/httpd/httpd.pid
- start program = "/etc/init.d/httpd start"
- stop program = "/etc/init.d/httpd stop"
- if failed host 192.168.0.1 port 80 for 5 cycles then alert
- if 15 restarts within 15 cycles then timeout
- check process nginx with pidfile /var/run/nginx.pid
- start program = "/etc/init.d/nginx start"
- stop program = "/etc/init.d/nginx stop"
Вместо 192.168.0.1 впишите свой ip или имя домена. В оригинальном конфиге настроек должно быть еще больше, читайте описание :-)
Вот так выглядит web интерфейс, не забудьте добавить порт 10001 в список разрешенных, если у вас стоит Фаервол
