How to Install and Configure Nagios on CentOS 7

Install and Configure Nagios

Nagios Core is free & open source monitoring tool or software which can monitor the resources like servers, network equipment like firewall, network switches and printers etc. Nagios core also provides alerting services, using which nagios informs administrators about issue that has occurred & then trigger alerts again when the issue has been resolved.
Nagios provides information like CPU utilization, Disk utilization, Memory utilization & also has support for a number of networking protocols like SMTPHTTPPOP3SNMPICMPFTPSSH etc. Nagios shows all the information regarding all the servers on a single screen using its web-interface.

Installing essential packages

We need to install some essential packages like apache, php & packages required for building the source packages, use below command to install these packages.

# yum install httpd php gcc glibc glibc-comman gd gd-devel make net-snmp unzip -y

Downloading and extracting the Nagios packages:

 

Next thing to do is to download & extract the nagios & its plugins files. The download links are mentioned below

# wget https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.3.2/nagios-4.3.2.tar.gz
# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

To extract the packages, run following commands.

# tar -zxvf nagios-4.3.2.tar.gz
# tar -zxpvf nagios-plugins-2.2.1.tar.gz

Create user and group for Nagios

Next step is to create a user named ‘nagios‘ & a group named ‘nagcmd‘ for running nagios,

# useradd nagios
# passwd nagios
# groupadd nagcmd

Once the user & group has been added, we will now add the user nagios & apache user to the created group i.e. nagcmd

# usermod -G nagcmd nagios
# usermod -G nagcmd apache

Installing Nagios core

We are now ready to install the nagios on our server, so go to the folder with extracted nagios core files & compile the extracted files.

# cd nagios-4.3.2
# ./configure --with-command-group=nagcmd

Next we will install the compiled nagios package by running,

# make all
# make install

After running these, we need to install init scripts, command mode (to make nagios work from CLI) & also need to install some sample Nagios files.

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

Configuring Nagios Core Web-Interface

We will now install the web interface for the nagios, as we will be using web interface for monitoring the resources of the client systems. To install web interface, run.

# make install-webconf

Web interface will be installed with a default user by the name ‘nagiosadmin‘ but there will be no default password for the user. We will create default password for user by issuing the following command,

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

Configuring email alerts

Though this is an optional step but consider doing it. By configuring an email to receive alerts on nagios, you will remain informed of all the server activities 24/7. To configure an email, open and enter an email address.

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

Next, restart  Apache server for changes to take effect.

# systemctl restart httpd

Installing the Nagios Plugins

We have now completed installation for nagios core but we need to install plugins as without them we can’t monitor the resources. So open the directory with nagios plugin files & then we will compile & install the plugins.

# cd nagios-plugins-2.2.1/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install

Installation of nagios plugins is also complete.

Verify Nagios files

Last step is now to verify Nagios configuration file against a sample configuration file.

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

This will ensure that all the settings made to nagios configuration file are correct & if there is any issue with file, it will report that as well. After making sure that config file is error less, we will restart the nagios & apache service to implement the changes.

# systemctl restart  nagios
# systemctl restart httpd

Also make sure that these services restart after a reboot,

# systemctl enable  nagios
# systemctl enable httpd

Note: In Case OS firewall in enabled on your Nagios server then allow 80 port using beneath commands

# firewall-cmd --permanent --add-port=80/tcp
# firewall-cmd --reload

Logging into Nagios Web-interface

Now to check the status of the services, login to the nagios web interface by using the ip address of the nagios server followed by /nagios

http://100.10.100.10/nagios

You will now be asked to provide the credentials, Use nagiosadmin as user name and password that we set in above steps.  Once authenticated we can access the home page of nagios server.

Related posts

Leave a Comment