In this tutorial we will install and configure nagios core 4 on Ubuntu 12.04 LTS. Nagios Core 4 has recently been released,at the time of writing this post Nagios core 4.0.2 was available.
Nagios is one of the most popular,reliable and robust Monitoring System.You can find number of plugins to monitor the network and server resources.
Best thing is Nagios Core is open source.You can modify the monitoring system as per your requirement.You can also create your own nagios plugins.We suggest you to submit your Nagios related contribution in exchange.nagios.org
Nagios team has added lots of new feature in Nagios Core 4.x Version over last version.To read about new feature in Nagios Core 4.x here is the referral link .
We also suggest you to read about version history(Referral link : Nagios core 4.x Version history)
Install and configure Nagios Core 4 in Ubuntu
We are doing this practical in Ubuntu 12.04 LTS. Given below are the brief description of our specs
Operating System : Ubuntu 12.04 LTS (x86_64)
Package Name : Nagios Core 4.0.2
Apache Version : 2.2.22-1ubuntu1.4
IP Address of Nagios Server : 192.168.56.101
Note: The practical has been performed in Freshly installed Ubuntu 12.04 LTS
Follow the given below steps to install and configure Nagios core 4.x in Ubuntu
Step 1 : Login in Server and become super user. Now install dependencies require for Nagios core 4 version
sudo su - apt-get update apt-get install wget build-essential apache2 php5 openssl perl make php5-gd wget libgd2-xpm libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev daemon
Step 2 : Download the Nagios core 4 package
Step 3 : Now untar the downloaded nagios package
tar -xvzf nagios-4.0.2.tar.gz
Step 4 : Create user nagios and group nagcmd. Add the nagios user in supplementry group nagcmd
useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios
Step 5 : Compile and install nagios
cd nagios-4.0.2/ ./configure --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode make install-webconf
Step 6 : Copy eventhandlers directory into nagios base directory . Change the owner and group to nagios
cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/ chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Step 7 : Set nagiosadmin user password.It is a default user for Nagios dashboard administration .
Give the password for nagiosadmin and we will use it in Nagios Dashboard
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Step 8 : Enable the rewrite apache module.Restart the apache after this.
a2enmod rewrite /etc/init.d/apache2 restart
Step 9 : Starting the Nagios . We found problem while starting the nagios.Hence we will create service init script for nagios to start/stop the nagios service
Note: As per new nagios, the init script for nagios has problem with functions of Ubuntu/Debian system.
Below given is the error ,which we have found while running the command /etc/init.d/nagios start
Create a new file in /etc/init with name called nagios.conf
For service init script,we have taken reference from ssh.conf and rsyslog.conf file (path is /etc/init/ssh.conf and /etc/init/rsyslog.conf)
vi /etc/init/nagios.conf ## paste the below given content in /etc/init/nagios.conf # nagios4 init script ### use command 'service nagios start|stop|restart' 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
Step 10 : Now start the nagios service
service nagios start
Note 1: To stop the Nagios service
service nagios stop
Note 2: To check the status of Nagios service
service nagios status
Step 11 : There is one more problem i.e with eventhandlers found in Ubuntu.(See in this referral link)To fix this issue ,run below given command
chmod 666 /usr/local/nagios/var/rw/nagios.cmd
Step 12 : After starting nagios service.Open the web browser and type the URL appended with /nagios
(Replace the 192.168.56.101 with your server ip address or domain name)
When you click on Services tab in Nagios Dashboard,you may see lots of Red area which means plugin is not installed.. For this we will install Nagios plugins.
Install and configure Nagios plugin in Nagios Server
Now we will install nagios plugins in Nagios server for local alert check .
Step 13 : Download the nagios plugins in Nagios Server
cd ~ wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
Step 14: Untar the compressesed nagios-plugins-1.5.tar.gz file
tar -xvzf nagios-plugins-1.5.tar.gz
Step 15 : Change to extracted nagios-pligins directory and install the plugins
cd nagios-plugins-1.5 ./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install
Step 16 : Wait for a minimum 90 Seconds.The dashboard will be updated and all checks will be active. You can notice all Red colors change to Green colors
Note : Rather then waiting, you can reschedule the check in nagios.
Click on any Service for eg. “Current Load” . Now see at right hand side. There is a link called “Re-schedule the next check of this service“. Click on it, and after giving reschedule time,click ok. The Nagios Server will check and update the information in new re-schedule time.
Below is the reference screenshot of “Service Commands” section