In this tutorial we will learn, how to install Nagios 4 from source on Ubuntu 14.04 LTS. In this practical I have seen some problems while Nagios core 4 installation. Because in Ubuntu 14.04 LTS is shipped with new Apache 2.4 version ,it was quite obvious some extra steps we have to do.
I will also share some problems which I faced during the Nagios installation. More clearly it requires basic knowledge on Apache.I hope it will not help you to install Nagios whereas will get some information on Apache as well.
Description of Server and Software used
Operating System : Ubuntu 14.04 LTS Server edition
Arch : x86_64
Web Server : Apache 2.4
Nagios : Nagios Core 4.0.8 (Source Code)
Nagios Plugin : nagios-plugins 2.0.3 (Source Code)
Server IP Address : 192.168.56.102
Steps to install Nagios core 4.0 from source on Ubuntu 14.04 LTS
First login into your server and follow the given below steps to install Nagios core 4 on Ubuntu.
Step 1: Install Apache, PHP, OpenSSL and other requirements
Run the below given command to install Apache, PHP and other requirements.
Note: On Ubuntu 14.04 , apache 2.4 is default web server
sudo apt-get install wget build-essential apache2 php5 openssl perl make php5-gd wget libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev daemon
Step 2: Create user and group for Nagios
Run below given command to create user and group used for Nagios application.
sudo useradd nagios sudo groupadd nagcmd sudo usermod -a -G nagcmd nagios
Step 3: Download latest Nagios Core source package
You can download the current stable package from Nagios site.
At the time of writing this post Nagios Core version 4.0.8 was available.
Note: You can also download latest stable package. Hence, have to do slight changes in command with download URL.
Note: Nagios is also available at GitHub
Step 4: Extract downloaded Nagios core package
Now we are extracting the downloaded Nagios core package by using tar command
Note: Do the change with nagios package name, in case you have downloaded other version
tar -xvzf nagios-4.0.8.tar.gz
Step 5: Installing Nagios Core by compilation
Now install Nagios Core 4.x with compilation method.
First change to extracted out Nagios directory (From step 4)
Now start compiling the Nagios core package
sudo ./configure --with-command-group=nagcmd sudo make all sudo make install sudo make install-init sudo make install-config sudo sudo make install-commandmode sudo make install-webconf
IMPORTANT NOTE: When I run the command
sudo make install-webconf. It gave some error with Apache path. Because we are working on Ubuntu 14.04 , apache path is /etc/apache2
See the below given error, which I faced
[email protected]:~/nagios-4.0.8$ sudo make install-webconf /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf /usr/bin/install: cannot create regular file ‘/etc/httpd/conf.d/nagios.conf’: No such file or directory make: *** [install-webconf] Error 1 [email protected]:~/nagios-4.0.8$
Solution Instead of using
sudo make install-webconf , use below given command . You should be inside nagios-4.0.8 directory.(I have just changed the path of Apache)
sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf
Now you can check, the nagios.conf file will be available at /etc/apache2/sites-enabled. Reference from my system
[email protected]:~/nagios-4.0.8$ ls -l /etc/apache2/sites-enabled/ total 4 lrwxrwxrwx 1 root root 35 Aug 25 02:34 000-default.conf -> ../sites-available/000-default.conf -rw-r--r-- 1 root root 982 Aug 25 02:46 nagios.conf [email protected]:~/nagios-4.0.8$
Step 6: Copy eventhandlers
Copy eventhandlers directory to /usr/local/nagios/libexec/
sudo cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/
Now change the ownership of /usr/local/nagios/libexec/eventhandlers
sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Step 7: Create Nagios init script
Create nagios init script to start/stop/restart the nagios with service command
sudo vi /etc/init/nagios.conf
Now paste the below given contents in /etc/init/nagios.conf file
description "nagios 4.x core" start on filesystems stop on runlevel  respawn setuid nagios setgid nagcmd console log script exec /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg end script
Save and exit from file. It will create a file /etc/init/nagios.conf with above given contents.
Step 8: Enable apache rewrite and cgi module
Enable Apache’s rewrite and cgi module. And then restart the Apache2 service. Use below given command for this
sudo a2enmod rewrite sudo a2enmod cgi sudo service apache2 restart
Step 9: Start Nagios service
Start the nagios service
sudo service nagios start
Additional Information : From nagios init script you can start/stop/restart/status of nagios service by using below given commands
sudo service nagios start sudo service nagios stop sudo service nagios restart sudo service nagios status
Step 10: Change the permission of nagios.cmd file
Change the permission of nagios.cmd file
sudo chmod 666 /usr/local/nagios/var/rw/nagios.cmd
Step 11: Set Nagiosadmin user’s password
While setting htpasswd for nagiosadmin user, I faced the problem with
sudo: htpasswd: command not found
To solve this problem, install apache2-utils
sudo apt-get install apache2-utils
Now htpasswd is available. We are now setting nagiosadmin user’s password.
Type the password of nagiosadmin of your interest.
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
You may be wondered, why I only selected nagiosadmin user. The answer is hidden in /usr/local/nagios/etc/cgi.cfg file.
See below given reference. The nagiosadmin user is mentioned in the file and has many privileges on Nagios system. That is the reason we are setting nagiosadmin user password, so that it can login into Nagios Dashboard and take control.
[email protected]:~$ sudo grep nagiosadmin /usr/local/nagios/etc/cgi.cfg authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin [email protected]:~$
Step 12 : Access Nagios Server Dashboard
Now access the Nagios Server dashboard. Get ready with nagiosadmin password which we will use here
Open the web browser and type
http://SERVER_IP_ADDRESS/nagios on URL field.
SERVER_IP_ADDRESS = Give IP address of your Server (Use
ifconfing command to find ip address)
In our practical, we are using the IP Address 192.168.56.102 and suffix is /nagios
Give username and password
Username : nagiosadmin
Password : ****** (Which you have set at Step 11)
After successful login, you will see the Nagios Dashboard.
We will see lots of Red color alerts on screen. It is because of Nagios-plugin is not installed.
Now to clear these alerts, in next section we are installing Nagios-plugins on same Nagios Server
Install Nagios Plugins on Nagios server
Now install the Nagios plugins on newly built Nagios server. You can get latest nagios plugins information from Nagios Plugins community site.You can download and install latest from Nagios plugins site.
Right now, I got the new version as nagios-plugins-2.0.3
Download nagios-plugins-2.0.3 package.
Extract the package
tar -xvzf nagios-plugins-2.0.3.tar.gz
Change to extracted out directory
Compiling the Nagios plugins
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios sudo make sudo make install
The nagios is default updated at every 90 seconds. Wait for a few minutes, you will get all alerts monitored and green in color.