How to Setup and Configure Nagios Core on CentOS 7

Nagios Core is a free and open source software that monitors systems, networks and infrastructure. You can monitor and configure alerts for servers, switches, application, services, logs. In this tutorial, you will learn how to setup and configure Nagios Core 4.4.5 on CentOS 7.
Prerequisite
# setenforce 0
Or modify /etc/selinux/config file and change enforcing to disabled. After modifications please restart your machine to enable changes.
# vim /etc/selinux/config
See Also: How to Install Zabbix Server 5.0 on Ubuntu 20.04
See Also : How to Install Zabbix Agent on Ubuntu 20.04 / CentOS 7
Step:1. Install Build Dependencies
Now you need to install the dependencies that Core will need in order to function properly.
# yum install gcc glibc glibc-common wget gd gd-devel perl net-snmp openssl-devel curl unzip -y
Step:2. Download Nagios Core and Nagios Plugin
You need to create a directory for nagios installation. Now we will download the required nagios source code using below command.
# mkdir /nagios
# cd /nagios
# curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
# curl -L -O https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
Step:3. Create Nagios User and Group
You must create a user and group that will responsible to run the Nagios process. Please create ‘nagios’ user and ‘nagcmd’ group, then add the user to this group using below commands,
# useradd nagios
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache
Here, first we will configure nagios core, so we will move into nagios directory and extract downloaded packages with tar command as follows. Therefore we will configure nagios core as follows and you can see the end result in sample output snip.
# cd /nagios
# tar -xvf nagios-4.4.5.tar.gz
# cd /nagios/nagios-4.4.5
# ./configure --with-command-group=nagcmd
In below snip, there is end result of above command. The above command is executed successfully without errors or warning.
After configuring, you need to compile all binaries with below command.
# make all
After compiling, you need to install all binaries using make install command. It will install all required libraries.
# make install
End Result of the above command
The below command will install the init scripts for nagios. And to make sure nagios work from command line, you need to install command mode.
# make install-init
# make install-commandmode
Below commands install sample nagios files.
# make install-config
To receive email alerts on your mail id, Open the “ contacts.cfg “ file and put the email address.
# vim /usr/local/nagios/etc/objects/contacts.cfg
Step:5. Configure Web Interface for Nagios
We finished all configuration changes and now we are good to configure web interface for better monitoring. The following command “make install-webconf” will configure web interface and a user nagiosadmin. You now need to create a password for the nagiosadmin user. This user will be used to login to your nagios web console.
# make install-webconf
# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: xxxxxxxxx Re-type new password: xxxxxxxxx Adding password for user nagiosadmin
Step:6. Install & Configure Nagios Plugin
As we have already downloaded nagios plugin, let’s configure and install it using below commands.
# cd /nagios
# tar -xvf nagios-plugins-2.2.1.tar.gz
# cd /nagios/nagios-plugins-2.2.1
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios# make all
# make install
Step:7. Verify Nagios Configuration Files
So we have completed all necessary steps to configure nagios. Now let’s verify whether we have done all steps correctly. Please cross verify your output by below sample output.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
We now are good to start the nagios and httpd service.
# systemctl start httpd.service
# systemctl start nagios.service
Step:8. Login to the Nagios Web Console
Well done, you have successfully installed and configured Nagios. Now you can open in your web browser using “ http://your_server_IP_address/nagios" then provide username “ nagiosadmin” and password. The screen must be looking as below and nagios process should be running.
Conclusion
Hence, you have successfully installed and configured Nagios Core on CentOS 7.
I hope I helped. Happy Learning, Thanks !!
See Also : How to Add Remote Linux Host to Nagios Monitoring Server
Read Also : Difference Between File Systems in Linux
Originally published at https://thecodecloud.in on September 4, 2020.