5 minute guide to setup process monitoring with MONIT on Linux

If you find this free website useful – why don’t you support this with a donation? It is easy…. read more ….

If you are running a VPS, for a production server, it is very useful to have a process that monitors, and restarts if failed, and notifies you of key processes, like apache, mysql, postfix & ssh.

Monit is a free open source tool that does the job.

Took me a little while to get my head around the setup, but it is actually very simple, one you know, and can be done in 5 minutes.

 

These are the step I take on Debian (should be the same for Ubuntu)

sudo apt-get install monit

You don’t need to start anything or add it to any startup files, it does that automatically

There are a few settings needed to allow notification, and email address, an email server and a httpd server so you can monitor. These are in /etc/monit/monitrc

sudo vim /etc/monit/monitrc

Find the comment line with the word mail server.  My mail-server is on MailGun and my server is on Google Cloud  Compute so uses port 2525.  (obviously change the myuser / mypasswd / mydomain )

set mailserver smtp.mailgun.org port 2525 
    username "myuser@mydomain.com" 
    password "mypasswd"

Find the comment line # set alert sysadm@foo.bar  and add the line

set alert myuser@mydomain.com

Find the comment # set httpd port 2812 and uncomment (remove the #) the first 3 lines so you get

set httpd port 2812 
   and use address localhost # only accept connection from localhost 
   allow localhost # allow localhost to connect to the server and

Save the file & then do a quick configuration test

sudo monit -t

if OK reload monit

sudo /etc/init.d/monit reload

and check the log (as any issues with mail server will show now )

sudo tail -f /var/log/monit.log

ctril-c to stop following the log

check the status, the following command should show just one ‘System’

sudo monit status

Now we add the services we want to monitor, for me that is apache, mysql, ssh and postfix  and these are all redefined in /etc/monit/monitrc.d  so we just need to copy the definitions into /etc/monit/conf.d   like so

cd /etc/monit/monitrc.d
sudo cp apache2 openssh-server mysql postfix ../conf.d

restart monit

sudo /etc/init.d/monit reload

check the status , the following should give you all the info

sudo monit status |more

And that is it, now if say mysql dies, it will be restarted and you will get an email

 

 

 

 


Posted

in

, , , ,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *