check program list-files with path "/bin/ls -lrt /tmp/" if status != 0 then alert
# RHEL 7 rpm -ql monit ... /etc/logrotate.d/monit /etc/monit.d /etc/monit.d/logging /etc/monitrc /usr/bin/monit /usr/lib/systemd/system/monit.service /usr/share/doc/monit-5.14 /usr/share/doc/monit-5.14/COPYING /usr/share/doc/monit-5.14/README /usr/share/man/man1/monit.1.gz /var/log/monit.log
# RHEL 6 rpm -qlpi monit-5.25.1-1.el6.x86_64.rpm ... /etc/monit.conf /etc/monit.d /etc/rc.d/init.d/monit /usr/bin/monit /usr/share/doc/monit-5.25.1 /usr/share/doc/monit-5.25.1/COPYING /usr/share/doc/monit-5.25.1/README /usr/share/man/man1/monit.1.gz /var/lib/monit /var/monit # RHEL 7 rpm -qlpi monit-5.25.1-1.el7.centos.x86_64.rpm ... /etc/monit.conf /etc/monit.d /usr/bin/monit /usr/lib/systemd/system/monit.service /usr/share/doc/monit-5.25.1 /usr/share/doc/monit-5.25.1/COPYING /usr/share/doc/monit-5.25.1/README /usr/share/man/man1/monit.1.gz /var/lib/monit /var/monit
# EHEL 6 rpm -qlpi monit-5.25.1-1.el6.x86_64.rpm ... /etc/logrotate.d/monit /etc/monit.conf /etc/monit.d /etc/monit.d/logging /etc/rc.d/init.d/monit /usr/bin/monit /usr/share/doc/monit-5.25.1 /usr/share/doc/monit-5.25.1/COPYING /usr/share/doc/monit-5.25.1/README /usr/share/man/man1/monit.1.gz /var/log/monit # EHEL 7 rpm -qlpi monit-5.25.1-1.el7.x86_64.rpm ... /etc/logrotate.d/monit /etc/monit.d /etc/monit.d/logging /etc/monitrc /usr/bin/monit /usr/lib/systemd/system/monit.service /usr/share/doc/monit-5.25.1 /usr/share/doc/monit-5.25.1/COPYING /usr/share/doc/monit-5.25.1/README /usr/share/man/man1/monit.1.gz /var/log/monit.log
# 古いバージョンを待避 which monit /usr/bin/monit sudo service monit stop sudo mv /usr/bin/monit /usr/bin/monit.5.3.2 wget https://mmonit.com/monit/dist/binary/5.24.0/monit-5.24.0-linux-x64.tar.gz tar xvfz monit-5.24.0-linux-x64.tar.gz -C ./ sudo cp monit-5.24.0/bin/monit /usr/bin/ # ~/.monitrc, /etc/monitrc, /usr/local/etc/monitrc, /usr/local/etc/monitrc or at ./monitrc しか読んでくれないためsymlink sudo ln -s /etc/monit/monitrc /etc/monitrc sudo monit start sudo monit status
以下、monit 5.25.1 に更新すると解消する事を確認。
# /opt/healthcheck/httpd/check.shが失敗した時(exit status != 0)にプロセスをkillして強制起動させたい check program httpd-healthcheck with path "/opt/healthcheck/httpd/check.sh" with timeout 60 seconds if status != 0 for 3 cycles then exec "/bin/bash -c '/usr/bin/pkill -9 httpd && /bin/sleep 5 && /sbin/service httpd start'"
sudo iptables -A INPUT -p tcp -m tcp --dport 14186 -j DROP
sudo service iptables stop
sudo monit reload
This means that every "check program" will be associated with either a running process or a temporary zombie. This unwanted zombie side-effect will be removed in a later release of Monit.
# ゾンビプロセスの表示 ps aux | awk '{if($8 ~ /Z/) print}'
sudo monit summary
sudo monit status
monit -t
vim /etc/monit.conf ---- set mailserver localhost set alert manager@foo.bar not on { instance, action } ---- monit reload
sudo monit -v
#!/bin/bash { echo "-- MONIT-WRAPPER: date" date --iso-8601=seconds echo "-- MONIT-WRAPPER: env" env echo "-- MONIT-WRAPPER: $@" $@ R=$? echo "-- MONIT-WRAPPER: exit code: $R" } &> /tmp/monit.log
exec "/tmp/monit-wrapper.sh /bin/bash -c 'grep -P \'\[(warn|error)' /var/log/monit.log\'"
-- MONIT-WRAPPER: /bin/bash -c grep -P \ \[(warn|error)' /var/log/monit.log\'
# ファイルへ exec "/bin/bash -c '/path/myscript &> /tmp/myscript.out'" # syslogへ exec "/bin/bash -c '/path/myscript &> | /usr/bin/logger -i -t myscript'"
start program = "/bin/bash -c 'my shell command && my other command'"
cat /etc/monit.conf set httpd port 2812 and use address localhost # only accept connection from localhost allow localhost # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit' allow @monit # allow users of group 'monit' to connect (rw) allow @users readonly # allow users of group 'users' to connect readonly
sudo monit status
mkdir -p ~/rpm/{BUILD,SRPMS,SPECS,SOURCES,RPMS} cd rpm echo "%_topdir $HOME/rpm" > ~/.rpmmacros # 依存パッケージをインストール sudo yum install flex pam-devel -y wget https://mmonit.com/monit/dist/monit-5.14.tar.gz tar xvfz monit-5.14.tar.gz cp monit-5.14/system/packages/redhat/monit.spec SPECS/ mv monit-5.14.tar.gz SOURCES/ # ビルド rpmbuild -bb SPECS/monit.spec # インストール sudo rpm -Uvh ./RPMS/x86_64/monit-5.14-1.x86_64.rpm
rpm -ql monit /etc/init.d/monit /etc/monitrc /usr/bin/monit /usr/share/doc/monit-5.14 /usr/share/doc/monit-5.14/COPYING /usr/share/doc/monit-5.14/README /usr/share/man/man1/monit.1.gz