How to install Nagios 4 from source on Ubuntu 14.04 LTS
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 only help you to install Nagios but also enable you 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 : 10.10.0.x
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.
$ dpkg -l
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. (verify validity of your download)
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.
# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.0.8.tar.gz
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)
#cd nagios-4.0.8
#ls
Now start compiling the Nagios core package
$ sudo ./configure --with-command-group=nagcmd
.......................
*** Configuration summary for nagios 4.0.8 08-12-2014 ***:
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: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
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.
....................
$ sudo make all
....................
*** Support Notes *******************************************
If you have questions about configuring or running Nagios,
please make sure that you:
- Look at the sample config files
- Read the documentation on the Nagios Library at:
http://library.nagios.com
before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you. This might include:
- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:
http://support.nagios.com
.....................
$ sudo make install
.....................
NOTE: Use 'make install-classicui' to revert to classic Nagios theme
make[1]: Leaving directory `/home/sysadm/nagios-4.0.8'
make install-basic
make[1]: Entering directory `/home/sysadm/nagios-4.0.8'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults
*** Main program, CGIs and HTML files installed ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
make install-init
- This installs the init script in /etc/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs sample config files in /usr/local/nagios/etc
make[1]: Leaving directory `/home/sysadm/nagios-4.0.8'
.....................
$ sudo make install-init
.....................
/usr/bin/install -c -m 755 -d -o root -g root /etc/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/init.d/nagios
*** Init script installed ***
....................
$ sudo make install-comandmode
....................
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
...................
$ sudo make install-config
..................
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
..................
$ 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
root@host24:~/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
root@host24:~/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
root@host24:~/nagios-4.0.8$ ls -l /etc/apache2/sites-enabled/
# ls -l /etc/apache2/sites-enabled/
total 4
lrwxrwxrwx 1 root root 35 Jul 28 11:51 000-default.conf -> ../sites-available/000-default.conf
-rw-r--r-- 1 root root 982 Jul 28 13:01 nagios.conf
root@host24:~/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 [1246]
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.
>nagiospassword
$ 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.
root@host24:~$ 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
root@host24:~$
Step 11: Install Nagios Plugins
# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
# tar xvzf nagios-plugins-2.0.3.tar.gz
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
#make install
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 10.10.0.x and suffix is /nagios
http://10.10.0.24/nagios
Success!!!!!!!!