How to Install Nagios Open Source Monitoring on CentOS 9 Stream Server

How to Install Nagios Open Source Monitoring on CentOS 9 Stream Server. In this tutorial we will introduce Nagios with it’s main advantages and then we will proceed to download Nagios server and compile it from the downloaded source.

Nagios is very useful monitoring tool for Network and System administrator that helps to add and monitor any number of hosts and network devices from the web based console. If you are looking for an open source monitoring solution then Nagios is the best option for you.

What Is Nagios Monitoring Tool?

Nagios is an open source monitoring tool for computer systems. The tool is designed to run on the Linux operating system. It is used to monitor devices running on Linux, Windows and Unix Operating systems (OSes). The system conducts periodic checks regularly on critical parameters of application, network and server resources.

Nagios’ dashboard provides an overview of these critical parameters. Based on these parameters and thresholds, it sends out alerts to its users. You can receive the notification in different ways, including email and text messages. Then, an authorization system allows the administrator to restrict the access.

Furthermore, you can run Nagios either opting for an agent based or agentless configuration. While agent based configurations are installed both on hardware and software to collect data and then reported back to the management server, agentless monitoring uses the existing protocol to emulate an agent. However, whatever system you choose, they will be able to monitor file system usage, OS metrics, service and process states, etc.

Nagios Features

Nagios offers the following features to its users:

  • It can be managed effortlessly to find the issues that are present in the networks, thereby providing security and scalability to the network.
  • It also helps in managing logs and database systems.
  • It has an informative and easy to use web interface.
  • It sends an immediate alert to the user whenever it detects any network issues.
  • It also detects any kinds of performance bottlenecks.
  • It also offers several monitoring options like SMTP, HTTP, FTP, POP, SNMP, SSH, etc.
  • It offers flexibility as it has got multi user access simultaneously so that monitoring can be done effortlessly for network components.
  • Failover capability and continuous monitoring is the solid feature of this tool. It identifies performance bottlenecks in the network.

Benefits Of Nagios Monitoring

With the help of Nagios Monitoring, you tend to enjoy the following benefits:

  • It increases the ability of services, servers, applications and processes so that users can use them to monitor the network.
  • It helps in finding the protocol failures, network outages, and server outages so that they can be detected and solved immediately.
  • It also detects the server failure effortlessly and sends the notification to users immediately to inform them about the issue.
  • The web interface provided by the tool aids in monitoring the network and finding the issues present in the network components.

Follow this post to learn how to install Nagios Open Source Monitoring on CentOS 9 Stream Server.

Install Nagios Open Source Monitoring on CentOS 9 Stream Server

Prerequisites

  • A server running CentOS 9 Stream with SSH access.
  • A root user or a user with sudo privileges.

Install LAMP Server

First, you will need to install the LAMP server to access the Nagios via web browser. You can install all LAMP components by running the following command:

				
					dnf install httpd mariadb-server php php-mysqlnd php-fpm
				
			

Once LAMP server is installed, start and enable all LAMP server service by running the following command:

				
					systemctl start httpd mariadb php-fpm
systemctl enable httpd mariadb php-fpm

				
			

Download and Install Nagios

By default, Nagios is not included in the Centos 9 default repo. So you will need to compile it from the source. First, you will need to install all required dependencies needed to compile Nagios. You can install all of them using the following command:

				
					dnf install gcc glibc glibc-common wget gd gd-devel perl postfix -y
				
			

After installing all the dependency, add a Nagios user and set a password:

				
					adduser nagios
passwd nagios
				
			

Then add the Nagios user to the Apache group:

				
					usermod -aG nagios apache
groupadd nagcmd
				
			

After that, please download the Nagios source using the following command:

				
					wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
				
			

Once the download is completed, extract the downloaded source with the following command:

				
					tar -xvf nagios-4.4.5.tar.gz
				
			

Next, navigate to the Nagios source directory and configure it with the following command:

				
					cd nagios-4.4.5
./configure --with-command-group=nagcmd
				
			

You will get the following output:

				
					 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  /run/nagios.lock
   Check result directory:  /usr/local/nagios/var/spool/checkresults
           Init directory:  /lib/systemd/system
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /usr/sbin/sendmail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

				
			

Install Nagios

Please install Nagios with the following command:

				
					make all
make install

				
			

Next, install systemd service file for Nagios using the following command:

				
					make install-init
make install-daemoninit
				
			

Here please install Nagios config, and other configuration file with the following command:

				
					make install-config
make install-commandmode
make install-exfoliation
				
			

Next, install Nagios web server configuration file with the following command:

				
					make install-webconf
				
			

You will get the following output:

				
					/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
if [ 0 -eq 1 ]; then \
	ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \
fi

*** Nagios/Apache conf file installed ***

				
			

Setup Nagios Admin Password

By default, Nagios web interface is not secured with username and password. For security reasons, it is a good idea to secure Nagios admin console with username and password. You can set Nagios admin password with the following command:

				
					htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
				
			

Set your admin password as shown below:

				
					New password: 
Re-type new password: 
Adding password for user nagiosadmin
				
			

Next, restart the Apache service to apply the changes:

				
					systemctl restart httpd
				
			

Install Nagios Plugins

Nagios uses plugins to monitor different services, devices and application. First, download the Nagios plugin source with the following command:

				
					wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
				
			

Once the download is completed, extract the downloaded source with the following command:

				
					tar -xvf nagios-plugins-2.2.1.tar.gz
				
			

Next, change the directory to the source directory with the following command:

				
					cd nagios-plugins-2.2.1
				
			

Here create required directory and set proper permission on it:

				
					mkdir -p /usr/local/nagios/var/spool/checkresults
chown -R nagios:nagios /usr/local/nagios/var/spool/checkresults

				
			

Next, configure and install the Nagios plugin with the following command:

				
					./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
				
			

Now in this part of our article How to Install Nagios Open Source Monitoring on CentOS 9 Stream Server it is time to verify and start Nagios service.

Verify and Start Nagios

At this point, Nagios is installed and configured. Now, its time to check it. To verify Nagios configuration, run the following command:

				
					/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
				
			

You should see the following output:

				
					Running pre-flight check on configuration data...

Checking objects...
	Checked 8 services.
	Checked 1 hosts.
	Checked 1 host groups.
	Checked 0 service groups.
	Checked 1 contacts.
	Checked 1 contact groups.
	Checked 24 commands.
	Checked 5 time periods.
	Checked 0 host escalations.
	Checked 0 service escalations.
Checking for circular paths...
	Checked 1 hosts
	Checked 0 service dependencies
	Checked 0 host dependencies
	Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

				
			

Please start the Nagios service and enable it to start at system reboot:

				
					systemctl start nagios
systemctl enable nagios
				
			

To check the Nagios service, run the following command:

				
					systemctl status nagios
				
			

You should see the Nagios active status in the following output:

				
					● nagios.service - Nagios Core 4.4.5
   Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-06-25 06:45:04 UTC; 6s ago
     Docs: https://www.nagios.org/documentation
  Process: 48453 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
  Process: 48452 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
 Main PID: 48455 (nagios)
    Tasks: 6 (limit: 23696)
   Memory: 2.3M
   CGroup: /system.slice/nagios.service
           ├─48455 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
           ├─48456 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─48457 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─48458 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─48459 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           └─48460 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Jun 25 06:45:04 centos9 nagios[48455]: qh: Socket 'https://net.cloudinfrastructureservices.co.uk/usr/local/nagios/var/rw/nagios.qh' successfully initialized
Jun 25 06:45:04 centos9 nagios[48455]: qh: core query handler registered
Jun 25 06:45:04 centos9 nagios[48455]: qh: echo service query handler registered
Jun 25 06:45:04 centos9 nagios[48455]: qh: help for the query handler registered
Jun 25 06:45:04 centos9 nagios[48455]: wproc: Successfully registered manager as @wproc with query handler
Jun 25 06:45:04 centos9 nagios[48455]: wproc: Registry request: name=Core Worker 48457;pid=48457
Jun 25 06:45:04 centos9 nagios[48455]: wproc: Registry request: name=Core Worker 48458;pid=48458
Jun 25 06:45:04 centos9 nagios[48455]: wproc: Registry request: name=Core Worker 48456;pid=48456
Jun 25 06:45:04 centos9 nagios[48455]: wproc: Registry request: name=Core Worker 48459;pid=48459
Jun 25 06:45:05 centos9 nagios[48455]: Successfully launched command file worker with pid 48460

				
			

Configure Firewall

If firewalld service is installed and running on your server then you will need to allow the HTTP port 80 via firewalld service. You can allow it using the following command:

				
					firewall-cmd --add-port=80/tcp --permanent
				
			

Next, reload the firewalld service to apply the firewall rule:

				
					firewall-cmd --reload
				
			

Access Nagios Web Interface

Now, open your web browser and access the Nagios web interface using the URL http://your-server-ip/nagios. You should see the Nagios login page:

Provide your admin username, password and click on the Sign in button. You should see the Nagios dashboard on the following screen:

nagios dashboard

Click on the hosts in the left pane, you should see your Nagios host on the following screen:

Click on the services in the left pane, you should see the status of all services on the Nagios server on the following screen:

Great job! We have learned How to Install Nagios Open Source Monitoring on CentOS 9 Stream Server. Let’s summarize. 

How to Install Nagios Open Source Monitoring on CentOS 9 Stream Server Conclusion

The Nagios monitoring tool is a free and powerful tool that allows system administrator to detect and fix the issues present in the network from the central place. Nagios web based console helps you to monitor and add several remote machines and network devices via web browser.

In the above guide, we explained how to install the latest version of Nagios on CentOS 9 Stream server. We also explained how to install the Nagios and NRPE plugins and configure them to monitor the server itself. You can now add the remote hosts to the Nagios and start monitoring them from the central location.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x