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:
Next, you need to start Apache on boot by:
To work alongside PHP, you’d have to restart Apache with:
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:
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’:
Now, you can install Nagios with the following command:
Extract the files with:
Navigate into the directory where you’ve extracted the files with
Before you start building nagios, you need to configure it. Use this command for that matter:
Once done, compile nagios with -
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:
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:
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.:
Extract the plugin archive using this command:
Go into the extracted directory with:
Configure the plugin with -
Next, compile the plugin -
Once compiled, install it with this command -
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:
Extract the files and enter into the directory using:
Configure NRPE using:
Now, use these commands to install NRPE and the xinetd startup script:
Once the processes are complete, open xinetd startup script in any vi editor with this command:
In the script, locate the ‘only_from’ line and add the IP of the Nagios server at the end like - only_from = 127.0.0.1 101.123.123.111
Save the changes and exit. Now, you have to restart xinetd service and start NRPE daemon with the following command:
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:
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:
You also have to configure Nagios Contacts. So open the Nagios contacts configuration file using:
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 -
Then, add the following lines of code:
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:
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:
To start Nagios when the server boots, here’s the command to execute:
To access the web interface of Nagios, execute the following command:
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.
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:
Code:
yum install php php-mysql
Code:
systemcti enable httpd.service
Code:
# systemcti restart httpd.service
Installing Nagios 4 on CentOS 7
First, you need to install the required packages using this command:
Code:
sudo yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd<unzip
Code:
#sudo useradd nagios
#sudo groupadd nagcmd
#sudo usermod -a -G nagcmd nagios
Code:
#cd ~ && curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
Code:
#tar xvf nagios-*.tar.gz
Code:
#cd nagios-*
Code:
# ./configure –with-command-group=nagcmd
Code:
# make all
Code:
#sudo make install
#sudo make install-commandmode
#sudo make install-init
#sudo make install-config
#sudo make install-webconf
Code:
#sudo usermod -G nagcmd apache
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.:
Code:
#cd ~ && curl -L -O http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar
Code:
tar xvf nagios-plugins-*.tar.gz
Code:
cd nagios-plugins-*
Code:
#./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl
Code:
# make
Code:
#sudo make install
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:
Code:
#cd ~ && curl -L -O http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
Code:
#tar xvf nrpe-*.tar.gz && cd nrpe-*
Code:
# ./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
Code:
#make all
#sudo make install
#sudo make install-xinetd
#sudo make install-daemon-config
Code:
#sudo vi /etc/xinetd.d/nrpe
Save the changes and exit. Now, you have to restart xinetd service and start NRPE daemon with the following command:
Code:
#sudo service xinetd restart
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:
Code:
# sudo vi /usr/local/nagios/etc/nagios.cfg
Code:
#cfg_dir=/usr/local/nagios/etc/servers
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:
Code:
#sudo mkdir /usr/local/nagios/etc/servers
Code:
#sudo vi /usr/local/nagios/etc/objects/contacts.cfg
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 -
Code:
#sudo vi /usr/local/nagios/etc/objects/commands.cfg
Code:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
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:
Code:
# sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
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:
Code:
#sudo systemctl daemon-reload
#sudo systemctl start nagios.service
#sudo systemctl restart httpd.service
Code:
#sudo chkconfig nagios on
Code:
http://nagios_server_public_ip/nagios (substitute the IP address highlighted with your server IP)