• Recent blogs

    How To Install Nagios 4.4.2 on CentOS 7 or RHEL 7

    How To Install Nagios 4.4.2  on CentOS 7 or RHEL 7

    Nagios 4

    In this How to Guide , we will cover the installation of Nagios 4 on CentOS 7 or RHEL 7. Nagios Core a very popular open source monitoring system. In  this tutorial we'll Install and configure nagios , so you will be able to monitor host resources via the web interface. We will also utilize the Nagios Remote Plugin Executor (NRPE), that will be installed as an agent on remote hosts, to monitor their resources.

    Install Nagios Core

    This guide is based on SELinux being disabled or in permissive mode. Steps to do this are as follows.

    sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
    setenforce 0

    As we are building Nagios Core from source, we must install a few development libraries that will allow us to complete the build.

    First, install the required packages:

    [root@nagiosmaster ~]# yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd unzip httpd -y

    Create Nagios User and Group
    We must create a user and group that will run the Nagios process. Create a “nagios” user and “nagcmd” group, then add the user to the group with these commands:

    [root@nagiosmaster ~]# useradd nagios
    [root@nagiosmaster ~]# groupadd nagcmd
    [root@nagiosmaster ~]# usermod -a -G nagcmd nagios

    Download the source code for the latest stable release of Nagios Core. Go to the Nagios downloads page, and click the Skip to download link below the form. Copy the link address for the latest stable release so you can download it to your Nagios server.

    We have installed Nagios® Core™ 4.4.2, so you can download  that version or Latest One as per your Choice.

    Download it to your home directory with curl:

    [root@nagiosmaster ~]# cd ~
    [root@nagiosmaster ~]# curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz

    Extract the Nagios archive with this command:

    [root@nagiosmaster ~]# tar xvf nagios-*.tar.gz
    Then change to the extracted directory:

    [root@nagiosmaster ~]# cd nagios-*

    Before building Nagios, we must configure it with this command:

    [root@nagiosmaster ~]# ./configure --with-command-group=nagcmd 

    Now compile Nagios with this command:

    [root@nagiosmaster ~]# make all

    Now we can run these make commands to install Nagios, init scripts, and sample configuration files:

    [root@nagiosmaster ~]# make install
    [root@nagiosmaster ~]# make install-commandmode
    [root@nagiosmaster ~]#  make install-init
    [root@nagiosmaster ~]#  make install-config
    [root@nagiosmaster ~]# make install-webconf

    In order to issue external commands via the web interface to Nagios, we must add the web server user, apache, to the nagcmd group:

    [root@nagiosmaster ~]# usermod -G nagcmd apache

    Install Nagios Plugins

    Download the latest nagios plugin. 

    We have installed nagios-plugins-2.2.1.

    [root@nagiosmaster ~]# cd ~
    [root@nagiosmaster ~]# curl -L -O http://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

    Extract Nagios Plugins archive with this command:

    [root@nagiosmaster ~]# tar xvf nagios-plugins-*.tar.gz

    Then change to the extracted directory:

    [root@nagiosmaster ~]# cd nagios-plugins-*

    Before building Nagios Plugins, we must configure it. Use this command:

    [root@nagiosmaster ~]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl

    Now compile Nagios Plugins with this command:

    [root@nagiosmaster ~]# make

    Then install it with this command:

    [root@nagiosmaster ~]# make install

    Install NRPE

    Find the source code for the latest stable release of NRPE at the NRPE downloads page. Download the latest version to your Nagios server.

    we have installed nrpe-3.2.1 .

    [root@nagiosmaster ~]# cd ~
    [root@nagiosmaster ~]#curl -L -O https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.2.1/nrpe-3.2.1.tar.gz

    Extract the NRPE archive with this command:
    [root@nagiosmaster ~]# tar xvf nrpe-*.tar.gz

    Then change to the extracted directory:
    [root@nagiosmaster ~]# cd nrpe-*

    Configure NRPE with these commands:
    [root@nagiosmaster ~]# ./configure --enable-command-args --with-nagios-user=nagios --with-nagios-group=nagios --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu

    Now build and install NRPE and its xinetd startup script with these commands:
    [root@nagiosmaster ~]# make all
    [root@nagiosmaster ~]# make install
    [root@nagiosmaster ~]# make install-xinetd
    [root@nagiosmaster ~]# make install-daemon-config

    Start the xinetd service to start NRPE:

    [root@nagiosmaster ~]#  service xinetd start

    Install NRPE through YUM:

    The easiest way to install NRPE is to install it through YUM.  

    install the EPEL repository:

    [root@nagiosmaster ~]# yum install epel-release

    Now install Nagios Plugins and NRPE:

    [root@nagiosmaster ~]# yum install nrpe nagios-plugins-all

    Now, let’s update the NRPE configuration file. 

    [root@nagiosmaster ~]# vi /etc/nagios/nrpe.cfg
    Find the allowed_hosts directive, and add the private IP address of your Nagios server to the comma-delimited list :


    Save and exit. This configures NRPE to accept requests from your Nagios server, via its private IP address.

    Restart NRPE to put the change into effect:

    [root@nagiosmaster ~]# systemctl start nrpe.service
    [root@nagiosmaster ~]# systemctl enable nrpe.service

    Lets Configure Nagios : 

    We will need to configure the nagios server now.

    Open the Nagios configuration file:

    [root@nagiosmaster ~]# vi /usr/local/nagios/etc/nagios.cfg

    Un-comment this Line:


    Save and exit.

    Now create the directory that will store the configuration file for each server that you will monitor:

    [root@nagiosmaster ~]# mkdir /usr/local/nagios/etc/servers

    Configure Nagios Contacts

    Open the Nagios contacts configuration:

    [root@nagiosmaster ~]# vi /usr/local/nagios/etc/objects/contacts.cfg

    Set your e-mail id and Save and exit.

    Configure Authentication

    Use htpasswd to create an admin user, called “nagiosadmin”, that can access the Nagios web interface:

    [root@nagiosmaster ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

    Enter a password at the prompt. Remember this login, as you will need it to access the Nagios web interface.

    Verify Nagios Configuration Files:

    Its good habit to check nagios configurations file before starting nagios Services.

    [root@nagiosmaster ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    Sample Output: 

    Now start the nagios and restart Apache:

    [root@nagiosmaster ~]# systemctl daemon-reload
    [root@nagiosmaster ~]# systemctl start nagios.service
    [root@nagiosmaster ~]# systemctl restart httpd.service

    Accessing the Nagios

    Use Following URL to access Nagios Webpage. As we have set password, it will ask for authentication. After authenticating, you will be see the default Nagios home page.

    How to Monitor a Linux host With nagios

    No comments