Chris Brentano's Blog

0

Monit is a great little monitoring tool that I really like for it's simplicity and flexibility in monitoring local services like sshd, Apache, MySQL and others. It's quick to setup and use as well.

 

Requires gcc, flex, & bison, so if the configure script bitches about flex, yacc or not finding a C compiler, then just install those via yum/apt/etc.

 

1. Download the latest source: http://www.tildeslash.com/monit/dist/monit-4.10.1.tar.gz

 

2. Extract the archive

 

3. ./configure

 

4. make

 

5. sudo make install

 

By default it installs the binary in /usr/local/bin/monit

 

It won't run without a config file. The default location is /etc/monitrc -- here's a sample config:

 

# Monit control file

set daemon 120
set logfile syslog facility log_daemon
set mailserver mail.host.com
set alert you@host.com

set httpd port 3024 address server.host.com
allow 10.56.201.0/255.255.254.0
allow username:password

# sshd checking
check process sshd with pidfile /var/run/sshd.pid
start = "/etc/init.d/sshd start"
stop = "/etc/init.d/sshd stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

# mysqld checking
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
start = "/etc/init.d/mysqld start"
stop = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

 

So these settings do the following:

 

  • Checks sshd and mysqld every 120 seconds, and will attempt to restart them if they aren't responding

  • Logs to syslog

  • Alerts you@host.com if anything is amiss

  • Runs a httpd process on port 3024, using simple authentication (User: username, Pass: password)

  • Only allows hosts in the 10.56.201/23 network to connect (you'd change this to your network).

 

 

 

Note:

  • Make sure to change the hostname here to match the machine it's running on.

  • The http server is purely optional. It allows you to easily check on monitored services from your browser and restart them if necessary.

 

This file needs to be owned by root and chmod'ed 700 -- monit will complain if it isn't.

 

You can find more info on checking specific processes at http://www.tildeslash.com/monit/index.php -- and there's lots of stuff on teh Google.

 

In the monit-4.10.1/contrib folder is a file named rc.monit -- you can copy this to /etc/init.d and then install it as a service (on Fedora/RHEL/CentOS) with:

 


chkconfig --add monit
chkconfig --level 3 monit on
service monit start

 

Just edit the file to point to the correct monit binary (/usr/local/bin/monit), resave it as "monit", copy it to /etc/init.d, and then chown root, chmod 755.



There are no comments on this post

Click to view Chris Brentano's profile

Chris Brentano

Member since: Dec 31, 2007

I can haz open source?

View Chris Brentano's profile

Recent Comments

No recent comments.

Archives