In this tutorial, we’ll walk you through each step of installing Nagios Core on Ubuntu 22.04. You will have a Nagios setup that is fully operational by the end of this article, which will make it easier for you to keep a close eye on your network and systems.
Update Apt Repository List
The first step is to ensure that your system is up to date. To do this run the following commands:
sudo apt update && apt upgrade -y
This will upgrade your system to the most recent packages and security patches and update the package list.
Install Prerequisites
Nagios has specific software prerequisites that must be installed on your Ubuntu 22.04 server. We’ll go through each of them and install them one by one.
sudo apt install autoconf gcc libc6 make wget unzip apache2 apache2-utils php libgd-dev libmcrypt-dev libssl-dev bc gawk dc build-essential snmp libnet-snmp-perl gettext mailutils
Create a Nagios User and Group
Nagios should run as a separate user and group. Create them with the following commands:
sudo useradd -m -s /bin/bash nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data
Download and Compile Nagios on Ubuntu
Let’s download and build Nagios Core. To store the Nagios source code, we will create a directory, go there, and then download the source archive. Please change the version number to the latest version:
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.3.tar.gz
Extract and Compile Nagios Core
Extract the downloaded archive and navigate to the Nagios on Ubuntu source directory:
tar -zxvf nagios-4.5.3.tar.gz
cd nagios-4.5.3
Next, configure Nagios on Ubuntu and compile it:
./configure --with-nagios-group=nagios --with-command-group=nagcmd
make all
Install Nagios Core Binaries and Web Interface Files
Install Nagios on Ubuntu binaries, init script, and web interface files:
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
Install Nagios on Ubuntu Plugins
Ubuntu’s package manager, apt
, provides pre-compiled Nagios Plugins that you can easily install. This is the recommended method as it simplifies the installation process and ensures that you get the latest stable versions of the plugins. Run the following commands to install Nagios Plugins using apt
:
sudo apt update
sudo apt install nagios-plugins
cp /usr/lib/nagios/plugins/* /usr/local/nagios/libexec/
It’s important to rebuild the Nagios configuration and restart Nagios after installing or updating plugins
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
sudo systemctl restart nagios
sudo systemctl restart apache2
Configure Apache Web Server
Set a password for the Nagios admin user:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Start Nagios and Apache Services
Start the Nagios and Apache services and enable them to start on boot
sudo systemctl enable nagios
sudo systemctl enable apache2
sudo systemctl restart nagios
sudo systemctl restart apache2
Access Nagios Web Interface
Open your web browser and navigate to http://your_server_ip/nagios
. Log in with the username nagiosadmin
and the password you set earlier.
Congratulations! You have successfully installed Nagios on Ubuntu 22.04. Now you can start configuring Nagios to monitor your network, hosts, and services.
You can also secure your web interface with SSL, this can be easily achieved with a Lets Encrypt Certificate.
Ref: https://www.virtono.com/community/tutorial-how-to/how-to-install-nagios-on-ubuntu-22-04/