Wednesday 23 January 2013

Install Monit & MMonit on RHEL/Cent OS From Source

Installation
----------------
@Prerequists@

#yum install pam-devel
#yum install openssl-devel

@Get and install Monit@
#cd /usr/local/src
#wget http://mmonit.com/monit/dist/monit-5.5.tar.gz
#tar -zxvf monit-5.5.tar.gz
#cd monit-5.5
#./configure (If this fails, fix as necessary, then re-unpack the tar and try again)
#make
#make install

@Setup monitrc@

#cp monitrc /etc/
#vim /etc/monitrc  # At the end of monitrc add or uncomment: include /etc/monit.d/*
#mkdir /etc/monit.d

Create the service files (this will repeat for every service you monitor)
vim /etc/monit.d/apache

#Now Inside the apache file:
check process httpd with pidfile /var/run/httpd/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80 protocol http
 and request "/index.html"
then restart
if 5 restarts within 5 cycles then timeout

@To see more services, chec out this http://mmonit.com/wiki/Monit/ConfigurationExamples@

@Now setup the init.d file@
#cp contrib/rc.monit /etc/init.d/monit
#chmod 755 /etc/init.d/monit

You may need to fix the line inside the above file thats pointing at /usr/bin/monit to /usr/local/bin/monit.
After this is in place you should have the service monit restart command available.

To start Monit at boot, edit vim /etc/rc.d/rc.local and add in the next line

Go ahead and run the above line in the console to see if monit works.
If so, a call to service httpd stop should cause monit to restart apache.

@Finished@
Monit should be all setup. You can check with service monit status or ps aux | grep monit.

Another cool feature of monit is the web interface. Go to http://localhost:2812/ and
enter the username and password form your monitrc file, it should look something like this, feel free to change it:

set httpd port 2812
  allow hauk:password

@Main Files@

/etc/monitrc - Monit's control file

/etc/monit.d/* - all services Monit will track

/etc/init.d/monit - service control file

/usr/local/src/monit-5.5 - source code

/usr/local/bin/monit


Edit below settings based on our requirements
----------------------------------------------------------------

vim /etc/monitrc

set alert sysop@fak3r.com (to get alert email)

Lastly I changed the email format to be a little more user friendly for support and the other users. While I’ve grown fond of the simple/to the point alert system monit has by default, it’s easy to format the message so they’re a bit more specific, and easier to categorize. In the top, global section of monitrc, we add something like:

set mail-format {
     from: monit@somebigserver.com
     subject: [ $SERVICE ] $EVENT - $DATE
     message: This is an $ACTION: $DESCRIPTION [$SERVICE], tested remotely from $HOST }

To add remote host(192.168.2.14) http service in monit
------------------------------------------------------

check host 192.168.2.14-http  with address www.mansoor.com
  if failed port 80 proto http then alert

For multiple alert
------------------
check host fak3r.com with address fak3r.com
if failed url http://fak3r.com and content == "look out honey"
timeout 30 seconds for 1 cycles then alert
alert it.support@company.com { connection, timeout }
alert debbie.developer@company.com { connection, timeout }
alert dave.developer@company.com { connection, timeout }

For Adding Process list refer the below:
------------------------------------------------------

http://mmonit.com/wiki/Monit/ConfigurationExamples

Install MMonit:
--------------------

Check out the http://mmonit.com/wiki/MMonit/Setup

No comments:

Post a Comment