Difference between revisions of "Monit"

From Bashlinux
Jump to: navigation, search
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
= M/Monit =
+
=== How to install M/Monit from sources ===
 
* Download Monit tar file from tildeslash
 
== How to install M/Monit from sources ==
 
# Download Monit tar file from tildeslash
 
 
<pre><nowiki>
 
 
wget http://www.tildeslash.com/monit/dist/monit-4.10.1.tar.gz
 
wget http://www.tildeslash.com/monit/dist/monit-4.10.1.tar.gz
 
* Unpack and install
</nowiki></pre>
 
 
# Unpack and install
 
 
<pre><nowiki>
 
 
tar zxvf monit-4.10.1.tar.gz
 
tar zxvf monit-4.10.1.tar.gz
 
cd monit-4.10.1
 
cd monit-4.10.1
Line 17: Line 9:
 
make
 
make
 
make install
 
make install
</nowiki></pre>
 
   
 
=== How to setup M/Monit ===
 
 
* Open <tt>/etc/monit.conf</tt> and set/uncomment this values:
== How to setup M/Monit ==
 
 
** Run Monit as daemon
# Open `/etc/monit.conf` and set/uncomment this values:
 
 
<pre><nowiki>
 
# Run Monit as daemon
 
 
set daemon 120
 
set daemon 120
 
** Send logs to /var/log/messages
 
# Send logs to /var/log/messages
 
 
set logfile syslog facility log_daemon
 
set logfile syslog facility log_daemon
 
** Setup Monit Web Service with authentication from anywhere
 
# Setup Monit Web Service with authentication from anywhere
 
 
set httpd port 2812 and
 
set httpd port 2812 and
 
allow user:password
 
allow user:password
 
** Read configuration files for each service
 
# Read configuration files for each service
 
 
include /etc/monit.d/*
 
include /etc/monit.d/*
 
* Open <tt>/etc/httpd/conf/httpd.conf</tt> and add the following lines:
</nowiki></pre>
 
 
 
# Open `/etc/httpd/conf/httpd.conf` and add the following lines:
 
 
<pre><nowiki>
 
 
# Avoid Monit activity to be logged on Apache log
 
# Avoid Monit activity to be logged on Apache log
 
SetEnvIf Request_URI "^/monit/token$" dontlog
 
SetEnvIf Request_URI "^/monit/token$" dontlog
 
CustomLog logs/access_log common env=!dontlog
 
CustomLog logs/access_log common env=!dontlog
 
* Open port on iptables to watch monit on TCP port 2812
</nowiki></pre>
 
 
# Open port on iptables to watch monit on TCP port 2812
 
{{
 
 
iptables -A INPUT -p tcp --dport 2812 -j ACCEPT
 
iptables -A INPUT -p tcp --dport 2812 -j ACCEPT
</nowiki></pre>
 
   
   
== How to configure M/Monit services ==
+
=== How to configure M/Monit services ===
=== Apache ===
+
==== Apache ====
'''File:''' `/etc/monit.d/httpd.conf`
+
'''File:''' <tt>/etc/monit.d/httpd.conf</tt>
 
<pre><nowiki>
 
 
check process httpd with pidfile /var/run/httpd.pid
 
check process httpd with pidfile /var/run/httpd.pid
 
group apache
 
group apache
Line 66: Line 40:
 
then restart
 
then restart
 
if 5 restarts within 5 cycles then timeout
 
if 5 restarts within 5 cycles then timeout
</nowiki></pre>
 
   
 
==== MySQL ====
 
 
'''File:''' <tt>/etc/monit.d/mysqld.conf</tt>
=== MySQL ===
 
'''File:''' `/etc/monit.d/mysqld.conf`
 
 
<pre><nowiki>
 
 
check process mysql with pidfile /var/run/mysqld/mysqld.pid
 
check process mysql with pidfile /var/run/mysqld/mysqld.pid
 
group mysql
 
group mysql
Line 80: Line 50:
 
then restart
 
then restart
 
if 5 restarts within 5 cycles then timeout
 
if 5 restarts within 5 cycles then timeout
</nowiki></pre>
 
   
 
==== Actionqueue ====
 
 
'''File:''' <tt>/etc/monit.d/actionqueue.conf</tt>
=== xmlBlaster ===
 
'''File:''' `/etc/monit.d/xmlblaster.conf`
 
 
<pre><nowiki>
 
check process xmlblaster with pidfile /var/run/xmlblaster.pid
 
group root
 
start program = "/sbin/service xmlblaster start"
 
stop program = "/sbin/service xmlblaster stop"
 
if failed host iron.bashlinux.com port 3412 protocol http
 
and request "/status.html" then restart
 
if 5 restarts within 5 cycles then timeout
 
</nowiki></pre>
 
 
 
=== Actionqueue ===
 
'''File:''' `/etc/monit.d/actionqueue.conf`
 
 
<pre><nowiki>
 
 
check process actionqueue with pidfile /var/run/actionqueue.pid
 
check process actionqueue with pidfile /var/run/actionqueue.pid
 
group root
 
group root
Line 108: Line 60:
 
then restart
 
then restart
 
if 5 restarts within 5 cycles then timeout
 
if 5 restarts within 5 cycles then timeout
</nowiki></pre>
 
   
 
=== How to setup and start M/Monit service ===
 
 
==== Boot init from init.d ====
== How to setup and start M/Monit service ==
 
=== Boot init from SYSV init.d ===
 
 
# Register the service to start on boot
 
# Register the service to start on boot
 
<pre><nowiki>
 
 
chkconfig monit on
 
chkconfig monit on
</nowiki></pre>
 
   
 
# Start service
 
# Start service
 
<pre><nowiki>
 
 
service monit start
 
service monit start
</nowiki></pre>
 
 
   
=== Respawnning with inittab ===
+
==== Respawnning with inittab ====
# Append {{/etc/inittab}} to add:
+
* Append <tt>/etc/inittab</tt> to add:
 
<pre><nowiki>
 
 
mo:2345:respawn:/usr/bin/monit -Ic /etc/monit.conf
 
mo:2345:respawn:/usr/bin/monit -Ic /etc/monit.conf
</nowiki></pre>
 
   
 
# Start monit
 
# Start monit
 
<pre><nowiki>
 
 
init q
 
init q
</nowiki></pre>
 

Revision as of 02:22, 10 June 2015

How to install M/Monit from sources

  • Download Monit tar file from tildeslash
wget http://www.tildeslash.com/monit/dist/monit-4.10.1.tar.gz
  • Unpack and install
tar zxvf monit-4.10.1.tar.gz
cd monit-4.10.1
./configure
make
make install

How to setup M/Monit

  • Open /etc/monit.conf and set/uncomment this values:
    • Run Monit as daemon
set daemon 120
    • Send logs to /var/log/messages
set logfile syslog facility log_daemon
    • Setup Monit Web Service with authentication from anywhere
set httpd port 2812 and
allow user:password
    • Read configuration files for each service
include /etc/monit.d/*
  • Open /etc/httpd/conf/httpd.conf and add the following lines:
# Avoid Monit activity to be logged on Apache log
SetEnvIf Request_URI "^/monit/token$" dontlog
CustomLog logs/access_log common env=!dontlog
  • Open port on iptables to watch monit on TCP port 2812
iptables -A INPUT -p tcp --dport 2812 -j ACCEPT


How to configure M/Monit services

Apache

File: /etc/monit.d/httpd.conf

check process httpd with pidfile /var/run/httpd.pid
  group apache
  start program = "/sbin/service httpd start"
  stop program = "/sbin/service httpd stop"
  if failed port host 127.0.0.1 port 80 protocol http
    and request "/api/restaurant/id"
  then restart
  if 5 restarts within 5 cycles then timeout

MySQL

File: /etc/monit.d/mysqld.conf

check process mysql with pidfile /var/run/mysqld/mysqld.pid
  group mysql
  start program = "/sbin/service mysqld start"
  stop program = "/sbin/service mysqld stop"
  if failed host 127.0.0.1 port 3306 protocol mysql
    then restart
  if 5 restarts within 5 cycles then timeout

Actionqueue

File: /etc/monit.d/actionqueue.conf

check process actionqueue with pidfile /var/run/actionqueue.pid
  group root
  start program = "/sbin/service actionqueue start"
  stop program = "/sbin/service actionqueue stop"
  if failed host 127.0.0.1 port 8443
    then restart
  if 5 restarts within 5 cycles then timeout

How to setup and start M/Monit service

Boot init from init.d

  1. Register the service to start on boot
chkconfig monit on
  1. Start service
service monit start

Respawnning with inittab

  • Append /etc/inittab to add:
mo:2345:respawn:/usr/bin/monit -Ic /etc/monit.conf
  1. Start monit
init q