How To Install Nagios 4.4.x On CentOS 7
Nagios is a free and open-source monitoring tool which helps us to monitor the services and applications. Also, we can monitor network devices such as routers and switches.
Nagios comes with the inbuilt web interface to monitor devices, but you need to rely on configuration files for adding devices to Nagios monitoring.
We will now go through the installation of Nagios on CentOS 7.
Prerequisites
Install below packages for Nagios.
yum -y install httpd php gcc glibc glibc-common wget perl gd gd-devel unzip
Create a user and group account for the Nagios installation.
useradd nagios
groupadd nagcmd
Add both nagios and apache user to nagcmd group. This allows us to execute external commands through the Nagios web interface.
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
Download Nagios
You can use below commands to download Nagios core (v4.4.3) and Nagios plugins(v2.2.1). Else, you can visit the official website to download the latest version of Nagios core and plugins.
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.3.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
Install Nagios Core
Extract the Nagios core package.
tar -zxvf /tmp/nagios-4.4.3.tar.gz
cd /tmp/nagios-4.4.3
Run the series of command to compile and install Nagios core.
./configure --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
Install Nagios Web Interface
Execute the below command in the terminal to install Nagios web interface.
make install-webconf
You need to protect the Nagios web interface by creating a user account (nagiosadmin).
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Remember the password that you set to this user – you will need it later.
Restart Apache service.
systemctl restart httpd
systemctl enable httpd
Configure Nagios
Sample configuration can be found /usr/local/nagios/etc
directory. These sample files would be enough for getting started with Nagios.
But, you would need to make one change before you proceed.
Edit /usr/local/nagios/etc/objects/contacts.cfg
config file and change the email address of nagiosadmin contact definition to the address you would like to use for receiving alerts.
vi /usr/local/nagios/etc/objects/contacts.cfg
Change the Email address field with your email id to receive the notification.
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 <span class="pre-comments">admin@linuxbees.com</span> ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
Install Nagios Plugins
Extract the download Nagios Plugins.
cd /tmp
tar -zxvf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
Use below commands to compile and install the Nagios plugins.
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
Start Nagios Server
Check for any errors in the Nagios configuration file.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
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
If you don’t see any errors, then you are good to start the Nagios service.
systemctl start nagios
Start Nagios on system startup.
systemctl enable nagios
SELinux
See if SELinux is in Enforcing mode.
getenforce
We recommend it to disable it.
setenforce 0
You need to modify the settings in /etc/selinux/config to make it permanent. Then reboot the machine.
Firewall
Make sure you allow the web server to be accessible outside the network.
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
Access Nagios Web Interface
You can access the Nagios web interface using the following URL.
Enter the username and password:
You would get the Nagios console.
Click Hosts in the left pane to get a list of systems being monitored by Nagios. We haven’t added any host to Nagios, So it simply monitors the localhost itself.
Click Service in the left pane to get the status of any services that are being monitored with Nagios.
Conclusion
You have successfully setup Nagios monitoring tool on CentOS 7. At this moment, Nagios monitors only the services of Nagios server. In our upcoming article, we will configure Nagios to monitor Remote Linux System.