Search Windows and Linux Networking

Tuesday, August 30, 2011

Step by step Nagios (Network Monitoring System ) Installation on CentOS


Step by Step Nagios Installation.

Install Mail Server

Remove sendMail

# yum remove sendmail

# yum install postfix

The configuration file is located at /etc/postfix/main.cf. Edit the file and make sure you change the following lines with your domain name.

1) What domain name to use in outbound mail
  Eg:- mydomain = example.com
     myorigin = $mydomain
2) What domains to receive mail for
  Eg:- mydestination = 
3) What clients to relay mail from
  Eg:- mynetworks = 192.168.10.0/24 , 192.168.73.0/24, 127.0.0.0/8
4) What destinations to relay mail to
  Eg:- relay_domains = $mydestination
5) What delivery method: direct or indirect
  (For direct delivery to Internet.)
  Eg:-  relayhost = 

Now edit the mail configruaration file and set parameter to send mail with our register domain name.
# vi /etc/postfix/main.cf

myhostname= zabbix.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination =
mynetworks = 192.168.19.0/24 , 192.168.73.0/24, 127.0.0.0/8
relay_domains = $mydestination
relayhost =  

# chkconfig postfix on
# /etc/init.d/postfix restart
Shutting down postfix:                                     [FAILED]
Starting postfix:                                                [  OK  ]

Test mail server by sending test mail from telnet

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 zabbix.glam.com ESMTP Postfix
helo
501 Syntax: HELO hostname
helo example.com
250 zabbix.example.com
mail from:zabbix@example.com
250 2.1.0 Ok
rcpt to:abc_username@gmail.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject: test message
this is the test mail
.
250 2.0.0 Ok: queued as F02B840410
quit
221 2.0.0 Bye
Connection closed by foreign host

Install Apache

Install Apache Server on CentOS, RedHat, Linux

# yum install httpd
# chkconfig httpd on
# service httpd start
 Starting httpd:                                            [  OK  ]

Setup new user and group for Nagios.

#groupadd -g 5000 nagios
#groupadd -g 5001 nagioscmd
#useradd -u 5000 -g nagios -G nagioscmd -d /opt/nagios nagios
#passwd nagios
Set password for nagios user

#usermod -G nagioscmd apache

Setup directory for Nagios data, configuration and binary and set required permission to directory for Nagios user.


#mkdir -p /opt/nagios /etc/nagios /var/nagios
#chown nagios.nagios /opt/nagios /etc/nagios /var/Nagios


1) Install Prerequisites

# yum install httpd gcc glibc glibc-common gd gd-devel

2) Download Compile and Install Nagios and the Plugins.
Obtaining Nagios
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz
# tar zxvf nagios-3.3.1.tar.gz
# cd nagios
# ./configure --prefix=/opt/nagios --sysconfdir=/etc/nagios --localstatedir=/var/nagios --libexecdir=/opt/nagios/plugins --with-command-group=nagioscmd

# make all

*** Support Notes *******************************************

If you have questions about configuring or running Nagios,
please make sure that you:

     - Look at the sample config files
     - Read the documentation on the Nagios Library at:
           http://library.nagios.com

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:

     - What version of Nagios you are using
     - What version of the plugins you are using
     - Relevant snippets from your config files
     - Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

       http://support.nagios.com

*************************************************************

Enjoy.

# make install
# make install-init
# make install-config
# make install-commandmode

# cd

Obtaining Nagios Plugins.

#wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
# tar zxvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --prefix=/opt/nagios --sysconfdir=/etc/nagios --localstatedir=/var/nagios --libexecdir=/opt/nagios/plugins --enable-perl-modules
# make all
# make install
# cd
# cd nagios
# make install-webconf

Note:- You have to confirm your Nagios are configure properly
# cat /etc/httpd/conf.d/nagios.conf

ScriptAlias /nagios/cgi-bin "/opt/nagios/sbin"

<Directory "/opt/nagios/sbin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /etc/nagios/htpasswd.users
   Require valid-user
</Directory>

Set Password for Authentication for Nagios

# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

configure startup run level and start nagios 

# chkconfig --add nagios
# chkconfig nagios on
# chkconfig --list nagios
nagios          0:off   1:off   2:on    3:on    4:on    5:on    6:off
# /etc/init.d/nagios start
# /etc/init.d/postfix start
# chkconfig postfix on
# chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
# /etc/init.d/httpd start
# chkconfig httpd on
# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off


You now have a fully installed Nagios setup. Congratulations!

Now open Nagios web from browser with

http://nagios_ip_address/nagios

Note:- if you are not able to access authentication window at this point problem may be firewall, or Apache configuration or permission with Nagios or Apache user. To access /opt/nagios/sbin Please check that.


Type username as nagiosadmin and password you was set for nagiosadmin web. after successfully authentication you will be see following page.


Testing Nagios by Sending First Notification.


Now you have to check if Nagios is working or not by sending notification 


to allow nagios to send notification by mail you have told nagios whom to send mail if something goes wrongs for that you have to define contact.
by default local nagios host was added in nagios so you have to define your email address in file contact.cfg
change your email address
# vi /etc/nagios/objects/contacts.cfg

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                          yourname@yourdomainname.com        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

Now restart your nagios to apply changes by command
# service nagios restart

By default ssh and http service notification are disabled so enable httpd service notification to enable all notification for host click on hosts then click on local host at right side click on enable notification for all services on this host and then commit this will enable notification for all services.

Now stop any one service httpd or sshd on nagios server. 
# service httpd stop

After few minuet your nagios will send notification mail saying that httpd service has problem on localhost.
if you got mail from nagios then your nagios is working fine. now start that service again.
# service httpd start


Nagios will send second mail saying it recover. :-)


On Next time we will see how to add host and service for monitoring from nagios windows and linux host.

1 comment:

  1. i do that but i can'treceive mail when service httpd stop or start

    ReplyDelete