How to install Nagios in Linux
Installation of Nagios in Linux
Nagios is an Open Source monitoring tool that track on system/network. It monitors your remote hosts and services on a single window. It detects the problems in the server and their by reduces downtime and losses. Installation of Nagios is explained in this article.
To Install Nagios 4.0.1 and Nagios Plugin 1.5
Before installing Nagios, install the dependency packages.
[root@linuxhelp1 ~]# yum install httpd php gcc glibc glibc-common gd gd-devel make net-snmp -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Determining fastest mirrors
* base: centos.mirror.net.in
* extras: centos.mirror.net.in
* updates: centos.mirror.net.in
Package httpd-2.2.15-53.el6.centos.x86_64 already installed and latest version
Package glibc-2.12-1.192.el6.x86_64 already installed and latest version
Package glibc-common-2.12-1.192.el6.x86_64 already installed and latest version
Package 1:make-3.81-23.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-17.el6 will be installed
--> Processing Dependency: cpp = 4.4.7-17.el6 for package: gcc-4.4.7-17.el6.x86_64
--> Processing Dependency: cloog-ppl > = 0.15 for package: gcc-4.4.7-17.el6.x86_64
.
.
.
Installed:
gcc.x86_64 0:4.4.7-17.el6 gd.x86_64 0:2.0.35-11.el6 gd-devel.x86_64 0:2.0.35-11.el6 net-snmp.x86_64 1:5.5-57.el6
php.x86_64 0:5.3.3-47.el6
Dependency Installed:
cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-17.el6
fontconfig-devel.x86_64 0:2.8.0-5.el6 freetype-devel.x86_64 0:2.3.11-17.el6
libX11-devel.x86_64 0:1.6.3-2.el6 libXau-devel.x86_64 0:1.0.6-4.el6
libXpm.x86_64 0:3.5.10-2.el6 libXpm-devel.x86_64 0:3.5.10-2.el6
libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5 libpng-devel.x86_64 2:1.2.49-2.el6_7
libxcb-devel.x86_64 0:1.11-2.el6 mpfr.x86_64 0:2.4.1-6.el6
php-cli.x86_64 0:5.3.3-47.el6 php-common.x86_64 0:5.3.3-47.el6
ppl.x86_64 0:0.10.2-11.el6 xorg-x11-proto-devel.noarch 0:7.7-13.el6
zlib-devel.x86_64 0:1.2.3-29.el6
Complete!
To create a Nagios User and Group
Create a new nagios user and nagcmd group account and also set a password.
[root@linuxhelp1 ~]# useradd nagios [root@linuxhelp1 ~]# passwd nagios Changing password for user nagios. New password: BAD PASSWORD: it is based on a dictionary word BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully.
[root@linuxhelp1 ~]# groupadd nagcmd
You need to add both the nagios user and the apache user to the nagcmd group.
[root@linuxhelp1 ~]# usermod -G nagcmd nagios
[root@linuxhelp1 ~]# usermod -G nagcmd apache
Create a directory, to install Nagios.
[root@linuxhelp1 ~]# mkdir /root/nagios
[root@linuxhelp1 ~]# cd /root/nagios
Download the latest version of Nagios and Nagios plugin packages.
[root@linuxhelp1 nagios]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
--2016-07-01 17:46:23-- http://heanet.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.1/nagios-4.0.1.tar.gz
Resolving heanet.dl.sourceforge.net... 193.1.193.66, 2001:770:18:aa40::c101:c142
Connecting to heanet.dl.sourceforge.net|193.1.193.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1695367 (1.6M) [application/x-gzip]
Saving to: “ nagios-4.0.1.tar.gz”
100%[======================================> ] 1,695,367 566K/s in 2.9s
2016-07-01 17:46:26 (566 KB/s) - “ nagios-4.0.1.tar.gz” saved [1695367/1695367]
[root@linuxhelp1 nagios]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
--2016-07-01 17:47:36-- https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
Resolving www.nagios-plugins.org... 72.14.186.43
Connecting to www.nagios-plugins.org|72.14.186.43|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2428258 (2.3M) [application/x-gzip]
Saving to: “ nagios-plugins-1.5.tar.gz”
100%[======================================> ] 2,428,258 510K/s in 4.7s
2016-07-01 17:47:42 (510 KB/s) - “ nagios-plugins-1.5.tar.gz” saved [2428258/2428258]
Extract the downloaded package by using the tar command.
[root@linuxhelp1 nagios]# tar -xvf nagios-4.0.1.tar.gz
nagios-4.0.1/
nagios-4.0.1/.gitignore
nagios-4.0.1/Changelog
nagios-4.0.1/INSTALLING
nagios-4.0.1/LEGAL
.
.
.
nagios-4.0.1/xdata/xrddefault.c
nagios-4.0.1/xdata/xrddefault.h
nagios-4.0.1/xdata/xsddefault.c
nagios-4.0.1/xdata/xsddefault.h
[root@linuxhelp1 nagios]# tar -xvf nagios-plugins-1.5.tar.gz
nagios-plugins-1.5/
nagios-plugins-1.5/release
nagios-plugins-1.5/po/
nagios-plugins-1.5/po/LINGUAS
.
.
.
nagios-plugins-1.5/build-aux/config.sub
nagios-plugins-1.5/build-aux/config.rpath
nagios-plugins-1.5/build-aux/config.guess
nagios-plugins-1.5/build-aux/compile
To configure Nagios Core
To Configure Nagios Core, execute the following command.
[root@linuxhelp1 nagios]# cd nagios-4.0.1 [root@linuxhelp1 nagios-4.0.1]# ./configure --with-command-group=nagcmd checking for a BSD-compatible install... /usr/bin/install -c checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out . . . Web Interface Options: ------------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): /bin/traceroute
Compile and install all the binaries by using make all and make install command.
[root@linuxhelp1 nagios-4.0.1]# make all
cd ./base & & make
make[1]: Entering directory `/root/nagios/nagios-4.0.1/base'
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o broker.o broker.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nebmods.o nebmods.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o ../common/shared.o ../common/shared.c .
.
.
before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you. This might include:
- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:
http://support.nagios.com
*************************************************************
Enjoy.
[root@linuxhelp1 nagios-4.0.1]# make install
cd ./base & & make install
make[1]: Entering directory `/root/nagios/nagios-4.0.1/base'
make install-basic
make[2]: Entering directory `/root/nagios/nagios-4.0.1/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagios /usr/local/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagiostats /usr/local/nagios/bin
make[2]: Leaving directory `/root/nagios/nagios-4.0.1/base'
.
.
.
*** 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/nagios/nagios-4.0.1'
Run the following command to install the init scripts for Nagios.
[root@linuxhelp1 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 ***
Run the following command to install command-mode.
[root@linuxhelp1 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 ***
Now install sample nagios files.
[root@linuxhelp1 nagios-4.0.1]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
.
.
.
*** Config files installed ***
Remember, these are *SAMPLE* config files. You' ll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
To customize Nagios Configuration
Open the ' contacts.cfg' file and set the email address.
[root@linuxhelp1 nagios-4.0.1]# vim /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 testuserlinux360@gmail.com < < ***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
To Install and Configure Web Interface for Nagios
Run the following command to configure Web interface for Nagios and a new web admin user called ' nagiosadmin' will be created.
[root@linuxhelp1 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 ***
Create a password for ' nagiosadmin' into the Nagios Web interface.
[root@linuxhelp1 nagios-4.0.1]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Start the Apache service.
[root@linuxhelp1 nagios-4.0.1]# service httpd start
Starting httpd: [ OK ]
To Compile and Install Nagios Plugin
Now, we have successfully downloaded nagios plugins in /root/nagios
[root@linuxhelp1 nagios-4.0.1]# cd /root/nagios/nagios-plugins-1.5 [root@linuxhelp1 nagios-plugins-1.5]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for gcc... gcc . . . --with-gnutls: no --enable-extra-opts: no --with-perl: /usr/bin/perl --enable-perl-modules: no --with-cgiurl: /nagios/cgi-bin --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin --enable-libtap: no
[root@linuxhelp1 nagios-plugins-1.5]# make
make all-recursive
make[1]: Entering directory `/root/nagios/nagios-plugins-1.5'
Making all in gl
make[2]: Entering directory `/root/nagios/nagios-plugins-1.5/gl'
rm -f alloca.h-t alloca.h & &
{ echo ' /* DO NOT EDIT! GENERATED AUTOMATICALLY! */'
cat ./alloca.in.h
} > alloca.h-t & &
mv -f alloca.h-t alloca.h
.
.
.
make[2]: Leaving directory `/root/nagios/nagios-plugins-1.5/po'
make[2]: Entering directory `/root/nagios/nagios-plugins-1.5'
make[2]: Leaving directory `/root/nagios/nagios-plugins-1.5'
make[1]: Leaving directory `/root/nagios/nagios-plugins-1.5'
[root@linuxhelp1 nagios-plugins-1.5]# make install
Making install in gl
make[1]: Entering directory `/root/nagios/nagios-plugins-1.5/gl'
make install-recursive
make[2]: Entering directory `/root/nagios/nagios-plugins-1.5/gl'
make[3]: Entering directory `/root/nagios/nagios-plugins-1.5/gl'
make[4]: Entering directory `/root/nagios/nagios-plugins-1.5/gl'
.
.
.
make[2]: Nothing to be done for `install-exec-am' .
make[2]: Nothing to be done for `install-data-am' .
make[2]: Leaving directory `/root/nagios/nagios-plugins-1.5'
make[1]: Leaving directory `/root/nagios/nagios-plugins-1.5'
To Verify Nagios Configuration Files
To verify the Nagios configuration, run the following command.
[root@linuxhelp1 nagios-plugins-1.5]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.0.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 10-15-2013
License: GPL
Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
.
.
.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
To Add Nagios Services to the System Startup
Add nagios and httpd with chkconfig command to make Nagios function across system reboots.
[root@linuxhelp1 nagios-plugins-1.5]# chkconfig --add nagios
[root@linuxhelp1 nagios-plugins-1.5]# chkconfig --level 35 nagios on
[root@linuxhelp1 nagios-plugins-1.5]# chkconfig --add httpd
[root@linuxhelp1 nagios-plugins-1.5]# chkconfig --level 35 httpd on
Start the Nagios services.
[root@linuxhelp1 nagios-plugins-1.5]# service nagios start
nagios is stopped
Starting nagios: [ OK ]
To Login into the Nagios
Open your browser with ' http://< IP_address> /nagios' or ' http://< domain_name> /nagios'
Nagios Login
Host View
Nagios Overview
Service View
Process View
Update Nagios 3.x to Nagios 4.0.1
Before upgrading, Stop the Nagios and download the new tar file.
[root@linuxhelp1 nagios-plugins-1.5]# service nagios stop
nagios (pid 19171 19170 19169 19168 19167 19165) is running...
Stopping nagios: [ OK ]
[root@linuxhelp1 nagios-plugins-1.5]# wget https://sourceforge.net/projects/nagios/files/latest/download
--2016-07-01 18:14:24-- http://heanet.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.1.1/nagios-4.1.1.tar.gz
Resolving heanet.dl.sourceforge.net... 193.1.193.66, 2001:770:18:aa40::c101:c142
Connecting to heanet.dl.sourceforge.net|193.1.193.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11142182 (11M) [application/x-gzip]
Saving to: “ download”
100%[======================================> ] 11,142,182 123K/s in 68s
2016-07-01 18:15:33 (160 KB/s) - “ download” saved [11142182/11142182]
Extract the tar file and install it.
[root@linuxhelp1 nagios-plugins-1.5]# tar -zxvf download
nagios-4.1.1/
nagios-4.1.1/.gitignore
nagios-4.1.1/Changelog
nagios-4.1.1/INSTALLING
nagios-4.1.1/LEGAL
.
.
.
nagios-4.1.1/xdata/xrddefault.h
nagios-4.1.1/xdata/xsddefault.c
nagios-4.1.1/xdata/xsddefault.h
[root@linuxhelp1 nagios-plugins-1.5]# cd nagios-4.1.1/ [root@linuxhelp1 nagios-4.1.1]# ./configure checking for a BSD-compatible install... /usr/bin/install -c checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no . . . 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.
[root@linuxhelp1 nagios-4.1.1]# make all
cd ./base & & make
make[1]: Entering directory `/root/nagios/nagios-plugins-1.5/nagios-4.1.1/base'
make -C ../lib
make[2]: Entering directory `/root/nagios/nagios-plugins-1.5/nagios-4.1.1/lib'
make[2]: Nothing to be done for `all' .
make[2]: Leaving directory `/root/nagios/nagios-plugins-1.5/nagios-4.1.1/lib'
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -o nagios nagios.o broker.o nebmods.o ../common/shared.o nerd.o query-handler.o workers.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o utils.o retention-base.o xretention-base.o comments-base.o xcomments-b
.
.
.
before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you. This might include:
- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:
https://support.nagios.com
*************************************************************
Enjoy.
[root@linuxhelp1 nagios-4.1.1]# make install
cd ./base & & make install
make[1]: Entering directory `/root/nagios/nagios-plugins-1.5/nagios-4.1.1/base'
make install-basic
make[2]: Entering directory `/root/nagios/nagios-plugins-1.5/nagios-4.1.1/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagios /usr/local/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagiostats /usr/local/nagios/bin
make[2]: Leaving directory `/root/nagios/nagios-plugins-1.5/nagios-4.1.1/base'
make strip-post-install
.
.
.
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/nagios/nagios-plugins-1.5/nagios-4.1.1'
[root@linuxhelp1 nagios-4.1.1]# service nagios start
nagios is stopped
Starting nagios: [ OK ]
Comments ( 0 )
No comments available