Nagios is an awesome Open
Source monitoring
tool, its provides you more comprehensive monitoring environment to always keep
an eye on your all machines / networks whether you are in your data center or just your small labs.
With Nagios,
you can monitor your remote hosts and their services remotely on a single
window. It shows warnings and indicates if something goes wrong in your servers which eventually helps us to detect
some problems before they occur. It helps us to reduce downtime and business
losses.
This tutorial explains
how to install and configure the Nagios tool on Linux. I am using RHEL 5.8 for installation
Nagios.
Before installation
of Nagios some prerequisites are required to resolve the dependencies of
Nagios.
1.
Install required
dependencies:
During portions of the
installation you'll need to have root access to your machine.
Make sure you've installed the
following packages on your RHEL5.8 installation before continuing installation
of Nagios 4.0.1.
- Apache
- PHP
- GCC
compiler
- GD development libraries
You can use yum default package installer to
install these packages by running the following commands (as root):
[root@RHEL5 ~]#yum install httpd php
[root@RHEL5 ~]#yum install gcc glibc glibc-common
[root@RHEL5 ~]#yum install gd gd-devel
[root@RHEL5 ~]#yum install make net-snmp
2.
Create Nagios user and Group:
[root@RHEL5 ~]# useradd nagios
[root@RHEL5 ~]# passwd nagios
Changing password for user nagios.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated
successfully.
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.
[root@RHEL5 ~]# groupadd nagcmd
[root@RHEL5 ~]# /usr/sbin/usermod -a -G nagcmd
nagios
[root@RHEL5 ~]# /usr/sbin/usermod -a -G nagcmd
apache
3.
Download Nagios Core
4.0.1 and Nagios Plugin 1.5
Create a directory for your Nagios installation and all its future
downloads.
[root@RHEL5
~]# mkdir /root/downloads
[root@RHEL5
~]# cd /root/downloads
Now download latest Nagios
Core 4.0.1 and Nagios plugins 1.5 packages with wget command.
[root@RHEL5
downloads]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
[root@RHEL5
downloads]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
4.
Extract Nagios Core
and its Plugins:
We
need to extract the downloaded packages with tar command.
[root@RHEL5
downloads]# tar -xzvf nagios-4.0.1.tar.gz
[root@RHEL5
downloads]# tar -xzvf nagios-plugins-1.5.tar.gz
When you extract
these tarballs with tar command, two new folders will appear in that directory.
[root@RHEL5
downloads]# ls -ltr
total
4060
drwxr-xr-x
15 root root 4096 Oct
2 20:57 nagios-plugins-1.5
drwxrwxr-x
18 root root 4096 Oct 16 05:06 nagios-4.0.1
-rw-r--r-- 1
root root 1695367 Oct 16 05:19 nagios-4.0.1.tar.gz
-rw-r--r-- 1 root root 2428258 Jan 16 2014 nagios-plugins-1.5.tar.gz
5.
Configure Nagios
Core:
i) Now, first we will configure Nagios
Core and
to do so we need to go to Nagios directory and run configure file and if everything goes fine, it will
show the output in the end as sample output. Please see below
[root@RHEL5
downloads]# cd nagios-4.0.1
[root@RHEL5
nagios-4.0.1]# ./configure --with-command-group=nagcmd
Sample Output:
***
Configuration summary for nagios 4.0.1 10-15-2013 ***:
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Review
the options above for accuracy. If they
look okay,
type
'make all' to compile the main program and CGIs.
ii)
Now, after configuring we need to Compile and install all
the binaries with make command
and make install command will install all the needed libraries in your
machine and we can proceed further.
[root@RHEL5
nagios-4.0.1]# make all
[root@RHEL5
nagios-4.0.1]# make install
Sample Output:
***
Main program, CGIs and HTML files installed ***
You
can continue with installing Nagios as follows (type 'make'
without
any arguments for a list of all possible options):
make install-init
- This installs the init script in
/etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions
on the
directory for holding the external
command file
make install-config
- This installs sample config files in
/usr/local/nagios/etc
make[1]:
Leaving directory `/root/downloads/nagios-4.0.1'
iii)
Following command will install the init
scripts for Nagios.
[root@RHEL5
nagios-4.0.1]# make install-init
/usr/bin/install
-c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install
-c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
***
Init script installed ***
iv)
To make nagios work from command line we
need to install command-mode.
[root@RHEL5
nagios-4.0.1]# make install-commandmode
/usr/bin/install
-c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod
g+s /usr/local/nagios/var/rw
***
External command directory configured ***
v)
Next, install sample nagios files, please
run following command.
[root@RHEL5
nagios-4.0.1]# make install-config
6.
Customizing Nagios
Configuration:
Open the “contacts.cfg” file with your
choice of editor and set the email address associated with the nagiosadmin
contact definition to receiving email alerts.
[root@RHEL5
~]# vi /usr/local/nagios/etc/objects/contacts.cfg
##############################################################################
CONTACTS
##############################################################################
#
Just one contact defined by default - the Nagios admin (that's you)
#
This contact definition inherits a lot of default values from the
'generic-contact'
#
template which is defined elsewhere.
define
contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ;
Inherit default values from generic-contact template (defined above)
alias Nagios
Admin ; Full name of user
email jitendrakumaryogi@gmail.com ;
<<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
7.
Install and configure
Web Interface for Nagios:
We are done with all configuration in the
backend, now we will configure Web Interface for Nagios with following command.
The below command will Configure Web interface for Nagios and a web admin user
will be created “nagiosadmin”.
[root@RHEL5
nagios-4.0.1]# make install-webconf
/usr/bin/install -c
-m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
*** Nagios/Apache
conf file installed ***
In this step, we will be creating a
password for “nagiosadmin”. After executing
this command, please provide a password twice and keep it remember because this password will
be used when you login in the Nagios Web interface.
[root@RHEL5
nagios-4.0.1]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache to make the new settings take effect.
[root@RHEL5
nagios-4.0.1]# service httpd restart
Stopping
httpd:
[ OK ]
Starting
httpd:
[ OK ]
8.
Compile and Install
Nagios Plugin:
We have downloaded nagios plugins in /root/downloads,
Go there and configure and install it as directed below.
[root@RHEL5
nagios-4.0.1]# cd /root/downloads/
[root@RHEL5
downloads]# cd nagios-plugins-1.5
[root@RHEL5
nagios-plugins-1.5]#./configure --with-nagios-user=nagios
--with-nagios-group=nagios
[root@RHEL5
nagios-plugins-1.5]# make
[root@RHEL5
nagios-plugins-1.5]# make install
9.
Verify Nagios
configuration file:
Now we are all done with Nagios
configuration and its time to verify it and to do so please insert
following command. If everything goes smooth it will show up similar to below
output.
[root@RHEL5
nagios-plugins-1.5]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg
10. Add Nagios Services
to System Startup:
To make Nagios work across reboots, we
need to add nagios and https with chkconfig command.
[root@RHEL5
nagios-plugins-1.5]# chkconfig --add nagios
[root@RHEL5
nagios-plugins-1.5]# chkconfig --level 35 nagios on
[root@RHEL5
nagios-plugins-1.5]# chkconfig --add
httpd
[root@RHEL5
nagios-plugins-1.5]# chkconfig --level 35 httpd on
Restart Nagios to make the new settings take effect.
[root@RHEL5
nagios-plugins-1.5]# service nagios start
nagios is stopped
Starting
nagios:
[ OK ]
11. Modify SELinux Settings:
RedHat
ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by
default. This can result in "Internal Server Error" messages when you
attempt to access the Nagios CGIs. See if SELinux is in Enforcing mode.
[root@RHEL5 nagios-4.0.1]# getenforce
Put SELinux into
Permissive mode.
[root@RHEL5 nagios-4.0.1]# setenforce 0
To make this change
permanent, you'll have to modify the settings in /etc/selinux/config and
reboot.
Instead of disabling SELinux or
setting it to permissive mode, you can use the following command to run the
CGIs under SELinux enforcing/targeted mode:
[root@RHEL5
nagios-4.0.1]# chcon -R -t httpd_sys_content_t
/usr/local/nagios/sbin/
[root@RHEL5
nagios-4.0.1]# chcon -R -t httpd_sys_content_t
/usr/local/nagios/share/
12.
Login to Nagios Web Interface:
Your nagios is ready to work, please open
it in your browser with “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and provide the username “nagiosadmin” and password.
Nagios Login
Hi Jitendra
ReplyDeleteYour articles are so helpful for all and thank you.
Can you please help me how to enable nagios core 4.0.1 email alerts in rhel6?
thank u jithendra.... :)
ReplyDeleteThank you jithendra,
ReplyDeleteCan you please write configuration steps to add hosts and mount mounts.
Hi Jithendra,
ReplyDeleteVerry good document and i have configured nagios however could you please write
- How to confgure nrpe
- How to add hosts and service in customized way
thank you
ReplyDeletei had follow each step . but i am not able access nagios through web page
ReplyDeleteWhat error you get?
Deletei am also unable to access nagios through we getting error 403.please help me what need to be done plz mail to mohankamalesh@gmail.com
Deleteerror message :
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
Hey! Thank you for the Document. I have followed same step and installed the Nagios. the web page is opened with error "Not running" and if I browse Hosts getting error "Error: Could not read object configuration data!" could you please help me!
ReplyDeleteMy Mail ID: is ramut123@gmail.com
excellent blog
ReplyDeleteHi Jitendra can you plz upload a video about Nagios.
ReplyDeleteHi Jitendra can you plz upload a video about Nagios.
ReplyDeleteHi Jitendra can you plz upload a video about Nagios.
ReplyDeleteit is very nice tutorial for me.
ReplyDeletei am facing below issue.
Nagios install successfully
but i am unable to access it by http
page can not disply
i am also unable to access nagios through we getting error 403.please help me what need to be done plz mail to mohankamalesh@gmail.com
ReplyDeleteerror message :
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
its very good step. Also provide me how can add another host for monitor
ReplyDeletethankyou buddy
ReplyDeletehi i was configured that but i want alters in mob no. how i can add nos in that
ReplyDelete
ReplyDeleteThank you for sharing this Information.
I also found Various useful links related to Devops, Docker & Kubernetes
Kubernetes Kubectl Commands CheatSheet
Introduction to Kubernetes Networking
Basic Concept of Kubernetes
Kubernetes Interview Question and Answers
Kubernetes Sheetsheat
Docker Basic Tutorial
Linux Sar Command Tutorial
Linux Interview Questions and Answers
Docker Interview Question and Answers
OpenStack Interview Questions and Answers