CONTENTS
Lastmodified 2024-01-22 (月) 08:21:12
【参考URL】http://freebsd.fkimura.com/monit-a0.html
Monitとは、プロセスを監視して、例えばApacheのプロセス監視をして、何らかの原因で落ちたら自動的(60秒後)に起動して登録メールアドレスへ報告するというもの。
設定や監視プロセスの状態はGUIで確認できる。
https://FQDN:portNo ← portNoは
設定ファイル:/usr/local/etc/monitrc で設定したもの。デフォルトは、2812
https://piano2nd.smb.net:2812/
999 8:42 locate monit 1000 8:55 portinstall sysutils/monit 1001 8:58 cp /usr/local/etc/monitrc.sample /usr/local/etc/monitrc monit_enable="YES" to rc.conf file 1003 9:06 /usr/local/etc/rc.d/monit start 1006 9:37 top 1007 9:39 /usr/local/etc/rc.d/monit restart 1012 9:55 /usr/local/etc/rc.d/monit restart 1014 10:11 apachectl -v
ssl化:letsencryptで取得した.pem を chmod 600 として利用した。
############################################################################### ## Monit control file ############################################################################### set daemon 30 # check services at 30 seconds intervals set logfile syslog set mailserver localhost # primary mailserver set alert root@smb.net # receive all alerts set httpd port 2812 and SSL ENABLE PEMFILE /usr/local/etc/letsencrypt/live/piano2nd.smb.net/cert.pem #use address localhost # only accept connection from localhost allow localhost allow 192.168.1.139 allow 219.117.246.193/27 allow 210.255.122.209/28 # allow localhost to connect to the server and #allow admin:monit # require user 'admin' with password 'monit' allow foo:hogehoge ############################################################################### ## Services ############################################################################### ### Apache ### check process apache with pidfile /var/run/httpd.pid start program = "/usr/local/etc/rc.d/apache24 start" with timeout 60 seconds stop program = "/usr/local/etc/rc.d/apache24 stop" ### amavisd ### check process amavisd with pidfile /var/amavis/amavisd.pid start program = "/usr/local/etc/rc.d/amavisd start" with timeout 60 seconds stop program = "/usr/local/etc/rc.d/amavisd stop" ### clamav ### check process clamav-clamd with pidfile /var/run/clamav/clamd.pid start program = "/usr/local/etc/rc.d/clamav-clamd start" with timeout 60 seconds stop program = "/usr/local/etc/rc.d/clamav-clamd stop" ### freshclam ### check process clamav-freshclam with pidfile /var/run/clamav/freshclam.pid start program = "/usr/local/etc/rc.d/clamav-freshclam start" with timeout 60 seconds stop program = "/usr/local/etc/rc.d/clamav-freshclam stop" ### munin ### check process munin with pidfile /var/run/munin/munin-node.pid start program = "/usr/local/etc/rc.d/munin-node start" with timeout 60 seconds stop program = "/usr/local/etc/rc.d/munin-node stop" ### named bind ### check process bind with pidfile /var/run/named/pid start program = "/usr/local/etc/rc.d/named start" with timeout 60 seconds stop program = "/usr/local/etc/rc.d/named stop" # /usr/local/etc/rc.d/monit restart
サーバを再起動した際、monitの起動が、監視プロセスよりも早いと、monitがプロセスを起動するため、アラートメールが発生し、システムがプロセスを起動させようとするとエラーがでるなど、なにかと五月蝿いので、monit は、なるべく起動シークエンスの後の方で、ってのがヨサゲです。
ということで、
/usr/local/etc/rc.d/monit の # REQUIRE: NETWORKING SERVERS 行に postfix apache24 cron を追加。
#!/bin/sh # # $FreeBSD: head/sysutils/monit/files/monit.in 340872 2014-01-24 00:14:07Z mat $ # # PROVIDE: monit # REQUIRE: NETWORKING SERVERS postfix apache24 cron # BEFORE: DAEMON # KEYWORD: shutdown
console log
Jun 5 04:17:59 sun1 kernel: Jun 5 04:17:59 sun1 monit[461]: Cannot translate 'sun1.smb.net' to IP address -- Name does not resolve Jun 5 04:17:59 sun1 kernel: Jun 5 04:17:59 sun1 monit[461]: 'httpd' failed protocol test [HTTP] at [sun1.smb.net]:80/nextcloud [TCP/IP] -- Cannot resolve [sun1.smb.net]:80
Total access 5244:本日 2:昨日 0