How to setup nagios server on Linux ?

Nagios Installation on 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 https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
--2022-05-17 18:16:20--  https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
Resolving assets.nagios.com... 45.79.49.120, 2600:3c00::f03c:92ff:fef7:45ce
Connecting to assets.nagios.com|45.79.49.120|: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 https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz --no-check-certificate
--2022-05-17 18:16:39--  https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
Resolving nagios-plugins.org... 45.56.123.251
Connecting to nagios-plugins.org|45.56.123.251|:443... connected.
WARNING: cannot verify nagios-plugins.org’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           indent.sh   Makefile.in       pkginfo.in     tap             worker
autoconf-macros  config.sub       doxy.conf      INSTALLING  make-tarball      README.md      test            xdata
base             configure        functions      install-sh  mkpackage         sample-config  THANKS
cgi              configure.ac     html           LEGAL       module            startup        t-tap
Changelog        contrib          include        lib         nagios.spec       subst.in       update-version
common           CONTRIBUTING.md  indent-all.sh  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

 

6. Install the configuration files.

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

 

7. Define Contacts in the file.

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

define contact {

    contact_name            User             ; Short name of user
    use                     generic-contact         ; Inherit default values from generic-contact template (defined above)
    alias                   User Jain            ; Full name of user
    email                   user@ngelinux.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

define contactgroup {

    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin User
}

 

8. Configuring web interface for nagios

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

 

9. Set password for users.

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

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

 

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

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

 

11. Compile and install nagios plugins

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

[root@ngelinux001 nagios]# cd nagios-plugins-2.2.1
[root@ngelinux001 nagios-plugins-2.2.1]# ls
ABOUT-NLS         ChangeLog     configure.ac  lib                  nagios-plugins.spec.in  plugins          REQUIREMENTS
acinclude.m4      CODING        COPYING       m4                   NEWS                    plugins-root     SUPPORT
ACKNOWLEDGEMENTS  config.h.in   FAQ           Makefile.am          NPTest.pm               plugins-scripts  tap
aclocal.m4        config.rpath  gl            Makefile.in          NP-VERSION-GEN          po               test.pl.in
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

 

12. Verify the nagios status

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

 

13. 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
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments