Posts Tagged ‘Bind) with Monit to prevent server downtimes’

Monitoring and restart server services (Apache, Mysql, Bind) with Monit to prevent server downtimes

Monday, August 9th, 2010

Monit Daemon Service Logo

If you’re a system administrator responsible for a server running a heavy loaded high traffic website equipped with Apache, MySQL, Bind, Spamassassin .. you name the service, you have probably already faced the stressful situations whenever unexpected server services crashes occur.

You should already know by experience that whenever an Apache or Database server goes down especially on a well known respected website, then you’re into real shit.

In my prefessional work experience as a system admin some time ago I found a handy small program written especially to save you the many nerves and worries, of unexpected server services failures caused by an unexpected running server software bugs.

The great program able to monitor your specified system services is called Monit

Monit is specially written with the idea in mind to track daemon, processes, files, devices and even a remote systems.

What makes monit a really superb and a desireful piece of software to install on each and every software you take care of is it’s ability to trigger certain activities whenever some critical problems with monitor system files are missing, daemons are not runnign any more, some kind of critical system overload occurs and even almost everything bad you can imagine could happen could be previously foreseen and described from the monit configuration file monitrc

For instance if your MySQL server is crashing every now and then without logging any meaningful to its log file, and yet your site users have to wait before it gets restarted by you, you can easily automate that using monit.

Monit is also built with a small daemon listening on a port that is able to show you the monitored services state, it’s also capable of sending altert emails in case if critical predefined occurances.

Monit is even able to be installed on a number of server nodes and be used directly from a common web interface and therefore a management of all server services from just one interface is possible.
This is especially handy if you’re a system administrator responsible for 10+ servers like I used to be some time ago.

Another handy example of whenever using monit would be of a immesurable extra benefit is for instance if you have a server where you have a dying SSH server every now and then on your dedicated server located some 100 000 km away.

If you have properly installed and configure monit and this kind of emergency situation occurs monit will handle the situation and restart your SSHD daemon ASAP as it realizes the sshd daemon is not properly running on your server.

In this article I’m about to explain how to install and configure monit on a Debian GNU/Linux.
The install and configure procedure should be most likely also compatible with Ubuntu and any other Debian based distribution like Sidux, on Redhat based Linuxes the steps to be followed might be a bit different but yet easily adapted from the one I explain here.

1. Install the monit deb package on your Debian serverdebian-server:~# apt-get install monit

2. Configure monit to enabled as a daemon and start up on boot

– Edit /etc/default/monit :

By default /etc/default/monit looks like so:

# Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Fredrik Steen <>

# You must set this variable to for monit to start

# To change the intervals which monit should run uncomment
# and change this variable.

Change in the above /etc/default/monit configuration:


This is necessary otherwise the monit daemon won’t start up.

3. Download my monitrc already configured to track and Restart MySQL, Apache and Bind

Apart from monitoring MySQL, Apache and Bind, with this configuration monit is configured to alert on an emailthat needs to be configured from /etc/monit/monitrc .

It also checks for free disk space availability dangerously decreasing as well as for high load avarage and critical low levels of memory usage.

You will have to modify the monitrc provided and substitute the my default domain with whatever is the name of yours.

Some other minor modifations to the conf file might be necessary so review it before proceeding with running up the monit daemon.

You can either download a working copy of monitrc or directly execute on your server:

debian-server:~# cd/etc/monit
debian-server:/etc/monit # mv monitrc monitrc.orig
debian-server:/etc/monit # wget

After a minor modifications to monitrc you should be ready to start up the monit service and it will monitor and alert whenever it matches any of the configuration prerogative.

4. Test monit configuration

To test if your prepared monitrc has a valid syntax issue:

debian-server:~# monit -t

5. Start up the monit service

debian-debian-server:~# /etc/init.d/monit start

6. Accessing Monit Web interface

Monit Web interface will run on the port number 2812.If you have any firewall preventing acccess to 2812 make sure you allow access to the port in order to be able to access it.

Now point your browser to
Log in with admin and test, and you should see the monit web interface

Having a monit on your server can assure you a better both server and services uptime as well as inform you of a possible approaching problems, the uses of monit to track and react on certain unexpected common troubles comes up to your imagination and creativity.