Wednesday 13 April 2016

How to install nagios-4.43 in Ubuntu 18.04 LTS, 16.04 LTS, and 14.04 LTS and Debian systems

Step 01 : Install the required packages

Make sure you have installed the following packages on your Ubuntu system before continuing.
Apache 2
PHP
GCC compiler and development libraries
GD development libraries

If you did not install then please run the following commands:

sudo apt-get update
sudo apt-get install wget build-essential unzip openssl libssl-dev
sudo apt-get install apache2 php libapache2-mod-php php-gd libgd-dev
Need personal assistance on Nagios? Please contact me at

immukesh72@gmail.com

at very nominal charges

Step 02 Create Account Information for nagios user

Create a new nagios user account and give it a password.
sudo adduser 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 or /usr/sbin/groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data

Step 03 Download and install Nagios core service

Create a directory for storing the downloads.

mkdir ~/downloads
cd ~/downloads

Download the source code for both Nagios core by following commands.

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.3.tar.gz
tar xzf nagios-4.4.3.tar.gz

After extracting cd to nagios-4.4.3 directory and install using configure and make command.
cd nagios-4.4.3

sudo ./configure --with-command-group=nagcmd
sudo make all
sudo make install
sudo make install-init
sudo make install-daemoninit
sudo make install-config
sudo make install-commandmode
sudo make install-exfoliation

Now copy event handlers scripts under libexec directory. These binaries provides multiple events triggers for your Nagios web interface.
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Step 04: Setup Apache with Authentication

create an Apache configuration file for your Nagios server as below:

sudo vi /etc/apache2/conf-available/nagios.conf
Paste the following content in nagios.cfg and save
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"


  Options ExecCGI
  AllowOverride None
  Order allow,deny
  Allow from all
  AuthName "Restricted Area"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users
  Require valid-user


Alias /nagios "/usr/local/nagios/share"


  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
  AuthName "Restricted Area"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users
  Require valid-user

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you will need it later.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Now enable Apache configuration and restart Apache service to make the new settings take effect.

sudo a2enconf nagios
sudo a2enmod cgi rewrite
sudo service apache2 restart (or) /etc/init.d/apache2 reload

Step 5 – Installing Nagios Plugins

Download and extract the Nagios source code from tar as following.
tar -zxvf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1

sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
sudo make
sudo make install

Step 06: Verify settings

Use the Nagios commands to verify the Nagios installation and configuration setting.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
You should get following output at end.
Total Warnings: 0
Total Errors: 0

Start nagios service
service nagios start

Also configure Nagios to auto start on system boot.
sudo systemctl enable nagios

Step 7 – Access Nagios Web Interface

Enter the following url into the browser , it will ask to enter username and password. In this configuration we have username as nagiosadmin and password also as nagios admin.
http://localhost/nagios/
or
http://Ip_addreess_of_nagios_server/nagios/
Step 8 Customize Configuration

Sample configuration files have now been installed in its default location /usr/local/nagios/etc directory. Before procceding ahead edit the /usr/local/nagios/etc/objects/contacts.cfg file to place your email address.
Email address should be associated with nagiosadmin contact definition on which you would like to receive email alerts.

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






Step 9 Other Modifications


If you want to receive email notifications for Nagios alerts, you need to install the mailx (Postfix) package.

sudo apt-get install mailx
sudo apt-get install postfix

You'll have to edit the Nagios email notification commands found in /usr/local/nagios/etc/objects/commands.cfg and change any '/bin/mail' references to '/usr/bin/mail'. Once you do that you'll need to restart Nagios to make the configuration changes live.

sudo /etc/init.d/nagios restart
Need personal assistance on Nagios? Please contact me at

immukesh72@gmail.com

at very nominal charges

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...