Install Nagios 4.4.3 on centos 7
Nagios is one of the most popular open source monitoring systems. Nagios keeps an inventory of your entire IT infrastructure and ensures your networks, servers, applications, services, and processes are up and running.
Prerequisites:
Make sure you are logged in with root user or any user with sudo privileges.
Update your centos system and install Apache,php and all the packages necessary to download and compile the Nagios application and plugins.
For this LAMP stack required. Follow this article if you want to install it on your server.
After installing like Apache,php packages install below dependencies
[root@lampblogs ~]# yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd unzip gettext autoconf net-snmp-utils epel-release perl-Net-SNMP postfix php httpd wget
Create a nagios user and nagcmd group for allowing the external commands to be executed through the web interface, add the nagios and apache user to be a part of the nagcmd group.
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
Install Nagios
Download latest version of nagios core
[root@lampblogs ~]# mkdir nagios
[root@lampblogs ~]# cd nagios
[root@lampblogs nagios]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.3.tar.gz
[root@lampblogs nagios]# tar -xvzf nagios-4.4.3.tar.gz
[root@lampblogs nagios]# cd nagios-4.4.3/
you can compile and install nagios
[root@lampblogs nagios-4.4.3]# ./configure --with-command-group=nagcmd
[root@lampblogs nagios-4.4.3]# make all
[root@lampblogs nagios-4.4.3]# make install
[root@lampblogs nagios-4.4.3]# make install-init
[root@lampblogs nagios-4.4.3]# make install-config
[root@lampblogs nagios-4.4.3]# make install-commandmode
Install the Nagios web configuration and exfoliation theme using the following commands.
[root@lampblogs nagios-4.4.3]# make install-webconf
[root@lampblogs nagios-4.4.3]# make install-exfoliation
create user account for password for webinterface.
[root@lampblogs ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
These login details will be used to access the Nagios web interface.
Now restart Apache service to effect changes.
[root@lampblogs ~]# systemctl restart httpd
[root@lampblogs ~]# systemctl enable httpd
Now sample configuration files are installed at /usr/local/nagios/etc.
Edit /usr/local/nagios/etc/objects/contacts.cfg config file and change email address field to receive notification.
[root@lampblogs ~]# vi /usr/local/nagios/etc/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 admin@lampblogs.com ; *** CHANGE TO YOUR EMAIL ADDRESS ***
}
Install Nagios Plugins
[root@lampblogs ~]# cd nagios
[root@lampblogs nagios]# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
[root@lampblogs nagios]# tar -zxvf nagios-plugins-2.2.1.tar.gz
[root@lampblogs nagios]# cd nagios-plugins-2.2.1/
Once the Nagios Plugins archive is extracted, run the following commands to compile and install the Nagios Plugins
[root@lampblogs nagios-plugins-2.2.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@lampblogs nagios-plugins-2.2.1]# make
[root@lampblogs nagios-plugins-2.2.1]# make install
verify Nagios
Verify the sample Nagios configuration files.
[root@lampblogs ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
sample output...
Nagios Core 4.4.3
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2019-01-15
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
After you have successfully installed Nagios Core and the Nagios Plugins your CentOS 7 system, you can use the following command to start and enable the Nagios service.
[root@lampblogs ~]# systemctl start nagios
[root@lampblogs ~]# systemctl enable nagios
[root@lampblogs ~]# systemctl enable httpd
Selinux and Firewall
If your selinux in enforcing mode you can disable it
[root@lampblogs ~]# vi /etc/sysconfig/selinux
set it as SELINUX=disabled and reboot system.
For disable tempararly run below command
[root@lampblogs ~]# setenforce 0
[root@lampblogs ~]# sestatus
Make sure to allow port 80 through firewall.
[root@lampblogs ~]# firewall-cmd --permanent --add-service=http
success
[root@lampblogs ~]# firewall-cmd --reload
success
To access Nagios Core, open your browser and navigate to http://ip_address/nagios and log in using the nagiosadmin user account which you have created in one of the previous step.
Nagios console will look like below.
Nagios After Login screen
Click on Hosts in the left pane to get a list of systems being monitored by Nagios. We have not added any host to Nagios, So it simply monitors the localhost itself.
Click on Services in the left pane to get the status of any services that are being monitored with Nagios.
Now You’ve successfully installed and configured Nagios and its Plugins.