How to configure and install Nagios Server on Linux ?

Today we will see Nagios Installation on Linux

Lets see step by step procedure how to do this in Linux.

1. First create User and Group

# useradd nagios
# groupadd nagcmd

# usermod -G nagcmd nagios
# usermod -g nagcmd apache

[root@ngelinux001 ~]# id apache
uid=48(apache) gid=30334(nagcmd) groups=30334(nagcmd)

[root@ngelinux001 ~]# id nagios
uid=493(nagios) gid=485(nagios) groups=30334(nagcmd),3813(nagios),485(nagios)


2. Make Nagios directory and download package.

[root@ngelinux001 ~]# mkdir /root/nagios
[root@ngelinux001 ~]# cd /root/nagios/
[root@ngelinux001 nagios]# wget
--2022-05-17 18:16:20--
Resolving, 2600:3c00::f03c:92ff:fef7:45ce
Connecting to||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11304463 (11M) [application/x-gzip]
Saving to: “nagios-4.4.5.tar.gz”

100%[====================================================================================>] 11,304,463  2.19M/s   in 4.9s

2022-05-17 18:16:26 (2.19 MB/s) - “nagios-4.4.5.tar.gz” saved [11304463/11304463]

[root@ngelinux001 nagios]# wget --no-check-certificate
--2022-05-17 18:16:39--
Connecting to||:443... connected.
WARNING: cannot verify’s certificate, issued by “/C=US/O=Let's Encrypt/CN=R3”:
  Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 2728818 (2.6M) [application/x-gzip]
Saving to: “nagios-plugins-2.2.1.tar.gz”

100%[====================================================================================>] 2,728,818    927K/s   in 2.9s

2022-05-17 18:16:43 (927 KB/s) - “nagios-plugins-2.2.1.tar.gz” saved [2728818/2728818]

[root@ngelinux001 nagios]#


3. Unzip the Nagios packages.

[root@ngelinux001 nagios]# tar -xvf nagios-4.4.5.tar.gz 
[root@ngelinux001 nagios]# tar -xvf nagios-plugins-2.2.1.tar.gz 

[root@ngelinux001 nagios]# ls -l
total 13716
drwxrwxr-x 20 root root     4096 Aug 20  2019 nagios-4.4.5
-rw-r--r--  1 root root 11304463 Aug 20  2019 nagios-4.4.5.tar.gz
drwxr-xr-x 15 root root     4096 Apr 19  2017 nagios-plugins-2.2.1
-rw-r--r--  1 root root  2728818 Apr 19  2017 nagios-plugins-2.2.1.tar.gz

[root@ngelinux001 nagios]# cd nagios-4.4.5
[root@ngelinux001 nagios-4.4.5]# ls
aclocal.m4       config.guess     docs      tap             worker
autoconf-macros  config.sub       doxy.conf      INSTALLING  make-tarball      test            xdata
base             configure        functions      install-sh  mkpackage         sample-config  THANKS
cgi         html           LEGAL       module            startup        t-tap
Changelog        contrib          include        lib         nagios.spec       update-version
common   LICENSE     nagios.sysconfig  t              UPGRADING
[root@ngelinux001 nagios-4.4.5]#


4. Configure the package.

# ./configure --with-command-group=nagcmd

*** Configuration summary for nagios 4.4.5 2019-08-20 ***:

 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:  /var/run/nagios.lock
   Check result directory:  /usr/local/nagios/var/spool/checkresults
           Init directory:  /etc/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 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@ngelinux001 nagios-4.4.5]#


5. Install the package.

[root@ngelinux001 nagios-4.4.5]# make all
cd ./base && make
make[1]: Entering directory `/root/nagios/nagios-4.4.5/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 /com

[root@ngelinux001 nagios-4.4.5]# make install

*** 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/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

[root@ngelinux001 nagios-4.4.5]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/init.d
/usr/bin/install -c -m 755 -o root -g root startup/default-init /etc/init.d/nagios

[root@ngelinux001 nagios-4.4.5]# 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
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***


6. Define Contacts in the file.

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

define contact {

    contact_name            saket             ; Short name of user
    use                     generic-contact         ; Inherit default values from generic-contact template (defined above)
    alias                   Saket Jain            ; Full name of user
    email          ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

define contactgroup {

    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin saket


7. Configuring web interface for nagios

# make install-webconf
This will copy /etc/httpd/conf.d/nagios.conf file.


8. Set password for users.

[root@ngelinux001 saket]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

[root@ngelinux001 saket]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users saket
New password:
Re-type new password:
Adding password for user saket
[root@ngelinux001 saket]#


9. Restart Apache to make the new settings take effect.

[root@ngelinux001 saket]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName
                                                           [  OK  ]
[root@ngelinux001 saket]#


10. Compile and install nagios plugins

[root@ngelinux001 saket]# cd /root/nagios/

[root@ngelinux001 nagios]# cd nagios-plugins-2.2.1
[root@ngelinux001 nagios-plugins-2.2.1]# ls
ABOUT-NLS         ChangeLog  lib          plugins          REQUIREMENTS
acinclude.m4      CODING        COPYING       m4                   NEWS                    plugins-root     SUPPORT
ACKNOWLEDGEMENTS   FAQ                plugins-scripts  tap
aclocal.m4        config.rpath  gl            NP-VERSION-GEN          po     
AUTHORS           config_test   INSTALL       mkinstalldirs        perlmods                README           THANKS
build-aux         configure     LEGAL         nagios-plugins.spec  pkg                     release          tools
[root@ngelinux001 nagios-plugins-2.2.1]#

[root@ngelinux001 nagios-plugins-2.2.1]# ./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

[root@ngelinux001 nagios-plugins-2.2.1]# make
make  all-recursive
make[1]: Entering directory `/root/nagios/nagios-plugins-2.2.1'
Making all in gl

# make install


11. Verify the nagios status

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


12. Enable nagios service

[root@ngelinux001 nagios-plugins-2.2.1]# chkconfig --add nagios
[root@ngelinux001 nagios-plugins-2.2.1]# chkconfig --level 35 nagios on
[root@ngelinux001 nagios-plugins-2.2.1]# chkconfig --add httpd
[root@ngelinux001 nagios-plugins-2.2.1]# chkconfig --level 35 httpd on
# systemctl enable nagios
# systemctl enable httpd
0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments