24/7/365 Support

Installing and configuring Nagios Core in CentOS

In this process, we will learn how to install Nagios Core version 4, an open-source network monitoring system that checks whether hosts and services are working and notifies users when problems occur or services become unavailable. Nagios provides solutions to monitor your complete IT infrastructure and is designed with an architecture that is highly extendable and customizable and goes far beyond simple bash scripts to monitor your services. (Refer to the Monitoring important server infrastructure process.)

To Start With: What Do You Need?

To complete this process, you will require a working installation of the CentOS 7 operating system with root privileges, a console-based text editor of your choice, and a connection to the Internet in order to facilitate the download of additional packages. Nagios Core 4 is not available in the official sources but from the EPEL repository; make sure to have installed it before (refer to the Using a third-party repository process in, Managing Packages with YUM). For the Nagios web frontend, you need a running Apache2 web server as well as PHP (refer to the processes from, Providing Web Services) installed on your Nagios server. In our example, the Nagios server has the IP address 192.168.1.7, and it will be able to monitor all IT infrastructure in the complete 192.168.1.0/24 subnet.

The Process

Nagios Core 4 is not available by default, so let’s begin by installing all the required packages:

  1. To do so, log in as root and type the following command:
    yum install nagios nagios-plugins-all nagios-plugins-nrpe nrpe
  2. First, create a new user account called nagiosadmin, which is needed for authentication to the web frontend (enter a secure password when prompted), then reload the Apache configuration:
    htpasswd /etc/nagios/passwd nagiosadmin && systemctl reload httpd
  3. Now, add an e-mail address for the nagiosadmin web user to the Nagios configuration, open the following file, and search and replace the string, nagios@localhost, with an appropriate e-mail address you want to use here (it can be a domain-wide or external e-mail address):
    vi /etc/nagios/objects/contacts.cfg
  4. Now, we need to adjust the main configuration file to activate /etc/nagios/servers as our server’s definition configuration directory, where we will put all our server config files later, but first, make a backup:
    cp /etc/nagios/nagios.cfg /etc/nagios/nagios.cfg.BAK
    sed -i -r 's/^#cfg_dir=(.+)servers$/cfg_dir=\1servers/g'
    /etc/nagios/nagios.cfg
  5. We will have to create the server’s config directory that we just defined in the last step:
    mkdir /etc/nagios/servers
    chown nagios: /etc/nagios/servers;chmod 750 /etc/nagios/servers
  6. Afterwards, to check the correctness of the nagios.cfg syntax, run the following:
    nagios -v /etc/nagios/nagios.cfg
  7. Finally, enable the Nagios daemon on boot and start the service:
    systemctl enable nagios && systemctl start nagios

How Does It Work?

Here in this process, we have shown you how to install the Nagios Core v4 server (Core is the open-source version of the Nagios project) on CentOS 7. Besides the main Nagios package, we also required the NRPE package and all the Nagios plugins on our Nagios server. After installing, we created a user account, which is able to log in to the web frontend, and we set the e-mail address for this user in the main Nagios configuration file. Next, we activated the /etc/nagios/servers directory using sed, where all our server definition files will be put in a later process, here. Then, we created the directory and changed permissions to the Nagios user. To test the Nagios server installation, open a web browser on a computer in the same subnet 192.168.1.0/24 as your Nagios server, open the following URL (in our example, the Nagios server has the IP 192.168.1.7, so change accordingly), and then log in with your newly created nagiosadmin user account to http://192.168.1.7/nagios.

 

Help Category:

What Our Clients Say