
Nagios, also known as Nagios Core, is a free and open-source application that monitors systems, networks, and infrastructure. Nagios offers to monitor and alerting services for servers, switches, applications, and services.
Prerequisites
To install Nagios server, you must have root privileges on the CentOS 7 server. If you need help setting up CentOS 7, follow the How to setup CentOS 7.
My Nagios server test box details.
- OS: CentOS 7 Minimal
- IP Address: 192.168.117.140/24
- Firewalld: Enable.
Step 1: Update OS
Login to your server, make sure that your server is up-to-date by running the following command.
[luv@teclearners ~]$ sudo yum -y update
Step 2: Install Build Dependencies
Because we are building Nagios 4 from source, we must install build dependencies libraries that will allow us to complete the build.
[luv@teclearners ~]$ sudo yum install httpd php php-cli gcc unzip wget glibc glibc-common gd gd-devel net-snmp postfix perl
[luv@teclearners ~]$ sudo yum groupinstall development tools
Step 3: Setup User Accounts
We must create a user and group that will run the Nagios process. we will create a “nagios” user and “nagcmd” group.
[luv@teclearners ~]$ sudo useradd nagios
[luv@teclearners ~]$ sudo passwd nagios
[luv@teclearners ~]$ sudo groupadd nagcmd
[luv@teclearners ~]$ sudo -a -G nagcmd nagios
[luv@teclearners ~]$ sudo -a -G nagcmd apache
Step 4: Download Nagios and Plugins
Go to the Nagios download page, and get the latest version. The current latest version is Nagios 4.4.6, plugin 2.3.3 date 04/06/2020: .
[luv@teclearners Downloads]$ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz
[luv@teclearners Downloads]$ wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
Step 5: Install Nagios
Go to the directory where you have downloaded nagios , plugins and extrat it using terminal.
[luv@teclearners Downloads]$ tar xzf nagios-4.4.6.tar.gz
To compile and install nagios, change to the nagios directory, and run the following commands.
[luv@teclearners Downloads]$ cd nagios-4.4.6/
[luv@teclearners nagios-4.4.6]$ sudo ./configure –with-command-group=nagcmd
[luv@teclearners nagios-4.4.6]$ sudo make all
[luv@teclearners nagios-4.4.6]$ sudo make install
[luv@teclearners nagios-4.4.6]$ sudo make install-init
[luv@teclearners nagios-4.4.6]$ make install-config
[luv@teclearners nagios-4.4.6]$ sudo make install-commandmode
To install the Nagios web interface, enter the following command.
[luv@teclearners nagios-4.4.6]$ sudo make install-webconf
Create a user account “nagiosadmin for loggin into the Nagios web interface.
[luv@teclearners nagios-4.4.6]$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache server to make the new settings take effect.
[luv@teclearners nagios-4.4.6]$ sudo systemctl restart httpd
[luv@teclearners nagios-4.4.6]$ sudo systemctl restart httpd
Step 6: Install Nagios plugins
Go to the directory where you downloaded the the nagios plugins, and extract it.
[luv@teclearners Downloads]$ tar zxf nagios-plugins-2.3.3.tar.gz
Change to the nagios plugins directory:
[luv@teclearners Downloads]$ cd nagios-plugins-2.3.3/
Run the following commands one by one to compile and install the plugins.
[luv@teclearners nagios-plugins-2.3.3]$ sudo ./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl
[luv@teclearners nagios-plugins-2.3.3]$ sudo make
[luv@teclearners nagios-plugins-2.3.3]$ sudo make install
Step 7: Configure Nagios
Nagios configuration files are installed in the /usr/local/nagios/etc directory. It should work fine without any changes. However, you need to put your actual email ID to receive alerts.
Edit the /usr/local/nagios/etc/objects/contacts.cfg config files with your favorite editor and change the email address associated with the nagiosadmin, as shown below.
[luv@teclearners /]$ sudo 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 luv@teclearners.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
Save and close the file.
Edit file /etc/httpd/conf.d/nagios.conf
[luv@teclearners /]$ sudo vi /etc/httpd/conf.d/nagios.conf
[...] # Comment the following lines # Order allow,deny # Allow from all # Uncomment and Change lines as shown below Order deny,allow Deny from all Allow from 127.0.0.1 192.168.117.0/24 [...]
Restart httpd service:
[luv@teclearners /]$ sudo systemctl restart httpd
Now, you can check for any configuration errors following using command:
[luv@teclearners /]$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
You should get the result as depicted in the below image.

If there are no errors, start Nagios service and make it to start automatically on boot.
[luv@teclearners /]$ sudo systemctl start nagios
[luv@teclearners /]$ sudo systemctl enable nagios
Step 8: Firewall
Make sure to allow httpd through the firewall.
[luv@teclearners /]$ sudo firewall-cmd –add-port=80/tcp –permanent
[luv@teclearners /]$ sudo firewall-cmd –reload
Step 9: Access Nagios Web Interface
Now access the Nagios web interface using the following URL. You will be prompted for the username (nagiosadmin) and password you specified earlier.
http://nagios server IP address/nagios/

Nagios console will look like as depicted below.

Click on “Hosts” & “Services” in the left panel to get a list of systems and services being monitored by the Nagios server. We have not added any host to the Nagios server, So it by default monitors the localhost itself.

In the next article, we will see How To Monitor Remote Linux System With Nagios Server.