Complete Guide to Installing Nagios Core on CentOS 7 to Monitor Servers

Complete Guide to Installing Nagios Core on CentOS 7 to Monitor Servers

Nagios is a state-of-the-art software for monitoring IT infrastructure. It can monitor systems, networks, and other software with ease. If you’ve been using CentOS 7 as your platform, then you must use Nagios. It’s a handy tool in keeping an inventory of your servers and ensuring that you’ve got them configured to handle critical processes. Furthermore, because both are open-source in nature and hence free, it doesn’t cost you anything to get started. In this article, learn how to install Nagios Core on your CentOS 7.

Before you begin, you’d need to install Apache and PHP if you haven’t already.

To install Apache, you can use this command: yum install httpd

Similarly, install PHP by:
yum install php php-mysql
Next, you need to start Apache on boot by:
systemcti enable httpd.service
To work alongside PHP, you’d have to restart Apache with:
# systemcti restart httpd.service
Once that’s out of the way, you can get started with install Nagios.

Installing Nagios 4 on CentOS 7

First, you need to install the required packages using this command:

sudo yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd<unzip
Once done, it’s time to create a user and a group. These will be responsible for running the Nagios process. Use the following command to create a user named ‘nagios’ and a group named ‘nagcmd’:

#sudo useradd nagios
#sudo groupadd nagcmd
#sudo usermod -a -G nagcmd nagios
Now, you can install Nagios with the following command:

#cd ~ &&amp curl -L -O
Extract the files with:
#tar xvf nagios-*.tar.gz
Navigate into the directory where you’ve extracted the files with
#cd nagios-*
Before you start building nagios, you need to configure it. Use this command for that matter:
# ./configure –with-command-group=nagcmd
Once done, compile nagios with -
# make all
Now it’s time to start installing Nagios. Along with that, you’d have to install init scripts and the sample configuration files. Execute these commands:

#sudo make install
#sudo make install-commandmode
#sudo make install-init
#sudo make install-config
#sudo make install-webconf
If you want to send commands to the Nagios server using a web interface, you need to add the web server user apache to the group you created earlier (nagcmd). Execute this command for this:

#sudo usermod -G nagcmd apache
Installing the Nagios plugins

To make Nagios work, you must install the plugins. You can browse the required plugins from this directory and download as required to your server.

Here’s how you’ll be downloading the Nagios plugins 2.1.1.:

#cd ~ &&amp curl -L -O
Extract the plugin archive using this command:

tar xvf nagios-plugins-*.tar.gz
Go into the extracted directory with:

cd nagios-plugins-*
Configure the plugin with -
#./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl
Next, compile the plugin -
# make
Once compiled, install it with this command -
#sudo make install
Installing NRPE

To run Nagios on your server, you have to install NRPE or Nagios Remote Plugin Executor. Go to the NPRE download page and select the latest release to download and use.

If you’re installing version 2.15, then use this command:

#cd ~ && curl -L -O
Extract the files and enter into the directory using:

#tar xvf nrpe-*.tar.gz && cd nrpe-*
Configure NRPE using:

# ./configure –enable-command-args –with-nagios-user=nagios –with-nagios-group=nagios –with-ssl=/usr/bin/openssl –with-ssl-lib=/usr/lib/x86_64-linux-gnu
Now, use these commands to install NRPE and the xinetd startup script:

#make all
#sudo make install
#sudo make install-xinetd
#sudo make install-daemon-config
Once the processes are complete, open xinetd startup script in any vi editor with this command:

#sudo vi /etc/xinetd.d/nrpe
In the script, locate the ‘only_from’ line and add the IP of the Nagios server at the end like - only_from =

Save the changes and exit. Now, you have to restart xinetd service and start NRPE daemon with the following command:

#sudo service xinetd restart
This will mark the completion of the Nagios 4 installation process. Now Nagios Core is installed on your Cent OS server.

Configuring Nagios 4

Next you’d have to configure the Nagios you have just installed. Using a text editor, open the main Nagios configuration file using this command:

# sudo vi /usr/local/nagios/etc/nagios.cfg
Find the below line and uncomment it by removing the hash (#) sign:

Save the changes exit.

Now it’s time to create the directories where you’d be storing the configuration files for the servers you want to monitor. Use this command:

#sudo mkdir /usr/local/nagios/etc/servers
You also have to configure Nagios Contacts. So open the Nagios contacts configuration file using:
#sudo vi /usr/local/nagios/etc/objects/contacts.cfg
In the file, locate the email directive. Edit the value by replacing the existing email value (nagios@localhost) with your own. Save the changes made and exit.

Next, you’ have to configure the ‘check_nrpe’ command. You have to add a new command to the Nagios configuration so that it allows for using ‘check_nrpe’ command in Nagios service definitions. Open the file at -

#sudo vi /usr/local/nagios/etc/objects/commands.cfg
Then, add the following lines of code:

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
Save the changes and exit.

Configuring Apache

Along with Nagios, you’d also have to configure Apache. This involves creating an admin user who would have access to Nagios web interface. Execute this command to create the user:

# sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
When prompted, enter a password of your choice.

In case you created a user that is not named ‘nagiosadmin,’ then you’d have to edit the configuration file at /usr/local/nagios/etc/cgi.cfg. In this file, replace the reference for ‘nagiosadmin’ wherever it exists. Save the changes.

Now you have a Nagios Core that’s installed on your server and ready to be used. To get started, execute these commands:

#sudo systemctl daemon-reload
#sudo systemctl start nagios.service
#sudo systemctl restart httpd.service
To start Nagios when the server boots, here’s the command to execute:

#sudo chkconfig nagios on
To access the web interface of Nagios, execute the following command:

http://nagios_server_public_ip/nagios (substitute the IP address highlighted with your server IP)
Explore the page as there are lot of resources that you might find useful. If you decide to make any additional changes, it’s important to follow the instructions clearly to avoid errors. For further assistance, contact your hosting provider support team.
First release
Last update
0.00 star(s) 0 ratings

More resources from kumkumsharma