коментариев
Поделиться статьей:

Инструкция по установке и настройке monit на Centos 7

Аникей Александров 01.02.2016 8313 на прочтение 5 минут

Раз Вы тут, значит, наверное, знаете, что такое monit и для чего он нужен. Если вкратце, то это сервис для наблюдения за системными процессами (Monit - мониторилка подойдет как при аренде ВПС так и физического сервера).

В данной статье я постараюсь помочь Вам с инструкцией, как этот самый Monit поставить на сервер с ОС Centos7:

1. Сначала установим репозиторий epel на сервер (используем консольный менеджер RPM-пакетов YUM):

yum insall epel-release

2. Устанавливаем monit на сервер (используем консольный менеджер RPM-пакетов YUM)

yum -y install monit

3. Добавляем monit в автозагрузку

systemctl enable monit

4. Редактируем конфигурационный файл monit (используем редактор vim)

vim /etc/monitrc

Приступаем к редактированию параметров, которые нуждаются в изменении:

set daemon 60 # время выставляется в секундах, а параметр отвечает за интервал с которым monit будет проверять службы на сервере
set mailserver localhost # основной почтовый сервер
set alert #  тут укажите почтовый ящик, на который будут отправляться уведомления от monit
set httpd port 2812 and # порт, по которому будет открываться вебморда (веб-интерфейс) monit
allow 0.0.0.0/0.0.0.0 # разрешаем доступ к вебморде monit
allow admin:monit # логин и пароль для доступа к веб-интерфейсу monit

5. Создаем файл с настройками для проверки и перезапуска служб

vim /etc/monit.d/service

Вставляем строки, что ниже в наш файл /etc/monit.d/service

ВАЖНО! Проверяем, какие службы у Вас на сервере, и по необходимости редактируем, добавляем или удаляем нужные блоки!

###########################################################

check process httpd with pidfile "/var/run/httpd/httpd.pid"
start program = "/usr/bin/systemctl start httpd.service"
stop program = "/usr/bin/systemctl stop httpd.service"
if failed host 127.0.0.1 port 8080 protocol http then restart
if 5 restarts within 5 cycles then timeout

###########################################################

check process sshd with pidfile "/var/run/sshd.pid"
start program "/usr/bin/systemctl start sshd.service"
stop program "/usr/bin/systemctl stop sshd.service"
if failed host 127.0.0.1 port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

###########################################################

# блок ниже предназначен для работы с сервером баз данных MariaDB

###########################################################

check process mysqld with pidfile /var/run/mariadb/mariadb.pid
start program = "/usr/bin/systemctl start mariadb.service"
stop program = "/usr/bin/systemctl stop mariadb.service"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

###########################################################

check process exim with pidfile "/var/run/exim.pid"
start program = "/usr/bin/systemctl start exim.service"
stop program = "/usr/bin/systemctl start exim.service"
if failed host 127.0.0.1 port 25 then restart
if 5 restarts within 5 cycles then timeout

###########################################################

check process crond with pidfile "/var/run/crond.pid"
start program = "/usr/bin/systemctl start crond.service" #with timeout 60 seconds
stop program = "/usr/bin/systemctl stop crond.service"

###########################################################

check process proftpd with pidfile "/var/run/proftpd/proftpd.pid"
start program = "/usr/bin/systemctl start proftpd.service"
stop program = "/usr/bin/systemctl stop proftpd.service"
if failed host 127.0.0.1 port 21 then restart
if 5 restarts within 5 cycles then timeout

###########################################################

check process named with pidfile "/var/run/named/named.pid"
start program = "/usr/bin/systemctl start named.service"
stop program = "/usr/bin/systemctl stop named.service"
if failed host 127.0.0.1 port 53 then restart
if 5 restarts within 5 cycles then timeout

##########################################################

check process php-fpm with pidfile "/var/run/php-fpm/php-fpm.pid"
start program = "/usr/bin/systemctl start php-fpm.service"
stop program = "/usr/bin/systemctl stop php-fpm.service"
if failed host 127.0.0.1 port 9000 then restart
if 5 restarts within 5 cycles then timeout

###########################################################

check process nginx with pidfile "/var/run/nginx.pid"
start program = "/usr/bin/systemctl start nginx.service"
stop program = "/usr/bin/systemctl stop nginx.service"
if failed host 127.0.0.1 port 80 then restart
if 5 restarts within 5 cycles then timeout

###########################################################

check process dovecot with pidfile "/var/run/dovecot/master.pid"
start program = "/usr/bin/systemctl start dovecot.service"
stop program = "/usr/bin/systemctl stop dovecot.service"
if failed host 127.0.0.1 port 993 then restart
if 5 restarts within 5 cycles then timeout

##########################################################

6. Запускаем monit

systemctl start monit

В браузере monit доступен по адресу
http://127.127.127.127:2812/

127.127.127.127 - IP-адрес сервера, на котором Вы произвели установку monit (обязательно меняем на свой )

Cистемы мониторинга сервера Linux более подробно тут.

Надеемся, что у Вас все получится и желаем успехов в работе!


Close Screen
Аникей Александров
Статей: 41
Оцените статью:


Спасибо за отзыв
Рейтинг: 4 из 5 Голосов: 2