Reference 1: Nagios and Nginx on Ubuntu 12.04 LTS
Reference 2: Ubuntu quickstart guide to installing Nagios.
Development files and packages
libssl-dev
is the development files needed for compiling Nagios plugins. Without this you will encounter errors while compiling Nagios plugins.
sudo apt-get install apache2 libapache2-mod-php5 \ build-essential libssl-dev libgd2-xpm-dev -y
Create user and group
Create user and group for nagios, also create another group for external command executed via nagios.
Create a user nagios and disable nagios from gaining shell access by assigning nagios to /bin/false
shell. nagios will also never be able to login to the Ubuntu linux shell.
sudo useradd -m -s /bin/false nagios sudo groupadd nagios sudo usermod -G nagios nagios sudo groupadd nagcmd sudo usermod -a -G nagcmd www-data sudo usermod -a -G nagcmd nagios
Verify:
cyruslab@Nachos:/$ cat /etc/group | grep nagios nagios:x:1001:nagios nagcmd:x:1002:www-data,nagios cyruslab@Nachos:/$
To remove a user from a group use the gpasswd
command, example gpasswd -d www-data nagcmd
removes www-data
user from nagcmd
group.
Download nagios and plugins
cyruslab@Nachos:/bin$ cd /tmp/ cyruslab@Nachos:/tmp$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz cyruslab@Nachos:/tmp$ wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
Untar and unzip the files:
cyruslab@Nachos:/tmp$ tar -zxvf nagios-3.4.1.tar.gz cyruslab@Nachos:/tmp$ tar -xzvf nagios-plugins-1.4.16.tar.gz
Compile and install
Configure the source code:
cyruslab@Nachos:/tmp/nagios$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios \ > --with-command-user=nagios --with-command-group=nagcmd --sysconfdir=/etc/nagios
Compile the source code locally and install the compiled code:
cyruslab@Nachos:/tmp/nagios$ make all && sudo make install
Installs the init scripts to /etc/init.d
cyruslab@Nachos:/tmp/nagios$ sudo make install-init
Installs and configures permissions on the directory for holding the external command file.
cyruslab@Nachos:/tmp/nagios$ sudo make install-commandmode
Installs sample config files in /etc/nagios
cyruslab@Nachos:/tmp/nagios$ sudo make install-config
Install nagios web config file to apache2
cyruslab@Nachos:/tmp/nagios$ sudo make install-webconf
Customize the username authorized to access nagios
cyruslab@Nachos:/tmp/nagios$ cd /etc/nagios/ cyruslab@Nachos:/etc/nagios$ sudo nano cgi.cfg
Change these parameters all to any username you like to access, for me I changed all the parameters from nagiosadmin to admin or just add admin with a comma after nagiosadmin:
1. authorized_for_system_information
2. authorized_for_configuration_information
3. authorized_for_system_commands
4. authorized_for_all_service_commands
5. authorized_for_all_host_commands
This step is not necessary however i felt nagiosadmin is a bit long for username.
#It is not necessary to create htpasswd.users yourself, htpasswd will create the file. cyruslab@Nachos:~$ sudo htpasswd -c /etc/nagios/htpasswd.users admin New password: Re-type new password: Adding password for user admin cyruslab@Nachos:~$
Configure nagios-plugins source code, compile and install:
cyruslab@Nachos:/tmp/nagios$ cd ../nagios cyruslab@Nachos:/tmp/nagios-plugins-1.4.16$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios cyruslab@Nachos:/tmp/nagios-plugins-1.4.16$ make && sudo make install
To start nagios automatically everytime system boot
Create symbolic link:
cyruslab@Nachos:/tmp/nagios-plugins-1.4.16$ sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
Verify nagios config
cyruslab@Nachos:/tmp/nagios-plugins-1.4.16$ sudo /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg Nagios Core 3.4.1 Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 05-11-2012 License: GPL Website: http://www.nagios.org Reading configuration data... Read main config file okay... Processing object config file '/etc/nagios/objects/commands.cfg'... Processing object config file '/etc/nagios/objects/contacts.cfg'... Processing object config file '/etc/nagios/objects/timeperiods.cfg'... Processing object config file '/etc/nagios/objects/templates.cfg'... Processing object config file '/etc/nagios/objects/localhost.cfg'... Read object config files okay... Running pre-flight check on configuration data... Checking services... Checked 8 services. Checking hosts... Checked 1 hosts. Checking host groups... Checked 1 host groups. Checking service groups... Checked 0 service groups. Checking contacts... Checked 1 contacts. Checking contact groups... Checked 1 contact groups. Checking service escalations... Checked 0 service escalations. Checking service dependencies... Checked 0 service dependencies. Checking host escalations... Checked 0 host escalations. Checking host dependencies... Checked 0 host dependencies. Checking commands... Checked 24 commands. Checking time periods... Checked 5 time periods. Checking for circular paths between hosts... Checking for circular host and service dependencies... Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check cyruslab@Nachos:/tmp/nagios-plugins-1.4.16$
Start the services
Start nagios and apache2:
sudo service nagios start sudo service apache2 start
500 internal server error
If you encounter the 500 internal server error it could be because the htpasswd.users
is not located, check nagios.cfg
to see if the htpasswd path is the same you have provided using the htpasswd -c
command.