Author Photo

Ahmer's SysAdmin Recipes is a blog for Linux System Administrators. This blog provides recipes for Installation & Configuration of Linux, Ubuntu, Oracle Database, MySQL, Apache, Nginx, Oracle Cloud Control, FreeIPA, Kerberos & OpenLDAP, Subversion, PXE, DevOps, etc. over Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and Windows.

Please give me your feedback and help me improve this blog. Please let me know If you want me to write on a specific topic.

Sunday, 23 December 2018

Install & Configure Nagios Core 4.4 on CentOS 7

install-and-configure-nagios-core-on-centos-7Nagios Core is a free and open source software application that provides monitoring and alerting services for servers, switches, applications and services. It monitors targets (i.e. hosts and services) and alerts users when something go wrong and alerts them a second time when the problem has been resolved. Nagios Core is primary application and monitoring and alerting engine, around that hundred of Nagios Projects are built.

In this article, we will install and configure Nagios Core 4.4 on CentOS 7 server.

Before moving forward, it is required to have basic concepts of Nagios Core 4. Therefore, it is highly recommended that you should have Learning Nagios - Third Edition. It will be really helpful for you during your Nagios journey.

 

System Specification:

We have configured a CentOS 7 virtual machine with following specifications:

Operating System CentOS 7.6
Nagios Core 4.4.2
Hostname nagios-01.example.com
IP Address: 192.168.116.130/24

 

Install Nagios Core 4.4 on CentOS 7:

Connect to nagios-01.example.com using ssh.

Install pre-requisite packages using yum command.

[root@nagios-01 setup]# yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix ... Installed: gcc.x86_64 0:4.8.5-36.el7 gd.x86_64 0:2.0.35-26.el7 gd-devel.x86_64 0:2.0.35-26.el7 httpd.x86_64 0:2.4.6-88.el7.centos perl.x86_64 4:5.16.3-293.el7 php.x86_64 0:5.4.16-46.el7 unzip.x86_64 0:6.0-19.el7 Dependency Installed: apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 cpp.x86_64 0:4.8.5-36.el7 dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 expat-devel.x86_64 0:2.1.0-10.el7_3 fontconfig.x86_64 0:2.13.0-4.3.el7 fontconfig-devel.x86_64 0:2.13.0-4.3.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 freetype-devel.x86_64 0:2.8-12.el7 glibc-devel.x86_64 0:2.17-260.el7 glibc-headers.x86_64 0:2.17-260.el7 httpd-tools.x86_64 0:2.4.6-88.el7.centos kernel-headers.x86_64 0:3.10.0-957.1.3.el7 libICE.x86_64 0:1.0.9-9.el7 libSM.x86_64 0:1.2.2-2.el7 libX11.x86_64 0:1.6.5-2.el7 libX11-common.noarch 0:1.6.5-2.el7 libX11-devel.x86_64 0:1.6.5-2.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXau-devel.x86_64 0:1.0.8-2.1.el7 libXext.x86_64 0:1.3.3-3.el7 libXpm.x86_64 0:3.5.12-1.el7 libXpm-devel.x86_64 0:3.5.12-1.el7 libXt.x86_64 0:1.1.5-3.el7 libjpeg-turbo.x86_64 0:1.2.90-6.el7 libjpeg-turbo-devel.x86_64 0:1.2.90-6.el7 libmpc.x86_64 0:1.0.1-3.el7 libpng-devel.x86_64 2:1.5.13-7.el7_2 libuuid-devel.x86_64 0:2.23.2-59.el7 libxcb.x86_64 0:1.13-1.el7 libxcb-devel.x86_64 0:1.13-1.el7 libzip.x86_64 0:0.10.1-8.el7 mailcap.noarch 0:2.1.41-2.el7 mpfr.x86_64 0:3.1.1-4.el7 perl-Carp.noarch 0:1.26-244.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-Pod-Escapes.noarch 1:1.04-293.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-293.el7 perl-macros.x86_64 4:5.16.3-293.el7 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 php-cli.x86_64 0:5.4.16-46.el7 php-common.x86_64 0:5.4.16-46.el7 xorg-x11-proto-devel.noarch 0:2018.4-1.el7 zlib-devel.x86_64 0:1.2.7-18.el7 Complete!

Currently, Nagios Core does not compliance with SELinux, therefore we have to disable SELinux.

[root@nagios-01 setup]# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config [root@nagios-01 setup]# setenforce 0

Create a directory for downloading Nagios Core source.

[root@nagios-01 ~]# mkdir setup

Download Nagios Core from https://www.nagios.org/downloads/nagios-core/.

[root@nagios-01 ~]# cd ~/setup [root@nagios-01 setup]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz --2018-12-23 10:35:22-- https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz Resolving assets.nagios.com (assets.nagios.com)... 72.14.181.71, 2600:3c00::f03c:91ff:fedf:b821 Connecting to assets.nagios.com (assets.nagios.com)|72.14.181.71|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 11301454 (11M) [application/x-gzip] Saving to: ânagios-4.4.2.tar.gzâ 100%[======================================>] 11,301,454 1.16MB/s in 10s 2018-12-23 10:35:34 (1.03 MB/s) - ânagios-4.4.2.tar.gzâ saved [11301454/11301454]

Extract downloaded source of Nagios Core.

[root@nagios-01 setup]# tar xvf nagios-4.4.2.tar.gz ... nagios-4.4.2/xdata/xpddefault.h nagios-4.4.2/xdata/xrddefault.c nagios-4.4.2/xdata/xrddefault.h nagios-4.4.2/xdata/xsddefault.c nagios-4.4.2/xdata/xsddefault.h

Compile and install Nagios Core from extracted source.

[root@nagios-01 setup]# cd ~/setup/nagios-4.4.2 [root@nagios-01 nagios-4.4.2]# ./configure config.status: creating t/Makefile config.status: creating t-tap/Makefile config.status: creating include/config.h config.status: creating lib/snprintf.h config.status: creating lib/iobroker.h Creating sample config files in sample-config/ ... *** Configuration summary for nagios 4.4.2 2018-08-16 ***: General Options: ------------------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagios Event Broker: yes Install ${prefix}: /usr/local/nagios Install ${includedir}: /usr/local/nagios/include/nagios Lock file: /run/nagios.lock Check result directory: /usr/local/nagios/var/spool/checkresults Init directory: /lib/systemd/system Apache conf.d directory: /etc/httpd/conf.d Mail program: /usr/sbin/sendmail 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): Review the options above for accuracy. If they look okay, type 'make all' to compile the main program and CGIs. [root@nagios-01 nagios-4.4.2]# make all ... make[1]: Entering directory `/root/setup/nagios-4.4.2/worker' cd ./ping && make all make[2]: Entering directory `/root/setup/nagios-4.4.2/worker/ping' gcc -I.. -I ../../include -I ../.. -g -O2 -DHAVE_CONFIG_H -o worker-ping worker-ping.c -L ../../lib -l nagios make[2]: Leaving directory `/root/setup/nagios-4.4.2/worker/ping' make[1]: Leaving directory `/root/setup/nagios-4.4.2/worker' *** Compile finished *** If the main program and CGIs compiled without any errors, you can continue with testing or installing Nagios as follows (type 'make' without any arguments for a list of all possible options): make test - This runs the test suite make install - This installs the main program, CGIs, and HTML files make install-init - This installs the init script in /lib/systemd/system make install-daemoninit - This will initialize the init script in /lib/systemd/system make install-groups-users - This adds the users and groups if they do not exist 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 You'll have to modify these sample files before you can use Nagios. Read the HTML documentation for more info on doing this. Pay particular attention to the docs on object configuration files, as they determine what/how things get monitored! make install-webconf - This installs the Apache config file for the Nagios web interface make install-exfoliation - This installs the Exfoliation theme for the Nagios web interface make install-classicui - This installs the classic theme for the Nagios web interface *** Support Notes ******************************************* If you have questions about configuring or running Nagios, please make sure that you: - Look at the sample config files - Read the documentation on the Nagios Library at: https://library.nagios.com 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.

Create OS user and groups for Nagios Core.

[root@nagios-01 nagios-4.4.2]# make install-groups-users groupadd -r nagios useradd -g nagios nagios [root@nagios-01 nagios-4.4.2]# usermod -a -G nagios apache

Install Nagios Core 4.4 now.

[root@nagios-01 nagios-4.4.2]# make install /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/spool/checkresults chmod g+s /usr/local/nagios/var/spool/checkresults *** 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 /lib/systemd/system 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/setup/nagios-4.4.2'

Install Nagios Core service.

[root@nagios-01 nagios-4.4.2]# make install-daemoninit /usr/bin/install -c -m 755 -d -o root -g root /lib/systemd/system /usr/bin/install -c -m 755 -o root -g root startup/default-service /lib/systemd/system/nagios.service Created symlink from /etc/systemd/system/multi-user.target.wants/nagios.service to /usr/lib/systemd/system/nagios.service. *** Init script installed ***

Enable httpd service.

[root@nagios-01 nagios-4.4.2]# systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

Install and configure external command file.

[root@nagios-01 nagios-4.4.2]# make install-commandmode /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw chmod g+s /usr/local/nagios/var/rw *** External command directory configured ***

Install Sample configuration files for Nagios Core.

[root@nagios-01 nagios-4.4.2]# make install-config /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 *** 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.

Add Nagios Core configurations to Apache Web Server.

[root@nagios-01 nagios-4.4.2]# make install-webconf /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf if [ 0 -eq 1 ]; then \ ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \ fi *** Nagios/Apache conf file installed ***

Configure Linux Firewall to allow http service.

[root@nagios-01 nagios-4.4.2]# firewall-cmd --permanent --add-service=http success [root@nagios-01 nagios-4.4.2]# firewall-cmd --reload success

Nagios does not have integrated user authentication, therefore, we have to use Basic HTTP authentication for this purpose.

Create an admin user for Nagios Core Web UI.

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

Start httpd & nagios services.

[root@nagios-01 nagios-4.4.2]# systemctl start httpd.service [root@nagios-01 nagios-4.4.2]# systemctl start nagios.service Warning: nagios.service changed on disk. Run 'systemctl daemon-reload' to reload units. [root@nagios-01 nagios-4.4.2]# systemctl daemon-reload

Browse URL http://192.168.116.130/nagios to connect with Nagios Core Web UI.

nagios-core-web-ui-login-01

Login using nagiosadmin user.

nagios-core-web-ui-dashboard-01

Go to services page.

nagios-core-web-ui-services-01

You can see that all the services are unavailable. It is because we don’t have installed Nagios Plugins on our CentOS 7 server.

 

Install Nagios Plugins on CentOS 7 Server:

Install pre-requisite packages for Nagios Plugins using yum command.

[root@nagios-01 nagios-4.4.2]# yum install -y perl-Net-SNMPyum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release ... Installed: autoconf.noarch 0:2.69-11.el7 automake.noarch 0:1.13.4-3.el7 epel-release.noarch 0:7-11 net-snmp.x86_64 1:5.7.2-37.el7 net-snmp-utils.x86_64 1:5.7.2-37.el7 openssl-devel.x86_64 1:1.0.2k-16.el7 Dependency Installed: keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.15.1-34.el7 libcom_err-devel.x86_64 0:1.42.9-13.el7 libkadm5.x86_64 0:1.15.1-34.el7 libselinux-devel.x86_64 0:2.5-14.1.el7 libsepol-devel.x86_64 0:2.5-10.el7 libverto-devel.x86_64 0:0.2.5-4.el7 lm_sensors-libs.x86_64 0:3.4.0-6.20160601gitf9185e5.el7 m4.x86_64 0:1.4.16-10.el7 net-snmp-agent-libs.x86_64 1:5.7.2-37.el7 net-snmp-libs.x86_64 1:5.7.2-37.el7 pcre-devel.x86_64 0:8.32-17.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Test-Harness.noarch 0:3.28-3.el7 perl-Thread-Queue.noarch 0:3.02-2.el7 Complete! [root@nagios-01 nagios-4.4.2]# yum install -y perl-Net-SNMP ... Installed: perl-Net-SNMP.noarch 0:6.0.1-7.el7 Dependency Installed: perl-Crypt-DES.x86_64 0:2.05-20.el7 perl-Digest.noarch 0:1.17-245.el7 perl-Digest-HMAC.noarch 0:1.03-5.el7 perl-Digest-MD5.x86_64 0:2.52-3.el7 perl-Digest-SHA.x86_64 1:5.85-4.el7 perl-Digest-SHA1.x86_64 0:2.13-9.el7 perl-Socket6.x86_64 0:0.23-15.el7 Complete!

Download Nagios Plugins from https://www.nagios.org/downloads/nagios-plugins/.

[root@nagios-01 ~]# cd ~/setup [root@nagios-01 setup]# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz --2018-12-23 10:37:19-- https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz Resolving nagios-plugins.org (nagios-plugins.org)... 72.14.186.43 Connecting to nagios-plugins.org (nagios-plugins.org)|72.14.186.43|:443... connected. 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 813KB/s in 3.3s 2018-12-23 10:37:24 (813 KB/s) - ânagios-plugins-2.2.1.tar.gzâ saved [2728818/2728818]

Extract downloaded source of Nagios Plugins.

[root@nagios-01 nagios-4.4.2]# cd ~/setup [root@nagios-01 setup]# tar xvf nagios-plugins-2.2.1.tar.gz ... nagios-plugins-2.2.1/pkg/solaris/solpkg nagios-plugins-2.2.1/pkg/solaris/pkginfo.in nagios-plugins-2.2.1/pkg/solaris/pkginfo nagios-plugins-2.2.1/pkg/redhat/ nagios-plugins-2.2.1/pkg/redhat/requires

Compile Nagios Plugins source.

[root@nagios-01 setup]# cd ~/setup/nagios-plugins-2.2.1 [root@nagios-01 nagios-plugins-2.2.1]# ./configure ... config.status: executing libtool commands config.status: executing po-directories commands config.status: creating po/POTFILES config.status: creating po/Makefile

Install Nagios Plugins.

[root@nagios-01 nagios-plugins-2.2.1]# make ... make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/root/setup/nagios-plugins-2.2.1/po' make[2]: Entering directory `/root/setup/nagios-plugins-2.2.1' make[2]: Leaving directory `/root/setup/nagios-plugins-2.2.1' make[1]: Leaving directory `/root/setup/nagios-plugins-2.2.1' [root@nagios-01 nagios-plugins-2.2.1]# make install ... make[2]: Entering directory `/root/setup/nagios-plugins-2.2.1' 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/setup/nagios-plugins-2.2.1' make[1]: Leaving directory `/root/setup/nagios-plugins-2.2.1'

Go to Nagios Web UI and open services page.

nagios-core-web-ui-services-02

You can see that, now all the services are in OK state now. (Note: Keep patience, Nagios Core takes a while to collect data for each service)

We have successfully install and configure Nagios Core 4.4 on our CentOS 7 server.

Install & Configure Nagios Core 4.4 on CentOS 7


YOU MIGHT ALSO LIKE:

22 comments:

  1. I Like your work highly appreciate
    Thanks

    ReplyDelete
  2. Hi Ahmer,

    Thank you for the configuration. I wanted to monitor backup job status from veritas backup exec but I am getting unknown error which is "unknown command check_backupexec".

    Details of Nagios: Nagios 4.4.2 in CentOS 7. Veritas backup verion 20, 2018.

    ReplyDelete
    Replies
    1. Hi,
      Thanks for liking this article.

      Make sure you have defined the command check_backupexec in command.cfg file.
      It looks like you are using BackupExec plugin. Please refer to BackupExec - Nagios Exchange for complete configuration.

      Delete
  3. Hi Ahmer,
    I am faceing the following issue while following your blog:
    systemctl start nagios.service
    Failed to start nagios.service: Unit not found.

    Can you please guide. How to start nagios service.

    ReplyDelete
    Replies
    1. It looks like nagios service is not correctly installed.
      Please ensure that you have installed nagios daemon using (as mentioned in above article).
      # make install-daemoninit

      Delete
  4. how to configure snmp for nagios to monitor hard disk, cpu and etc.

    ReplyDelete
    Replies
    1. There are some templates available in Nagios default configurations for capturing SNMP traps from network devices. Just configure SNMP traps on that device and configure a service on you Nagios Core server to capture that SNMP trap.

      Delete
  5. Hi Ahmer,

    Brilliant peace thank you for that!

    Somehow follwing your instructions i must have missed a step, because i am able to start en reload the nagios service and i am also able te see the test appache webpage, but
    When i put in the ipaddress/nagios into the url of my webbrowser it can't find anything :(
    The webpage cannot be found

    Could you please guide my into the right direction of the step i might have missed?

    thanks you!

    ReplyDelete
    Replies
    1. Hi, Thanks for appreciating my work.

      - For Nagios Service, use following command to verify and troubleshoot errors in Nagios configurations.

      - For Apache Service, refer to /var/log/messages for any possible errors.

      Delete
  6. how to install ndoutil on nagios ?

    ReplyDelete
  7. Can I add China skyline gateway for monitoring in nagios ???
    If yes how can I add ?

    ReplyDelete
    Replies
    1. Yes, you can.
      You have to enable SNMP Traps, and allow Nagios Server to access the router SNMP traps.

      Delete
    2. Thanks or the reply.
      Can you guide me through ???

      Delete
  8. thanks you ,
    i have a question please , i wan't to add supervisor can you show me what i should i do ?

    ReplyDelete
    Replies
    1. Nagios Core uses HTTP basic authentication and Nagios Core's default password file is /usr/local/nagios/etc/htpasswd.users.

      You can use htpasswd command to add a supervisor user therein.

      Delete
    2. Thanks you MR Ahmed,
      What about NRPE,apache, postgress ?
      I want to connect Nagios with server in my vmwork .

      Delete
    3. Hi, NRPE installation is already mentioned here.

      You need to create services in Nagios to monitor services like Apache, Postgres, etc.

      If you are working on a DIY strategy than, I suggest you to please read Learning Nagios - Third Edition.

      Delete