# cd /usr/local/src
# wget https://mmonit.com/monit/dist/monit-5.26.0.tar.gz
# tar zxvf monit-5.26.0.tar.gz
2. ビルド&インストール
1234
# cd monit-5.26.0
# ./configure
# make
# make install
3. インストールの確認
1234
# monit -V
This is Monit version 5.26.0
Built with ssl, with ipv6, with compression, with pam and with large files
Copyright (C) 2001-2019 Tildeslash Ltd. All Rights Reserved.
# This file is systemd template for monit service. To# register monit with systemd, place the monit.service file# to the /lib/systemd/system/ directory and then start it# using systemctl (see bellow).## Enable monit to start on boot: # systemctl enable monit.service## Start monit immediately: # systemctl start monit.service## Stop monit:# systemctl stop monit.service## Status:# systemctl status monit.service[Unit]Description=Pro-active monitoring utility for unix systems
After=network.target
Documentation=man:monit(1) https://mmonit.com/wiki/Monit/HowTo
[Service]Type=simple
KillMode=process
ExecStart=/usr/local/bin/monit -I
ExecStop=/usr/local/bin/monit quit
ExecReload=/usr/local/bin/monit reload
Restart= on-abnormal
StandardOutput=null
[Install]WantedBy=multi-user.target
check process mysql with pidfile /var/run/mysqld/mysqld.pid
every 1 cycle
start program="/etc/rc.d/init.d/mysqld start" stop program="/etc/rc.d/init.d/mysqld stop"if failed
host localhost port 3306 protocol mysql
with timeout 15 seconds for3times within 4 cycles
then restart$if failed
unixsocket /var/run/mysqld/mysqld.sock protocol mysql
for3times within 4 cycles
then restart$if5 restarts within 5 cycles then timeout
mysqld.pid ファイルを1サイクル(今回の設定では 120秒)毎に監視し、存在しなければ MySQL サーバを再起動する。
TCP ポート 3306 への接続が4回中3回15秒のタイムアウトで失敗する場合は、 MySQL サーバを再起動する。
# monit status
Monit 5.26.0 uptime: 4m
System 'noah'
status OK
monitoring status Monitored
monitoring mode active
on reboot start
load average [0.04] [0.16] [0.34]
cpu 0.0%us 0.1%sy 1.1%wa
memory usage 1.2 GB [60.7%]
swap usage 12.8 MB [0.3%]
uptime 54m
boot time Sun, 29 Sep 2019 10:24:29
data collected Sun, 29 Sep 2019 11:19:12
monit summary だと status だけを確認できる。
アラートの設定をしていれば、アラートの状況も出力される。
11. 個別監視の停止・起動
個別に監視を停止・起動するには以下のようにする。
12
# monit stop xxxx
# monit start xxxx
12. グループ単位での監視の停止・起動
個別の設定ファイル内で group xxxx のように記述していれば、xxxx グループの単位で監視を停止・起動することができる。