monitでApache2, MySQLを監視
サーバの監視が必要になって某先輩にmonitが良いと勧められ使ってみることにした。
参考にしたサイトはこちら > Linux: Monit導入 | Bamboo lath 日々の記録
Vagrant でローカルに CentOS 6.3 を起動して、上記サイトのように設定した。
Vagrant についてはまた今度まとめたいなー
Apache2 の方は問題無く監視できているっぽいがMySQLの方がうまく行かない。
監視のメールもこんなのが来る。
title: monit alert -- Connection failed mysql body: Connection failed Service mysql Date: Tue, 16 Apr 2013 12:11:24 +0000 Action: restart Host: localhost.localdomain Description: 'mysql' failed protocol test [MYSQL] at INET[localhost:3306] via TCP
title: monit alert -- Timeout mysql body: Timeout Service mysql Date: Tue, 16 Apr 2013 12:13:27 +0000 Action: unmonitor Host: localhost.localdomain Description: 'mysql' service timed out and will not be checked anymore
ググってたどり着いた > Re: [monit] MySQL: connection failed
/etc/monit.d/mysqld を編集する
check process mysql with pidfile /var/run/mysqld/mysqld.pid start program = "/etc/init.d/mysqld start" stop program = "/etc/init.d/mysqld stop" if failed unixsocket /var/lib/mysql/mysql.sock then restart if 5 restarts within 5 cycles then timeout
monitを再起動して、mysqlを停止して試してみる
$ sudo service monit restart Shutting down monit: [ OK ] Starting monit: [ OK ] $ ps aux | grep mysqld # mysqld が起動してるのを確認 $ sudo service mysqld stop Stopping mysqld: [ OK ] $ ps aux | grep mysqld # mysqld がいないことを確認 # monit の監視間隔分待ってみる $ ps aux | grep mysqld # →mysqld がいる!
monit と少し仲良くなれた気がした。