Installing and Configuring Nagios on Linux

I. Introduction to Nagios

Nagios logo

Nagios is an open-source computer system and network monitoring tool that can effectively monitor the status of Windows, Linux, and Unix hosts, network devices such as switches and routers, printers, and more. When a system or service experiences an abnormal state, it sends email or SMS alerts to immediately notify website operations personnel, and sends a normal email or SMS notification after the status recovers.

Nagios was originally named NetSaint, developed and maintained by Ethan Galstad to this day. NAGIOS is an acronym: “Nagios Ain’t Gonna Insist On Sainthood” — Sainthood translates to “saint,” and “Agios” is the Greek word for “saint.” Nagios was developed for use on Linux, but also works very well on Unix.

Key Features

  • Network service monitoring (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH)
  • Host resource monitoring (CPU load, disk usage, system logs), including Windows hosts (using NSClient++ plugin)
  • You can specify custom-written Plugins to collect data over the network to monitor any situation (temperature, warnings…)
  • You can configure Nagios to remotely execute plugins and run scripts remotely
  • Remote monitoring supports SSH or SSL encrypted channel monitoring
  • Simple plugin design allows users to easily develop their own required check services, supporting many development languages (shell scripts, C++, Perl, Ruby, Python, PHP, C#, etc.)
  • Includes many graphical data Plugins (Nagiosgraph, Nagiosgrapher, PNP4Nagios, etc.)
  • Supports parallel service checks
  • Can define network host hierarchies, allowing hierarchical checks starting from the parent host downward
  • Sends notifications when services or hosts experience problems, via email, pager, SMS, or any user-defined custom plugin for notification
  • Can define event handling mechanisms to reactivate problematic services or hosts
  • Automatic log rotation
  • Supports redundant monitoring
  • Includes a Web interface to view current network status, notifications, problem history, log files, etc.

II. How Nagios Works

The function of Nagios is to monitor services and hosts, but it does not itself include this functionality — all monitoring and detection functions are accomplished through various plugins.

After starting Nagios, it periodically and automatically invokes plugins to check server status. At the same time, Nagios maintains a queue where all status information returned by plugins enters. Nagios reads information from the head of the queue each time, processes it, and then displays the status results through the web interface.

Nagios provides many plugins that can conveniently monitor many service statuses. After installation, all plugins included with Nagios are located in /libexec under the Nagios home directory, such as check_disk for checking disk space, check_load for checking CPU load, and so on. You can view the usage and functionality of each plugin by running ./check_xxx -h.

Nagios can recognize 4 types of status return information: 0 (OK) indicates normal/green status, 1 (WARNING) indicates a warning/yellow, 2 (CRITICAL) indicates a very serious error/red, and 3 (UNKNOWN) indicates an unknown error/dark yellow. Nagios determines the status of the monitored object based on the value returned by the plugin and displays it through the web interface for administrators to promptly detect faults.

Four Monitoring States

2

Now regarding the alerting function — if a monitoring system discovers a problem but cannot send alerts, then it is meaningless. So alerting is also one of Nagios’s very important functions. However, similarly, Nagios itself has no alerting code, not even a plugin, but instead delegates this to users or other related open-source project teams.

Nagios installation refers to the basic platform, i.e., the installation of the Nagios software package. It is the framework of the monitoring system and the foundation of all monitoring.

Opening Nagios’s official documentation, you will find that Nagios basically has no dependency packages, only requiring the system to be Linux or another Nagios-supported system. However, if you have not installed Apache (HTTP service), then you will not have such an intuitive interface to view monitoring information, so Apache can be considered a prerequisite. There are many guides online for installing Apache — just follow them. After installation, check whether it works properly.

Knowing how Nagios manages server objects through plugins, let us now study how it manages remote server objects. The Nagios system provides a plugin called NRPE. Nagios periodically runs it to obtain various status information from remote servers. The relationship between them is shown in the diagram below:

1

Nagios remotely manages services via NRPE

1. Nagios executes the check_nrpe plugin installed on it and tells check_nrpe which services to check.

2. Via SSL, check_nrpe connects to the NRPE daemon on the remote machine.

3. NRPE runs various local plugins to check local services and status (check_disk, etc.).

4. Finally, NRPE sends the check results back to check_nrpe on the host side, and check_nrpe sends the results to the Nagios status queue.

5. Nagios reads information from the queue in sequence and then displays the results.

III. Lab Environment

Host Name OS IP Software
Nagios-Server CentOS release 6.3 (Final) 192.168.1.108 Apache, PHP, Nagios, nagios-plugins
Nagios-Linux CentOS release 5.8 (Final) 192.168.1.111 nagios-plugins, nrpe
Nagios-Windows Windows XP 192.168.1.113 NSClient++

The Server has Nagios software installed to process monitoring data and provide a web interface for viewing and management. Of course, it can also monitor information about the local machine itself.

The Client has NRPE and other client software installed, which performs monitoring according to the monitoring machine’s requests and then sends the results back to the monitoring machine.

Firewall is disabled / iptables: Firewall is not running.

SELINUX=disabled

IV. Lab Objectives

V. Nagios Server Installation

5.1 Basic Support Packages: gcc glibc glibc-common gd gd-devel xinetd openssl-devel

# rpm -q gcc glibc glibc-common gd gd-devel xinetd openssl-devel

8

If these packages are not present in the system, use yum to install them

# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

5.2 Create nagios user and user group

# useradd -s /sbin/nologin nagios# mkdir /usr/local/nagios# chown -R nagios.nagios /usr/local/nagios

6

Check the permissions of the nagios directory

# ll -d /usr/local/nagios/

7

5.3 Compile and Install Nagios

# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.3.tar.gz

# tar zxvf nagios-3.4.3.tar.gz

# cd nagios

# ./configure –prefix=/usr/local/nagios

9

10

# make all

11

12

# make install

13

# make install-init

14

# make install-commandmode

15

# make install-config

16

# chkconfig –add nagios

# chkconfig –level 35 nagios on

# chkconfig –list nagios

17

5.4 Verify that the program has been correctly installed

Switch to the installation path (here /usr/local/nagios) and check whether the five directories — etc, bin, sbin, share, var — exist. If they do, this indicates that the program has been correctly installed on the system. The purpose of each Nagios directory is described below:

bin Directory where Nagios executable programs are located
etc Directory where Nagios configuration files are located
sbin Directory where Nagios CGI files are located, i.e., the directory containing files required for executing external commands
share Directory where Nagios web page files are located
libexec Directory where Nagios external plugins are located
var Directory where Nagios log files, lock files, etc. are located
var/archives Directory for automatic Nagios log archiving
var/rw Directory used to store external command files

5.5 Install Nagios Plugins

# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

# tar zxvf nagios-plugins-1.4.16.tar.gz

# cd nagios-plugins-1.4.16

# ./configure –prefix=/usr/local/nagios

# make && make install

18

19

5.6 Install and Configure Apache and PHP

Apache and PHP are not required for installing Nagios, but Nagios provides a web monitoring interface through which you can clearly see the running status of monitored hosts and resources. Therefore, installing a web service is very necessary.
Note that starting from Nagios version 3.1.x, PHP support is required when configuring the web monitoring interface. Here, the Nagios version we downloaded is nagios-3.4.3, so after compiling and installing Apache, we also need to compile the PHP module. The PHP version selected here is php5.4.10.

a. Install Apache

# wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

# tar zxvf httpd-2.2.23.tar.gz

# cd httpd-2.2.23

# ./configure –prefix=/usr/local/apache2

# make && make install

22

If the following error occurs:

Then add –with-included-apr during compilation to resolve it.

b. Install PHP

# wget http://cn2.php.net/distributions/php-5.4.10.tar.gz

# tar zxvf php-5.4.10.tar.gz

# cd php-5.4.10

# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

23

# make && make install

24

c. Configure Apache
Find the Apache configuration file /usr/local/apache2/conf/httpd.conf
Find:

User daemon Group daemon 

Change to

User nagios Group nagios 

Then find

<IfModule dir_module>   DirectoryIndex index.html </IfModule> 

Change to

<IfModule dir_module>   DirectoryIndex index.html index.php </IfModule> 

Then add the following content:

AddType application/x-httpd-php .php 

For security reasons, under normal circumstances the Nagios web monitoring page must require authentication to access. This requires adding authentication configuration, i.e., adding the following information at the end of the httpd.conf file:

Copy Code
#setting for nagios ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/usr/local/nagios/sbin">      AuthType Basic      Options ExecCGI      AllowOverride None      Order allow,deny      Allow from all      AuthName "Nagios Access"      AuthUserFile /usr/local/nagios/etc/htpasswd             //File used for authentication for this directory access      Require valid-user </Directory> Alias /nagios "/usr/local/nagios/share" <Directory "/usr/local/nagios/share">      AuthType Basic      Options None      AllowOverride None      Order allow,deny      Allow from all      AuthName "nagios Access"      AuthUserFile /usr/local/nagios/etc/htpasswd      Require valid-user </Directory> 
Copy Code

d. Create the Apache directory authentication file

In the configuration above, the directory authentication file htpasswd was specified. Now create this file:

# /usr/local/apache2/bin/h

Leave a Comment

Your email address will not be published.