Current time: 11-25-2024, 05:17 AM Hello There, Guest! (LoginRegister)


Post Reply 
[How-to] Configure MONIT to monitorize your server
Author Message
GaRCieLD Offline
Junior Member
*

Posts: 15
Joined: Jun 2007
Reputation: 0
Post: #1
Toungue [How-to] Configure MONIT to monitorize your server
MONITORING YOUR SERVER WITH MONIT

We are going to install MONIT to be able to monitorize our server, and be able to restart the processes that crashes or bypass permited memory or CPU.

This code are optimized for Debian Etch 4.0.

1. Installation

Code:
apt-get install monit

2. Configure MONIT, making a backup of the default config (you can look inside for other options)

Code:
cp /etc/monit/monitrc /etc/monit/monitrc_default
vi /etc/monit/monitrc

I put the config to monitorize: PROFTPD, SSHD, DNS SERVER (bind), MYSQLD, APACHE and POSTFIX.

You have to change the mail-format and put your domain instead of hosting.example.com.

Code:
set daemon  60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: monit@hosting.example.com }
set alert root@localhost
set httpd port 2812 and
     SSL ENABLE
     PEMFILE  /etc/monit/monit.pem
     allow admin:ispcp

# PROFTPD
check process proftpd with pidfile /var/run/proftpd.pid
   group services
   start program = "/etc/init.d/proftpd start"
   stop program  = "/etc/init.d/proftpd stop"
   if failed port 21 protocol ftp then restart
   if 5 restarts within 5 cycles then timeout

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

# DNS SERVER
check process named with pidfile /var/run/bind/run/named.pid
   group services
   start program  "/etc/init.d/bind9 start"
   stop program  "/etc/init.d/bind9 stop"
   if failed host 127.0.0.1 port 53 type tcp protocol dns then alert
   if failed host 127.0.0.1 port 53 type udp protocol dns then alert
   if 5 restarts within 5 cycles then timeout

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

# APACHE
check process apache with pidfile /var/run/apache2.pid
   group services
   start program = "/etc/init.d/apache2 start"
   stop program  = "/etc/init.d/apache2 stop"
   if failed host admin.hosting.example.com port 80 protocol http
      and request "/tools/monin_test_file" then restart
   if cpu is greater than 60% for 2 cycles then alert
   if cpu > 90% for 5 cycles then restart
   if totalmem > 500 MB for 5 cycles then restart
   if children > 250 then restart
   if loadavg(5min) greater than 10 for 8 cycles then stop
   if 3 restarts within 5 cycles then timeout

# POSTFIX
check process postfix with pidfile /var/spool/postfix/pid/master.pid
   group services
   start program = "/etc/init.d/postfix start"
   stop  program = "/etc/init.d/postfix stop"
   if failed port 25 protocol smtp then restart
   if 5 restarts within 5 cycles then timeout

# ISPCP_DAEMON
check process ispcp_daemon with pidfile /var/run/ispcp-daemon.pid
   group services
   start program = "/etc/init.d/ispcp_daemon start"
   stop  program = "/etc/init.d/ispcp_daemon stop"
# If you active this, your /var/log/daemon will grow every minute,
# so it's not recomended unless you don't want to trust only in .pid
#   if failed port 9876 then restart
   if 5 restarts within 5 cycles then timeout

3. Configure MONIN to start

First we make the "test file" to test if apache is running (see the moninrc config file to personalize for you). You can put anywhere this file, but then change moninrc.

Code:
echo "OK" > /var/www/ispcp/gui/tools/monin_test_file

and then we can edit /etc/default/monit to enable the monit daemon, and change startup to "1", and if you want change also the CHECK_INTERVALS to the seconds that you want (normaly 60, default 180)
Code:
vi /etc/default/monit

----- BEGIN:/etc/default/monit -----
# Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Fredrik Steen <stone@debian.org>

# You must set this variable to for monit to start
startup=1

# To change the intervals which monit should run uncomment
# and change this variable.
CHECK_INTERVALS=60
----- END:/etc/default/monit -----

4. Configure SSL with MONIN

When you generates the certificate, you can change this values, so you can put this example file without changes.

Code:
vi /etc/monit/monit.cnf

----- BEGIN:monit.cnf -----
# create RSA certs - Server

RANDFILE = ./openssl.rnd

[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type

[ req_dn ]
countryName = Country Name (2 letter code)
countryName_default = MO

stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default     = Monitoria

localityName                    = Locality Name (eg, city)
localityName_default            = Monittown

organizationName                = Organization Name (eg, company)
organizationName_default        = Monit Inc.

organizationalUnitName          = Organizational Unit Name (eg, section)
organizationalUnitName_default  = Dept. of Monitoring Technologies

commonName                      = Common Name (FQDN of your server)
commonName_default              = server.monit.mo

emailAddress                    = Email Address
emailAddress_default            = root@monit.mo

[ cert_type ]
nsCertType = server
----- END:monit.cnf -----

and then generate the certificate

Code:
openssl req -new -x509 -days 365 -nodes -config ./monit.cnf -out /etc/monit/monit.pem -keyout /etc/monit/monit.pem

openssl gendh 512 >> /etc/monit/monit.pem

openssl x509 -subject -dates -fingerprint -noout -in /etc/monit/monit.pem

chmod 700 /etc/monit/monit.pem

You also can configure a client certificate to bypass the login/pwd (http://www.tildeslash.com/monit/doc/ssl.php)

6. Start MONIT

Finally start monit:
Code:
/etc/init.d/monit start

and watch /var/log/syslog for errors in monit configuration, and try to stop proftpd or other service to see if it works correctly.

then point your browser to https://www.example.com:2812/ to see the web interface

Hope this helps to increase your uptime Smile

Albert
(This post was last modified: 06-21-2007 08:51 PM by GaRCieLD.)
06-19-2007 09:10 AM
Find all posts by this user Quote this message in a reply
Illidan Offline
Junior Member
*

Posts: 93
Joined: May 2007
Reputation: 2
Post: #2
RE: [How-to] Configure MONIT to monitorize your server
is that not the same like the server status in ispCP?

ok, sry, it have more information Big Grin

http://www.tildeslash.com/monit/doc/shoo..._httpd.gif

nice manual, i will install it at the weekend thx Big Grin
(This post was last modified: 06-19-2007 02:27 PM by Illidan.)
06-19-2007 02:25 PM
Visit this user's website Find all posts by this user Quote this message in a reply
GaRCieLD Offline
Junior Member
*

Posts: 15
Joined: Jun 2007
Reputation: 0
Post: #3
RE: [How-to] Configure MONIT to monitorize your server
Illidan Wrote:is that not the same like the server status in ispCP?

ok, sry, it have more information Big Grin

http://www.tildeslash.com/monit/doc/shoo..._httpd.gif

nice manual, i will install it at the weekend thx Big Grin

not only more information (cpu for process, memory for each process, ...), also a daemon to restart your process if it crashes, and if can't restart it send you and email...and all very configurable... Smile

Maybe serverstatus can have the same info in 1.1 Tongue

When I can install maia & amavis &... I will update the config file with this info.

thanks,
Albert
06-19-2007 05:19 PM
Find all posts by this user Quote this message in a reply
xister Offline
Member
*
Beta Team

Posts: 405
Joined: Oct 2006
Reputation: 6
Post: #4
RE: [How-to] Configure MONIT to monitorize your server
whats with the ispcp deamon? Tongue
06-19-2007 05:34 PM
Find all posts by this user Quote this message in a reply
GaRCieLD Offline
Junior Member
*

Posts: 15
Joined: Jun 2007
Reputation: 0
Post: #5
RE: [How-to] Configure MONIT to monitorize your server
xister Wrote:whats with the ispcp deamon? Tongue

Smile good point. I've just edited the original post to include it. Thanks!
06-19-2007 07:57 PM
Find all posts by this user Quote this message in a reply
tioan Offline
Junior Member
*

Posts: 22
Joined: Dec 2006
Reputation: 0
Post: #6
RE: [How-to] Configure MONIT to monitorize your server
GaRCieLD Wrote:
Illidan Wrote:is that not the same like the server status in ispCP?

ok, sry, it have more information Big Grin

http://www.tildeslash.com/monit/doc/shoo..._httpd.gif

nice manual, i will install it at the weekend thx Big Grin

not only more information (cpu for process, memory for each process, ...), also a daemon to restart your process if it crashes, and if can't restart it send you and email...and all very configurable... Smile

Maybe serverstatus can have the same info in 1.1 Tongue

When I can install maia & amavis &... I will update the config file with this info.

thanks,
Albert

monit also provide this info from shell with monit status, so it is maby a good idee to use monit als backend for the ispcp server stats so isoco can show the infos from monit status on an own ispcp page.
06-19-2007 10:04 PM
Visit this user's website Find all posts by this user Quote this message in a reply
BioALIEN Offline
Public Relations Officer
*****
Dev Team

Posts: 620
Joined: Feb 2007
Reputation: 5
Post: #7
RE: [How-to] Configure MONIT to monitorize your server
Nice guide, I'll be sure to try this out once I am confident enough to use ispCP on a production server.
06-21-2007 03:54 AM
Find all posts by this user Quote this message in a reply
Miguel Offline
Junior Member
*

Posts: 11
Joined: Apr 2007
Reputation: 0
Post: #8
RE: [How-to] Configure MONIT to monitorize your server
Thanks for the howto! it works great for me!
I needed to do alittle modification when it says in the /etc/monit/monitrc file at the apache section:

Code:
and request "/monin_test_file" then restart

it should say

Code:
and request "/tools/monin_test_file" then restart

or where ever you want but it has to be the same place where you put

Code:
echo "OK" > /var/www/ispcp/gui/tools/monin_test_file
06-21-2007 11:00 AM
Find all posts by this user Quote this message in a reply
GaRCieLD Offline
Junior Member
*

Posts: 15
Joined: Jun 2007
Reputation: 0
Post: #9
RE: [How-to] Configure MONIT to monitorize your server
Thanks Miguel, I've just edited the post to correct this.
(This post was last modified: 06-21-2007 06:21 PM by GaRCieLD.)
06-21-2007 06:20 PM
Find all posts by this user Quote this message in a reply
GaRCieLD Offline
Junior Member
*

Posts: 15
Joined: Jun 2007
Reputation: 0
Post: #10
RE: [How-to] Configure MONIT to monitorize your server
another change...

In monitrc, if you leave this line,

# ISPCP_DAEMON
check process ispcp_daemon with pidfile /var/run/ispcp-daemon.pid
group services
start program = "/etc/init.d/ispcp_daemon start"
stop program = "/etc/init.d/ispcp_daemon stop"
if failed port 9876 then restart
if 5 restarts within 5 cycles then timeout

in /var/log/daemon you will receive every minute something like this, so I've commented it in the first post.

Code:
Jun 21 12:43:12 test_ispcp ispcp_daemon[23642]: child 23642 started !
Jun 21 12:43:12 test_ispcp ispcp_daemon[23642]: Aeee! SIG_PIPE was received ! Will we survive ?
Jun 21 12:43:12 test_ispcp ispcp_daemon[23642]: send_line(): socket write error: Broken pipe
Jun 21 12:43:12 test_ispcp ispcp_daemon[23642]: read_line(): socket EOF ! other end closed the connection !

Jun 21 12:44:14 test_ispcp ispcp_daemon[23733]: child 23733 started !
Jun 21 12:44:14 test_ispcp ispcp_daemon[23733]: Aeee! SIG_PIPE was received ! Will we survive ?
Jun 21 12:44:14 test_ispcp ispcp_daemon[23733]: send_line(): socket write error: Broken pipe
Jun 21 12:44:14 test_ispcp ispcp_daemon[23733]: read_line(): socket EOF ! other end closed the connection !

Jun 21 12:45:16 test_ispcp ispcp_daemon[24168]: child 24168 started !
Jun 21 12:45:16 test_ispcp ispcp_daemon[24168]: Aeee! SIG_PIPE was received ! Will we survive ?
Jun 21 12:45:16 test_ispcp ispcp_daemon[24168]: send_line(): socket write error: Broken pipe
Jun 21 12:45:16 test_ispcp ispcp_daemon[24168]: read_line(): socket EOF ! other end closed the connection !
06-21-2007 08:58 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)