Friday 20 January 2012

how to Install and configure Munin on linux server

The Installation and configuration are listed below
...................................................

Server Monitoring With munin

Munin produces nifty little graphics about nearly every aspect of the server (load average, memory usage, CPU usage, MySQL throughput, eth0 traffic, etc.) without much configuration, whereas monit checks the availability of services like Apache, MySQL, Postfix, Postgresql and takes the appropriate action such as a restart if it finds a service is not behaving as expected. The combination of the two gives you full monitoring: graphics that lets you recognize current or upcoming problems (like "We need a bigger server soon, our load average is increasing rapidly."), and a watchdog that ensures the availability of the monitored services.

Although munin lets you monitor more than one server, we will only discuss the monitoring of the system where it is installed here.

This tutorial is written for RHEL-4, but the configuration should apply to other distributions with little changes as well.

1:Enable The RPMforge Repository

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

2:Install And Configure munin

To install munin on RHEL-4, we do this:

yum install munin munin-node

3:Then we create the system startup links for munin and start it:
chkconfig --levels 235 munin-node on
/etc/init.d/munin-node start

Note:if chkconfig is not working from your login then do the following
yourlogin# su -
enter the root password:XXXXXXX
and again apply the chkconfig command you will have that.

4:we must edit the munin configuration file /etc/munin/munin.conf. We want munin to put its output into the directory /var/www/html/domaindirectory(serverweb)/munin, therefore we change the value of htmldir, and we want it to use the name serverweb instead of localhost.localdomain in the HTML output, therefore we replace localhost.localdomain with server1web. Without the comments,

vim /etc/munin/munin.conf

[...]
dbdir /var/lib/munin
htmldir /var/www/html/serverweb/munin
logdir /var/log/munin
rundir /var/run/munin

Where to look for the HTML templates
tmpldir /etc/munin/templates
[...]
a simple host tree
[server1.domain.com] #you domain name
address 127.0.0.1
use_node_name yes
[...]
5:Next we create the directory /var/www/html/serverweb/munin and change its ownership to the user and group munin, otherwise munin cannot place its output in that directory. Then we restart munin:

mkdir -p /var/www/html/serverweb/munin
chown munin:munin /var/www/html/serverweb/munin
/etc/init.d/munin-node restart

6: after a few minuts open your browser and access the link your.domain.com/munin

7: Password-Protect The munin Output Directory (Optional)
Now it is a good idea to password-protect the directory /var/www/html/serverweb/munin unless you want everybody to be able to see every little statistic about your server.

To do this, we create an .htaccess file in /var/www/html/serverweb/munin:

vim /var/www/html/serverweb/munin/.htaccess

AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/html/serverweb/.htpasswd

require valid-user


8:Then we must create the password file /var/www/html/serverweb/.htpasswd. We want to log in with the username admin, so we do this:
htpasswd -c /var/www/html/serverweb/.htpasswd admin

9:open browser and type http://www.serverweb.com/munin
user name: admin
password: admin

10: Thats all about for x86_64 RHEL-4 server.

Regards & Thanks
Imran Ullah

how to Install and configure Monit on Linux server RHEL

The Installation and configuration details are listed below.
............................................................

Install and Configure Monit on Linux Server for Process Monitoring
Monit is a open source utility for managing and monitoring, processes, files, directories and devices on a Unix system. Monit can perform automatic maintenance and repair and can execute useful actions in error situations.

E.g.
monit can start a process if it does not run,
monit can restart a process if it does not respond,
monit can stop a process if it uses to much resources.

You may use monit to monitor files, directories and devices for changes, such as timestamp changes, checksum changes or size changes.

1. Download the latest monit from rpmforge repository.
For (x86-bit) systems

wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/monit-5.2.5-1.el5.rf.x86_64.rpm
rpm -Uvh moit-5.2.5-1.el5.rf.x86_64.rpm

2. Install the monit rpm
rpm -Uvh monit-5.2.5-1.el5.rf.i386.rpm

yum install monit

chkconfig --levels 235 monit on
if chkconfig is unreconizable and installed then enter the command on you terminal and check again it will work.
su - presss enter
chkconfig --levels 235 monit on

3. Configure monit
vi /etc/monit.conf

set daemon 120 # check services at 2-minute intervals
set logfile /var/log/monit/access.log
set mailserver mail.server.local, # primary mailserver
set alert admin@server.local
set httpd port 2812 and
allow localhost # allow localhost to connect to the server and
allow IP.x.x.x # allow client ip address to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
4. Create /var/monit directory to place id and state
mkdir /var/monit

5. Configure service to be monitor

vim /etc/monit.d/monitrc

check process proftpd with pidfile /var/run/proftpd.pid
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

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

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

check process apache with pidfile /var/run/httpd.pid
group www
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host www.serverweb.com port 80 protocol http
and request "/monit/token" then restart
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% 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

check process postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
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

check process postgresql with pidfile /opt/postgres/data/postmaster.pid
group database
start program = "/etc/init.d/postgresql start"
stop program = "/etc/init.d/postgresql stop"
if failed unixsocket /tmp/.s.PGSQL.5432 protocol pgsql then restart
if failed unixsocket /tmp/.s.PGSQL.5432 protocol pgsql then alert
if failed host localhost port 5432 protocol pgsql then restart
if failed host localhost port 5432 protocol pgsql then alert
if 5 restarts within 5 cycles then timeout

:wq!

6: mkdir /var/www/serverweb/monit
echo "hello" > /var/www/serverweb/monit/token

7:mkdir /var/log/monit

8:Finally, we can start monit:
/etc/init.d/monit start

9: access the web interface www.serverweb.com:2812
username: admin
password: monit

10: you can add the application data to monitor to /etc/monit.d/monitrc
as i have did it in my server.

11: Create a possward for the user to login through web interface root# htpasswd -c /etc/monitpasswd admin

IMPORTANT NOTE
(To configure postgresql server and services you have to follow the steps below).

postgresql support:

Step # 1: Becoming a superuser

You need to login as database super user under postgresql server. Again the simplest way to connect as the postgres user is to change to the postgres unix user on the database server using su command as follows:
su - postgres
Step #3: Now connect to database server

Type the following command
$ psql template1
OR
$ psql -d template1 -U postgres
Output:

Welcome to psql 7.4.16, the PostgreSQL interactive terminal.
Type: \\copyright for distribution terms
\\h for help with SQL commands
\\? for help on internal slash commands
\\g or terminate with semicolon to execute query
\\q to quit
template1=#

Step #4: Add a user called monit

Type the following command to create a user called monit with a password called myPassword

template1=# CREATE USER monit WITH PASSWORD 'myPassword';

Step #5: Add a database called monit

Type the following command

template1=# CREATE DATABASE monit;

Now grant all privileges on database

template1=# GRANT ALL PRIVILEGES ON DATABASE monit to monit;
Type \q to quit:

template1=# \q

Step #6: Test tom user login

In order to login as monit you need to type following commands. Login as monit or use su command:
$ su - monit
$ psql -d monit -U monit

12: 1. Create DB user `root'.
2. Create a database 'root' owned by root. It doesn't need to contain any data.
3. Add these descriptions to pg_hba.conf;

host root root 127.0.0.1/32 trust <= for test via TCP port
local root root ident sameuser <= for test via UNIX socket
now the monit can restart the postgresql if there is any exception occurs in postgresql responding.

13: /etc/ini.d/monit restart

14:open your browser and access the link http://www.severweb.com:2812

That's all about monit installation and configuration

Regards & Thanks
Imran Ullah

How to Install and Configure M/Monit on RHEL X86_64 step by setp

nstallation and configuration procedure are listed below:
..........................................................

M/Monit expand upon Monit's capabilities to provide monitoring and management of all Monit enabled hosts from one easy to use web-interface.
This M/Monit release require Monit 5.2 or later as an agent. Monit can be downloaded from http://mmonit.com/download. See Supported Platforms for the exact OS versions supported by the binaries.

To install M/Monit:

1. First, check that M/Monit is supported on your OS platform

2. Get the latest release from http://mmonit.com/download/

3. Download and unpack the tar.gz file in a directory, any directory will do,
but unpacking in /opt or /usr/local are good choices.

4. Go to the unpacked mmonit- directory

5. Run M/Monit using: ./bin/mmonit

6. Point your Browser to the host where monit is installed (or "localhost"
if running on the same machine), for example: http://localhost:8080/
and login as user "admin" with password "swordfish".

You can run mmonit as any user, including root. It is not necessary to create a standalone account to run mmonit.

7:now do some changes on monit configuration files to connect both the servers.

vim /etc/monit.d/monitrc

add the following entries at the top of every files you want to monitor

set eventqueue basedir /var/monit/ slots 1000
set mmonit http://monit:monit@192.168.1.10:8080/collector
set httpd port 2812 and use address 192.168.1.101
allow localhost
allow 192.168.1.10
allow admin:secret

Assume we have the machines above where M/Monit runs on 192.168.1.10 and listen on port 8080. And Monit runs on 192.168.1.101
and listen on port 2812.

if both are running on the same server then both all the three IP's will be same are you can you can use 127.0.0.1

Note:ISSUE
if you are working on cloud servers they are using private IP addresses, by attempting your server primary live IP you would never going to successfully connect both the servers.

For that you have to ask your service porvider if you don't know your server secondry IP address which is the Private IP. and Put the Private IP Address in line number 2 of the above 6 steps.

In Line 3 put the name of your server serverweb in place of IP address.

Then allow your live IP address to connect through.

8: if you have a firewall then you also have to permit access for port 80 and port 2812 by creating policy, otherwise you will be unable to access your application

9: if you have more than 20 hosts to monitor through M/Monit then you have to change the default sqlite database to Postgresql or Mysql.

setps are listed here but i am using sqlite because i am monitoring not that much hosts.
Setting up M/Monit to use either MySQL or PostgreSQL is a simple two step process:

step-1:Create the M/Monit database. The database schemas can be found in mmonit/db/ Use one of the following recipes:

MySQL:
1) Create the mmonit database: mysqladmin create mmonit -u root -p
2) Create the mmonit user and grant access to the mmonit database:
GRANT ALL ON mmonit.* to mmonit@localhost identified by ''
3) Create the schema: mysql -u mmonit mmonit -p < mmonit-schema.mysql PostgreSQL: 1) Create a mmonit postgres user: createuser -U postgres -P mmonit 2) Create the mmonit database: createdb -U postgres -E utf8 -O mmonit mmonit 3) Create the schema: psql -U mmonit mmonit < mmonit-schema.postgresql step-2:Configure M/Monit; edit the M/Monit configuration file mmonit/conf/server.xml and replace the SQLite element with either.

This one for MySQL:


Or this one for PostgreSQL:


That is it. When you start M/Monit it connects to the configured database system.

10: After Completing this Exercise restart you monit server

/etc/init.d/monit restart

11: Check from log the successful connectivity with MMonit server.

12: open your browser and access the link http://www.serverweb.com:8080

username:admin
password: as listed in M/Monit installation

you will see the dashboard with your host server statistics.

That's all about the M/Monit.

Regards & Thanks
Imran Ullah