Wednesday 16 November 2016

Nagios Installations and configurations

Nagios Installations and configurations

What is Nagios :

Nagios is known as Nagios Core and it's a open source computer software application that monitor systems, network and infrastructure. It's also have alerting system for servers, switch, applications and services.

Server Monitoring :

Nagios is the one of the best monitoring software for servers. It made easy to monitor with flexibility of both agent-based and agent-less monitoring. It has over 5000 different kind of addons available to monitor servers.

Network Monitoring :

Nagios monitors the network for the problems caused by overloaded data links or network connections, same as switches, routers and more. It's easy to monitor availability up-time and response time of every node on the network.

Application Monitoring :

Implementing effective application monitoring with nagios allows our organization to quickly detect applications, services, and process problems. It alert when app got problems to the user that control nagios. 

Installation :

Before installation we need to have root access for that server will run Nagios ideally. 

Installation of Nagios 4 :

Step 1 

Install dependencies of below mentioned

yum install gcc glibc glibc-common gd gd-devel make net-snmp open-ssl xineted unzip -y

Step 2

Create nagios user and group for running Nagios.

useradd nagios

groupadd nagcmd

usermod -a -G nagcmd nagios

Step 3

Download the Ngaios stable release and place it where required that. I always use /opt dir. 

We can download nagios core and other open source in followed in here.

goto /opt

cd /opt

curl -L -o https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz

step 4

Extract the package in same location

tar -xvzf nagios-4.1.1.tar.gz

change the name as nagios-4.1.1 to nagios

mv nagios-4.1.1 nagios

Step 5

now let install 

cd nagios

./configure --with-command-group=nagcmd

after that

make all

now we need to install init script with following commands

make install
make install-commandmode
make install-init
make install-config
make install-webconf

We also need the apache to access our nagios so we need to add the apache user to nagcmd group.

usermod -G nagcmd apache

now Nagios installed. We need to install plugins for the nagios.

Installation of Nagios Plugin :

Step 1

got /opt directory.

cd /opt

curl -L -o http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

Step 2

Extract it on same location.

tar -xvzf nagios-plugins-2.1.1.tar.gz

cd nagios-plugin-2.1.1

Step 3

Configuring nagios plugin with following command

./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --with-openssl

Now compile the nagios plugin with following command

make

now install with following command

make install

now nagios plugin is completed

Installation of NRPE :

We can find the latest NRPE file following link in here.

Step 1

Download the NRPE and extract them.

cd /opt

curl -L -o http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

tar -xvzf nrpe-2.15.tar.gz

Step 2

Move to the directory and configure nrpe with following command

./configure --enable-command-args --with-nagios-user=nagios --with-nagios-group=nagios --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu

now we ready to install the NRP and init script with following command

make all
make install
make install-xinetd
make install-daemon-config

Step 3

Now open the startup xinetd script in your favorite editor

vi /etc/xinetd.d/nrpe

modify the only from line by adding your private IP address.

only_from = 127.0.0.1 192.168.0.0

save and exit.

Now the Nagios server will be communicate with NRPE.

Now restart the xinetd service to start the NRPE service.

Service xinetd restart.

Step 4

Configure the new command to our nagios configuration. For this we need to add some lines in commands.cfg file. Followed

vi /usr/local/nagios/etc/objects/commands.cfg

in that add the details below to the end of the file

define command{
          command_name check_nrpe
          command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

save & exit

This will allow us to use the check_nrpe command in nagios service definitions.

Configuration of Nagios :

Now we are going to make some changes in nagios default configuration.

open the nagios.cfg file and remove the # symbol from below mentioned line

vi /usr/local/nagios/etc/nagios.cfg

find the line of cfg_dir=/usr/local/nagios/etc/servers

#cfg_dir=/usr/local/nagios/etc/server

remove

cfg_dir=/usr/local/nagios/etc/server

save & exit

now create the directory that will store the nagios configuration file that each you monitor.

mkdir /usr/local/nagios/etc/servers

Configuration of Notification :

In this we can add our mail id for the alert notifications. All you need to configure the details in contacts.cfg

vi /usr/local/nagios/etc/objects/contacts.cfg

In that find the email directive and replace your mail id. 

email            yourmailid       ;<<***** CHANGE THIS TO YOUR EMAIL ADDRESS *****

save & exit

configurations of Apache :

Her you can set the password for nagiosadmin web user admin password. For this we use htpasswd in apache.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:

Re-type password: 

Adding password for nagiosadmin

if you don't want to use admin username as nagiosadmin the you have to edit /usr/local/nagios/etc/cgi.cfg file and change the name as you wished.

Now restart the nagios and httpd service 

service nagios restart
service httpd restart

make sure you enable the nagios on startup

chkconfig nagios on

Configurations of Restricted Access by IP :

If you want to access the nagios web interface only by your system then you have to edit the nagios apache configuration file.

vi /etc/httpd/conf.d/nagios.conf

and find the two line that mentioned below and add # in-front of it.

Order allow,deny
Allow from all

then remove the # from below mentioned lines and add your ip in Allow from line.

# Order deny,allow
# Deny from all
# Allow from 127.0.0.1 <- you can add your ip here 

As these line appear multiple the you have do the same in other.

save & exit

now restart nagios and httpd

service nagios restart
service httpd restart

now we have completed the configuration now open the nagios in web browser.

http://nagios_server_ip/nagios

it will ask username password



After that the page will appear like below image



That's all for nagios installation. Next I will come up with NRPE client configuration and adding host in nagios.

No comments:

Post a Comment

Permanent hostname setup for RHEL7

Step 1 Set the host name on NMTUI tool like following nmtui set host name   then save and exit Step 2 add the following l...