Nagios is another popular tool for Linux operating systems that offers a more rounded approach toward monitoring. It provides a comprehensive environment that allows users to stay on top of all their machines and networks, no matter the scale of operations. It can also enable users to monitor remote hosts and servers from a single window. If used properly, Nagios has the potential to prevent system downtime and business losses from it.
Like other popular Linux monitoring systems, it works on a Server/Agent architecture that utilizes plugins to communicate with remote hosts. Furthermore, the user interface is very clean, which helps with a visual representation of data for any final reports. The following article will be a guide on how to install Nagios on different Linux distributions in simple steps. Read on to learn more about it.
Table Of Contents
What Is Nagios?
As stated earlier, Nagios is an open-source IT monitoring tool designed to run on the Linux OS. It can monitor devices running Linux, Windows, or Unix OS. The tool performs a periodic check on critical applications and ensures that the system is running within well-defined parameters. It can also help increase system availability, be it servers, services, or web applications. Thus, you can even find out if there are any network outages, protocol failures, or failed services when you are running Nagios. Users can also use it to keep an eye on services like Apache, MySQL, BIND, etc.
Since it is so flexible yet extensive, you can find Nagios in several industries, no matter the scale. The tool offers numerous practical and commercial solutions, as well as being quite suitable for personal use. You can rely on it to view and analyze reports in a central location. Here are a few critical parameters of applications and server resources you can monitor with Nagios:
- Memory use
- Disk use
- Microprocessor load
- Number of currently running processes
- Log files
- File system use
- OS metrics
- Service and process states
How To Install Nagios On Linux?
You can follow the steps prescribed below to quickly install Nagios on your Linux system.
Method 1. Install Nagios On Linux Manually
First, we will see a quick installation method that can install Nagios directly on a number of Linux distros. It is a bare-bones version but will likely work 95% of the time.
For Quick Installation
Step 1. Start by running the following command in your terminal:
curl https://assets.nagios.com/downloads/nagiosxi/install.sh | sh
Step 2. Now, randomized passwords will be created for the following Nagios objects:
MySQL nagiosxi user
MySQL dbmaint nagiosxi user
MySQL nagiossql user
MySQL ndoutils
Step 3. Run the following command to find the passwords:
/usr/local/nagiosxi/etc/xi-sys.cfg
And that’s it. Although, you will still need to finalize the installation, which we have covered below. But you are likely to have installed Nagios.
For Manual Download
Step 1. You can also install Nagios by issuing the following command:
cd /tmp
wget https://assets.nagios.com/downloads/nagiosxi/xi-latest.tar.gz
tar xzf xi-latest.tar.gz
cd nagiosxi
./fullinstall
Step 2. Now, to finalize the installation:
- First, use the URL to access the UI.
- Then, in the Settings, enter your License.
- Finally, hit Finish to save the settings.
Method 2. Install Nagios Using Offline Tarball
Note: This method is only available for CentOS and RHEL systems.
Step 1. Run the following commands:
mkdir -p /tmp/rpms
cd /tmp/rpms
rm -rf nagiosxi*
Step 2. Then, use the Tarball command to install it:
tar xzf nagiosxi
cd nagiosxi
./fullinstall
Method 3. Build Nagios From Source
This is the most complicated but complete method to install Nagios on a Linux system:
RHEL/CentOS/Oracle Linux
Step 1. First, disable SELinux:
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
Step 2. Now, install the prerequisite packages:
For RHEL 5/6/7 | CentOS 5/6/7 | Oracle Linux 5/6/7
yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
yum install openssl-devel
For RHEL 8/9 | CentOS
dnf install -y gcc glibc glibc-common perl httpd php wget gd gd-devel
dnf install openssl-devel
dnf update -y
Step 3. Then, download the Source
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
tar xzf nagioscore.tar.gz
Step 4. Compile the files:
cd /tmp/nagioscore-nagios-4.4.14/
./configure
make all
Step 5. Now, you need to create a User and Group
make install-groups-users
usermod -a -G nagios apache
Step 6. Then, install Binaries
make install
Step 7. Finally, install Daemon
On RHEL 5/6 | CentOS 5/6 | Oracle Linux 5/6
make install-daemoninit
chkconfig --level 2345 httpd on
On RHEL 7/8/9 | CentOS 7 | Oracle Linux 7/8/9
make install-daemoninit
systemctl enable httpd.service
Step 8. Now, you need to install a command mode:
make install-commandmode
Step 9. Then, continue with the configuration files
make install-config
make install-webconf
Step 10. Set your firewall:
On RHEL 5/6 | CentOS 5/6 | Oracle Linux 5/6
iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
service iptables save
ip6tables -I INPUT -p tcp --destination-port 80 -j ACCEPT
service ip6tables save
On RHEL 7/8/9 | CentOS 7 | Oracle Linux 7/8/9 | CentOS Stream 8/9
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=80/tcp --permanent
Step 11. You will then need an Admin User Account
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Step 12. Then, start the Apache Web Server
On RHEL 5/6 | CentOS 5/6 | Oracle Linux 5/6
service httpd start
On RHEL 7/8/9 | CentOS 7 | Oracle Linux 7/8/9
systemctl start httpd.service
Step 13. Lastly, start Nagios Core
On RHEL 5/6 | CentOS 5/6 | Oracle Linux 5/6
service nagios start
On RHEL 7/8/9 | CentOS 7 | Oracle Linux 7/8/9
systemctl start nagios.service
NOTE: You have only installed the Nagios Core engine. If you are noticing some errors under the hosts and services along the lines of:
stderr: execvp(/usr/local/nagios/libexec/check_load, ...) failed. errno is 2: No such file or directory
Then install Nagios Plugins to resolve it:
For CentOS 5
yum install -y gcc glibc glibc-common make gettext automake wget openssl-devel net-snmp net-snmp-utils epel-release
yum install -y perl-Net-SNMP
cd /tmp
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz
tar xzf autoconf-2.60.tar.gz
cd /tmp/autoconf-2.60
./configure
make
make install
For CentOS 6/7
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release
yum install -y perl-Net-SNMP
For CentOS Stream 8/9
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release
yum --enablerepo=powertools,epel install perl-Net-SNMP
For RHEL 5 | Oracle Linux 5
cd /tmp
wget http://archives.fedoraproject.org/pub/archive/epel/epel-release-latest-5.noarch.rpm
rpm -ihv epel-release-latest-5.noarch.rpm
yum install -y gcc glibc glibc-common make gettext automake wget openssl-devel net-snmp net-snmp-utils
yum install -y perl-Net-SNMP
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz
tar xzf autoconf-2.60.tar.gz
cd /tmp/autoconf-2.60
./configure
make
make install
For RHEL 6 | Oracle Linux 6
cd /tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -ihv epel-release-latest-6.noarch.rpm
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
yum install -y perl-Net-SNMP
For RHEL 7
cd /tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ihv epel-release-latest-7.noarch.rpm
subscription-manager repos --enable=rhel-7-server-optional-rpms
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
yum install -y perl-Net-SNMP
For RHEL 8/9
cd /tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm -ihv epel-release-latest-8.noarch.rpm
subscription-manager repos --enable=rhel-8-server-optional-rpms
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
yum install -y perl-Net-SNMP
For Oracle Linux 7
yum install -y yum-utils
yum-config-manager --enable ol7_optional_latest
cd /tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ihv epel-release-latest-7.noarch.rpm
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
yum install -y perl-Net-SNMP
For Oracle Linux 8/9
yum install -y yum-utils
yum-config-manager --enable ol8_optional_latest
cd /tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm -ihv epel-release-latest-8.noarch.rpm
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
yum install -y perl-Net-SNMP
Now download the source
cd /tmp
wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.6.tar.gz
tar zxf nagios-plugins.tar.gz
And compile to install
cd /tmp/nagios-plugins-release-2.4.6/
./tools/setup
./configure
make
make install
Ubuntu/Debian
Step 1. Install the necessary prerequisites:
sudo apt-get update
sudo apt-get install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php7.4 libgd-dev
sudo apt-get install openssl libssl-dev
Step 2. Then, download the Source
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
tar xzf nagioscore.tar.gz
Step 3. Compile the files:
cd /tmp/nagioscore-nagios-4.4.14/
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all
Step 4. Now, create a User And Group
sudo make install-groups-users
sudo usermod -a -G nagios www-data
Step 5. Install binaries
sudo make install
Step 6. Install Daemon
sudo make install-daemoninit
Step 7. Finally, install the Command Mode
sudo make install-commandmode
Step 8. Now Install the Configuration Files
sudo make install-config
sudo make install-webconf
sudo a2enmod rewrite
sudo a2enmod cgi
Step 9. Then, configure the Firewall
sudo ufw allow Apache
sudo ufw reload
Step 10. Create a Nagios Admin User account
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Step 11. Next, start the Apache Web Server
sudo systemctl restart apache2.service
Step 12. You can now finally run Nagios:
sudo systemctl start nagios.service
Fedora
Step 1. First, disable SELinux:
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
Step 2. Then, install the prerequisites
dnf install -y gcc glibc glibc-common perl httpd php wget gd gd-devel
dnf update -y
Step 3. Now, download the source
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
tar xzf nagioscore.tar.gz
Step 4. After that, compile the files:
cd /tmp/nagioscore-nagios-4.4.14/
./configure
make all
Step 5. Then, create a user and group
make install-groups-users
usermod -a -G nagios apache
Step 6. Now, install binaries
make install
Step 7. And, install daemon
make install-daemoninit
systemctl enable httpd.service
Step 8. Finally, install the Command Mode
make install-commandmode
Step 9. After that, install the Configuration Files
make install-config
make install-webconf
Step 10. Now, set up your Firewall
firewall-cmd --zone=FedoraServer --add-port=80/tcp
firewall-cmd --zone=FedoraServer --add-port=80/tcp --permanent
Step 11. Start the web server and launch Nagios:
systemctl start httpd.service
systemctl start nagios.service
Arch Linux
Step 1. Start by installing the prerequisites:
pacman --noconfirm -Syyu
pacman --noconfirm -S gcc glibc make wget unzip apache php gd traceroute php-apache
Step 2. Then, download the source
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
tar xzf nagioscore.tar.gz
Step 3. Now, compile the files:
cd /tmp/nagioscore-nagios-4.4.14/
./configure --with-httpd-conf=/etc/httpd/conf/extra
make all
Step 4. After that, create a user and group
make install-groups-users
usermod -a -G nagios http
Step 5. Then, install binaries:
make install
Step 6. After that, you have to install Daemon
make install-daemoninit
systemctl enable httpd.service
Step 7. Now, you can install the Command Mode
make install-commandmode
Step 8. Now, configure the files:
make install-config
make install-webconf
Step 9. You have to make additional changes to the Apache config file httpd.conf to enable modules.
So, change this:
LoadModule mpm_event_module modules/mod_mpm_event.so
To this:
#LoadModule mpm_event_module modules/mod_mpm_event.so
Change this:
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
To this:
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
And, change this:
<IfModule !mpm_prefork_module>
#LoadModule cgid_module libexec/apache24/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
#LoadModule cgi_module libexec/apache24/mod_cgi.so
</IfModule>
To this:
<IfModule !mpm_prefork_module>
LoadModule cgid_module libexec/apache24/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
LoadModule cgi_module libexec/apache24/mod_cgi.so
</IfModule>
Then, change this:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
To this:
<IfModule dir_module>
DirectoryIndex index.php index.html index.htm AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps
</IfModule>
Finally, add these lines to the end of the file:
LoadModule php7_module modules/libphp7.so
Include "conf/extra/nagios.conf"
Include "conf/extra/php7_module.conf"
<FilesMatch ".php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
So, to make all the changes mentioned above, run the following command:
sed -i 's/^LoadModule mpm_event_module modules\/mod_mpm_event\.so/#LoadModule mpm_event_module modules\/mod_mpm_event\.so/g' /etc/httpd/conf/httpd.conf
sed -i 's/^#LoadModule mpm_prefork_module modules\/mod_mpm_prefork\.so/LoadModule mpm_prefork_module modules\/mod_mpm_prefork\.so/g' /etc/httpd/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm AddType application\/x-httpd-php .phpAddType application\/x-httpd-php-source .phps/g' /etc/httpd/conf/httpd.conf
sed -i 's/#LoadModule cgid_module/LoadModule cgid_module/g' /etc/httpd/conf/httpd.conf
sed -i 's/#LoadModule cgi_module/LoadModule cgi_module/g' /etc/httpd/conf/httpd.conf
echo 'LoadModule php7_module modules/libphp7.so' >> /etc/httpd/conf/httpd.conf
echo 'Include "conf/extra/nagios.conf"' >> /etc/httpd/conf/httpd.conf
echo 'Include "conf/extra/php7_module.conf"' >> /etc/httpd/conf/httpd.conf
printf '\n<FilesMatch ".php$">\n' >> /etc/httpd/conf/httpd.conf
printf '\tSetHandler application/x-httpd-php\n' >> /etc/httpd/conf/httpd.conf
printf '</FilesMatch>\n' >> /etc/httpd/conf/httpd.conf
printf '<FilesMatch ".phps$">\n' >> /etc/httpd/conf/httpd.conf
printf '\tSetHandler application/x-httpd-php-source\n' >> /etc/httpd/conf/httpd.conf
printf '</FilesMatch>\n' >> /etc/httpd/conf/httpd.conf
Step 10. Now, create a “nagiosadmin” User Account
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Step 11. Then, start the Apache Web Server and Nagois
systemctl start httpd.service
systemctl start nagios.service