How to install Nagios 4 on Ubuntu 14.04 LTS

NagiosNagios is an open source software that can be used for infrastructure monitoring: Nagios will monitor servers, switches, applications and services and it alerts (via email or other stuff) the system admin when something goes wrong.

sudo apt-get install wget build-essential apache2 apache2-utils php5 php5-gd libgd2-xpm-dev libapache2-mod-php5 openssl perl make wget libgd2-xpm-dev libperl-dev libssl-dev daemon
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
cd /tmp
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
tar -xvzf nagios-4.0.8.tar.gz
cd nagios-4.0.8
sudo ./configure --with-command-group=nagcmd --with-httpd-conf=/etc/apache2/conf-enabled

sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo sudo make install-commandmode
sudo make install-webconf
sudo cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/
sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
sudo nano /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

I haven’t finished it yet….

sudo a2enmod rewrite
sudo a2enmod cgi
sudo service apache2 restart
sudo service nagios start
sudo chmod 666 /usr/local/nagios/var/rw/nagios.cmd
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

Install Nagios Plugins on Nagios server

cd /tmp
wget http://www.nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
tar -xvzf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3/
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install 

Now you can get access to the Nagios Server dashboard using http://SERVER-IP-ADDRESS/nagios