Настройка описана для Ubuntu 20.04/22.04
Установка сервера описана на сайте CheckMK и в beginners guide
Как настроить агенты мониторинга описано в beginners guide - Setting up monitoring
В разделе краткие (и неполные) инструкции, самые частые команды использованные при настройке мониторинга.
Скачиваем агента мониторинга из админ.панели сервера
Загружаем .deb пакет на целевой сервер
Выполняем команду
cmk-agent-ctl register --hostname <HOST_NAME> --server <SERVER_HOST> --site <SITE_NAME> --user <USER_NAME>
HOST_NAME - имя хоста, которое указали в админ.панели checkmk
SERVER_HOST - URL или IP сервера мониторинга
SITE_NAME - имя сайта мониторинга (то которое указали при создании сервера мониторинга)
USER_NAME - логин админа в админ.панеле
cmk-update-agent register -H <HOST_NAME>
HOST_NAME - имя хоста, которое указали в админ.панели checkmk
cmk-update-agent show-config
cmk-agent-ctl status
apt install python3-pip -y && pip install docker
Централизованный сервер M/Monit платный, но агенты мониторинга monit - бесплатные. Можно пользоватся только ими, красивых графиков не будет, но базовые вещи и оповещения на email в них настроить можно
Заходим на сайт M/Monit и копируем ссылку на нужную версию (для Ubuntu это linux-arm64).
Переходим в целевой каталог на сервере.
Скачиваем на сервер мониторинга
Распаковываем архив
Переименовываем каталог
Удаляем архив
cd /usr/local/
wget https://mmonit.com/dist/mmonit-3.7.15-linux-arm64.tar.gz
tar xvzf mmonit-*.tar.gz
mv mmonit-* mmonit
rm mmonit-*.tar.gz
Создаем БД mmonit, пользователя mmonit и даем права на БД mmonit, загружаем схему БД
mysqladmin create mmonit -u root -p
mysql
CREATE USER mmonit@localhost IDENTIFIED BY '<password>';
GRANT ALL ON mmonit.* to mmonit@localhost;
FLUSH PRIVILEGES;
exit
mysql -u mmonit mmonit -p < /usr/local/mmonit/db/mmonit-schema.mysql
Заменяем SQLite <Realm> в конфигурации M/Monit conf/server.xml
Открываем conf/server.xml
nano /usr/local/mmonit/conf/server.xml
Добавляем конфигурацию БД MySQL/MariaDB
<Realm url="mysql://mmonit:mmonit@127.0.0.1:3306/mmonit"
minConnections="5"
maxConnections="30"
reapConnections="300" />
Добавляем M/Monit в сервисы
nano /etc/systemd/system/mmonit.service
Вставляем в файл
[Unit]
Description = Easy, proactive monitoring of Unix systems, network and cloud services
After = network.target
Documentation= https://mmonit.com/documentation/
[Service]
Type=simple
KillMode=process
ExecStart = /usr/local/mmonit/bin/mmonit -i
ExecStop = /usr/local/mmonit/bin/mmonit stop
PIDFile = /usr/local/mmonit/logs/mmonit.pid
Restart = on-abnormal
[Install]
WantedBy = multi-user.target
Сохраняем файл, перечитываем конфиги, включаем старт M/Monit при загрузке системы, стартуем M/Monit, проверяем статус
systemctl daemon-reload
systemctl enable mmonit
systemctl start mmonit
systemctl status mmonit
aptitude install monit
Конфиг агента - /etc/monit/monitrc
Свои конфиги лучше создавать в дериктории /etc/monit/conf.d/
Старт/стоп/статус агента мониторинга
systemctl start monit.service
systemctl stop monit.service
systemctl status monit.service
Для настройки писем с алертами от monit в конфиг агента /etc/monit/monitrc добавь строчку
set mailserver HOST port PORT username USERNAME password PASSWORD using SSL
HOST - адрес почтового сервера
PORT - порт SMTP (например 465)
USERNAME - имя для авторизации
PASSWORD - пароль (лучше указывать в ковычках, если пароль 1234, указывай "1234")
# ======================== http apache2 ==================
check process apache with pidfile /var/run/apache2/apache2.pid
start program = "/etc/init.d/apache2 start" with timeout 60 seconds
stop program = "/etc/init.d/apache2 stop"
if failed host localhost port 80 protocol http with timeout 15 seconds for 3 times within 4 cycles then restart
if 5 restarts with 5 cycles then unmonitor
# ========================= mysql =======================
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group database
group mysql
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 protocol mysql with timeout 15 seconds for 3 times within 4 cycles then alert
if failed unixsocket /var/run/mysqld/mysqld.sock protocol mysql for 3 times within 4 cycles then alert
if 5 restarts with 5 cycles then unmonitor
depend mysql_bin
depend mysql_rc
check file mysql_bin with path /usr/sbin/mysqld
group mysql
if failed checksum then unmonitor
# include /etc/monit/templates/rootbin
check file mysql_rc with path /etc/init.d/mysql
group mysql
if failed checksum then unmonitor
# include /etc/monit/templates/rootbin
# ======================== ssh ==========================
check process SSH with pidfile /var/run/sshd.pid
group system
group SSH
start program = "/etc/init.d/ssh start"
stop program = "/etc/init.d/ssh stop"
if failed host localhost port 22 with proto ssh then restart
if 5 restarts with 5 cycles then unmonitor
depend on sshd_bin
depend on sftp_bin
depend on sshd_rc
depend on sshd_rsa_key
depend on sshd_dsa_key
check file sshd_bin with path /usr/sbin/sshd
group SSH
include /etc/monit/templates/rootbin
check file sftp_bin with path /usr/lib/openssh/sftp-server
group SSH
include /etc/monit/templates/rootbin
check file sshd_rsa_key with path /etc/ssh/ssh_host_rsa_key
group SSH
include /etc/monit/templates/rootstrict
check file sshd_dsa_key with path /etc/ssh/ssh_host_dsa_key
group SSH
include /etc/monit/templates/rootstrict
check file sshd_rc with path /etc/ssh/sshd_config
group SSH
include /etc/monit/templates/rootrc
# ========================= main conf ====================
set mmonit http://user:password@domain.com:port/collector
set httpd port 2812
with SSL {
pemfile: /etc/letsencrypt/live/example.com/fullchain.pem
}
use address 157.90.158.251
allow 0.0.0.0/0.0.0.0
allow username:password
# ========================================================
# Мониторинг нашего сервера
check system example.com
group system
group server
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 80% then alert
if swap usage > 25% then alert
if cpu usage (user) > 70% for 3 times within 10 cycles then alert
if cpu usage (system) > 30% for 3 times within 10 cycles then alert
if cpu usage (wait) > 20% for 3 times within 10 cycles then alert
# Проверяем параметры корневой ФС
check device rootfs with path /
group system
group server
if failed permission 755 then alert
if space usage > 90% for 5 times within 10 cycles then alert
if space usage > 99% then stop
if inode usage > 30% for 5 times within 10 cycles then alert
if inode usage > 50% then stop
#============================================================