Home » Categories » Multiple Categories

How To Install Nagios On Ubuntu 12.10

Step 1 - Spin up Ubuntu 12.10 x64 and add SWAP memory

To add 2GB of SWAP memory:

dd if=/dev/zero of=/swap bs=1024 count=2097152
mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swap
echo /swap swap swap defaults 0 0 >> /etc/fstab
echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p

Step 2 - Install Packages on Monitoring Server

apt-get install -y nagios3 nagios-nrpe-plugin
usermod -a -G nagios www-data
chmod -R g+x /var/lib/nagios3/
sed -i 's/check_external_commands=0/check_external_commands=1/g' /etc/nagios3/nagios.cfg

You will be prompted for MySQL root password, we chose "PassWord", you should change it to something stronger.

Step 3 - Set Password Protection

Set Nagios Admin Panel Password:
htpasswd -c /etc/nagios3/htpasswd.users nagiosadmin
service nagios3 restart && service apache2 restart

Make sure to keep this username as "nagiosadmin" - otherwise you would have to change /etc/nagios3/cgi.cfg and redefine authorized admin.

Now you can navigate over to your Nagios panel at http://IP/nagios3 ( for our example): You will be prompted to enter your password, which you've specified in Step 3.

As you can see, we don't have any hosts currently being monitored, so lets set that up next.

Step 4 - Install NRPE on Clients

Now we should add our hosts that will be monitored by Nagios. For example, we will setup monitoring for cloudads.tk (, which runs Ubuntu 12.10 as well.

From public ports, we can monitor ping, any open ports such as webserver, e-mail server, etc.

For internal services that are listening on localhost, such as MySQL, memcached, system services, we will need to use NRPE.

Step 4 - Install NRPE on Client

apt-get install -y nagios-plugins nagios-nrpe-server

This next step is where you get to specify any manual commands that Monitoring server can send via NRPE to these client hosts.

Make sure to change allowed_hosts to your own values.

Edit /etc/nagios/nrpe.cfg


command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/vda
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200


In check_disk above, the partition being checked is /dev/vda - make sure your panel has the same partition by running df -h /

You can also modify when to trigger warnings or critical alerts - above configuration sets Warning at 20% free disk space remaining, and Critical alert at 10% free space remaining.

We should also setup firewall rules to allow connections from our Monitoring server to those clients and drop everyone else:

iptables -N NRPE
iptables -I INPUT -s 0/0 -p tcp --dport 5666 -j NRPE
iptables -I NRPE -s -j ACCEPT
iptables -A NRPE -s 0/0 -j DROP

Now you can start NRPE on your client host:
service nagios-nrpe-server restart

Step 5 - Add Server Configurations on Monitoring Server

Back on our Monitoring server, we will have to create config files for each of our client servers:
All configs can be stored in /etc/nagios3/conf.d in individual .cfgfiles (for example: /etc/nagios3/conf.d/cloudads.tk.cfg)

Edit /etc/nagios3/conf.d/cloudads.tk.cfg and add the following lines:

define host {
        use                     generic-host
        host_name               cloudads.tk
        alias                   cloudads.tk

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

define service {
        use                             generic-service
        host_name                       cloudads.tk
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0

define service {
        use                             generic-service
        host_name                       cloudads.tk
        service_description             Current Load
        check_command                   check_load!5.0!4.0!3.0!10.0!6.0!4.0

After you are done editing your config files, make sure to restart Nagios for changes to take effect:

service nagios3 restart

You can add more services to be monitored as desired, and even create your own Nagios plugins.

Step 6 - Monitor Hosts in Nagios

Navigate over to your Monitoring Server's IP address http://IP/nagios and enter password set in Step 2.

Now you should be able to see all the hosts and services.

And you are all done!
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
How to Setup a Multi-Protocol VPN Server Using SoftEther
Viewed 4072 times since Thu, Jan 2, 2014
How To Install Z Shell (zsh) on a Cloud Server
Viewed 1557 times since Fri, Dec 27, 2013
How To Create Nagios Plugins With Ruby On CentOS 6
Viewed 1425 times since Sat, Jan 4, 2014
How To Set Up vsftpd on Ubuntu 12.04
Viewed 1334 times since Thu, Dec 26, 2013
How To Install Nagios On CentOS 6
Viewed 2115 times since Sat, Jan 4, 2014
How To Install Git on Ubuntu 12.04
Viewed 2311 times since Mon, Dec 23, 2013
How To Install Rails, Apache, and MySQL on Ubuntu with Passenger
Viewed 2261 times since Mon, Dec 23, 2013
How To Use ps, kill, and nice to Manage Processes in Linux
Viewed 1719 times since Thu, Dec 26, 2013
How To Use SFTP to Securely Transfer Files with a Remote Server
Viewed 1970 times since Thu, Dec 26, 2013