1- Install LAMP on Ubuntu

follow previous already done instructions to install LAMP on Ubuntu

2- Install Prerequisites

$ sudo apt-get install build-essential libgd2-xpm-dev apache2-utils

3- Create Nagios User and Group

$ sudo useradd -m nagios
$ sudo passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface.

Add both the nagios user and the apache user to the group.

$ sudo groupadd nagcmd
$ sudo usermod -a -G nagcmd nagios
$ sudo usermod -a -G nagcmd www-data

4- Downlaod Nagios and Plugins

go to opt folder

$ cd /opt/

download nagios

$ sudo wget

download plugins

$ sudo wget

check out if nagios and plugins are saved

$ ls -l
-rw-r–r– 1 root root 1805059 Aug 12 2014 nagios-4.0.8.tar.gz
-rw-r–r– 1 root root 2659772 Jun 26 2014 nagios-plugins-2.0.3.tar.gz

5- Install Nagios

Extract tar file

$ sudo tar xzf nagios-4.0.8.tar.gz

change the directory to nagios and begin to install

$ cd nagios-4.0.8/
$ sudo ./configure –with-command-group=nagcmd
$ sudo make all
$ sudo make install
$ sudo make install-init
$ sudo make install-config
$ sudo make install-commandmode

6- Install Nagios Web Interface

Let’s continue to install Nagios Web Interface

$ sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf

check if nagios.conf is placed in /etc/apache2/sites-enabled

$ sudo ls -l /etc/apache2/sites-enabled/
lrwxrwxrwx 1 root root 35 Jun 29 09:43 000-default.conf -> ../sites-available/000-default.conf
-rw-r–r– 1 root root 982 Jun 29 13:13 nagios.conf

giving nagisadmin (username) and Memo3480$ (password) for nagios web interface

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart apache2

$ sudo service apache2 restart

7- Install Nagios Plugins

Go back to /opt folder where nagios plugins is downloaded

$ cd /opt/

extract tar file

$ sudo tar xzf nagios-plugins-2.0.3.tar.gz

change the directory to nagios plugins and begin to install

$ cd nagios-plugins-2.0.3
$ sudo ./configure –with-nagios-user=nagios –with-nagios-group=nagios
$ sudo make
$ sudo make install

8- Configure Nagios

Nagios sample configuration files have now been installed in the /usr/local/nagios/etc directory, change email to get alerts

$ sudo vi /usr/local/nagios/etc/objects/contacts.cfg

Edit nagios.conf file and put ips if you want to access nagios from particular ip series

$ sudo vi /etc/apache2/sites-enabled/nagios.conf

 ## Comment the following lines ##
 # Order allow,deny
 # Allow from all
## Uncomment and Change lines as shown below ##
 Order deny,allow
 Deny from all
 Allow from

we didn’t put any ip above

Enable Apache’s rewrite and cgi modules:

$ sudo a2enmod rewrite
$ sudo a2enmod cgi
$ sudo service apache2 restart

check nagios.conf file for any syntax errors:

$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start nagios service and make it to start automatically on every boot.

$ sudo service nagios start
$ sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

9- Enter Nagios Web

Go to http://X.X.X.X/nagios/

Click Hosts on the left menu. You will see there the no of hosts to be monitored by Nagios server. We haven’t added any hosts yet. So it simply monitors the localhost itself only.

10- Configure Nagios Clients

Let’s install it under a test server –

$ sudo apt-get install nagios-nrpe-server nagios-plugins
$ sudo vi /etc/nagios/nrpe.cfg

Add your Nagios server ip address (X.X.X.X):

 ## Find the following line and add the Nagios server IP ##
 allowed_hosts= X.X.X.X

Start nrpe service on Ubuntu/Debian clients:

$ sudo /etc/init.d/nagios-nrpe-server restart

11- Add Client in Nagios Server Configuration

Now, go back to your Nagios server (X.X.X.X)

$ sudo vi /usr/local/nagios/etc/nagios.cfg

and uncomment the following lines.

## Find and uncomment the following line ##

Create a directory called “servers” under “/usr/local/nagios/etc/”.

$ sudo mkdir /usr/local/nagios/etc/servers

Create config file to the client to be monitored

$ sudo vi /usr/local/nagios/etc/servers/moodle.cfg

Add the following lines:

define host{
use                             linux-server
host_name                       natest
alias                           Moodle-Prod-Server
max_check_attempts              5
check_period                    24x7
notification_interval           30
notification_period             24x7

Here, is moodle nagios client IP address. Finally restart nagios service.
Please add public ip if you need

$ sudo service nagios restart

Go back to site and check it out from Hosts
You will see the latest

Similarly, you can define more clients by creating a separate config files “/usr/local/nagios/etc/servers” directory for each client.

To add a service go back to latest.cfg file

$ sudo vi /usr/local/nagios/etc/servers/moodle.cfg

Add ssh service below define host and then ping service

define service {
        use                             generic-service
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0

define service {
        use                             generic-service
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%

$ sudo service nagios restart


$ sudo service nagios reload

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s