Install Nagios in Cent OS 6


Nagios is one of the most famous and used application, to check other servers in a network.
We can define hosts, and the services we need to monitor, in a ‘.cfg’ file. Once we are done with that, we can enter the IP of the machine on which we installed nagios followed by ‘/nagios’ i.e ‘192.168.0.100/nagios‘.

After authenticating, we will see a list of all the hosts, and their status. We can know which host is up, which is down, and which host has problems in which of its services. Nagios provides a detailed view of all the host and its services, including its up-time.
The main advantage and plus point of nagios is, you can check and monitor all the computers on your network in one single windows. It gives us warnings shows alerts, and tells us which of our servers are down. It also helps us detect problems.

Nagios.

Nagios.

You can install Nagios in Cent OS in two ways.

  • By downloading its repo, and using YUM.
  • By downloading its packages, extracting it and configuring them.

We will install via Second method. The first one is pretty simple. Download Nagios and nrpe using YUM, Edit the hosts. cfg file and enter the host names and IP addresses of host you want to monitor.

However Downloading its packages and configuring it is a very complex and lengthy process. We will see all the steps IN DETAIL. So this will be a very long post.
If you’re configuring Nagios for the first time, it will look confusing and difficult. But once you get through the installation, you’ll find it simple and straight-forward. You’ll know what to do next.

  1. yum install httpd php gcc glibc glibc-common gd gd-devel make  -y 
    Install all the dependencies.

    Install dependencies.

    Install dependencies.

     

  2. useradd -m nagios
    groupadd nagcmd
    usermod -G nagcmd nagios
    usermod -G nagcmd apache
    passwd nagios
    Add a new user as ‘nagios’ , and new group as ‘nagcmd’. Add ‘nagios’ and ‘apache’ users to group ‘nagcmd’
    Set a password fornagios user.

    Add nagios user and set its password. Add nagcmd group.

    Add nagios user and set its password. Add nagcmd group.

     

  3. mkdir /root/nagios
    cd /root/nagios
    Make a new directory namednagios. We will download all the files and extract them in this directory only.

    Create a directory .

    Create a directory .

     

  4. wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
    wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
    DownloadNagios package and its plugins package.

    Download Nagios and its plugins using wget

    Download Nagios and its plugins using wget

     

  5. Check the downloaded files before extracting.
    Check files.

    Check files

     

  6. tar -zxvf nagios-4.0.1.tar.gz
    ExtractNagios in the current folder.

    Extract Nagios.

    Extract Nagios

     

  7. cd nagios-4.0.1
    Once the tar fileis extracted, a folder would be created with the name ‘nagios-4.0.1’. Enter that directory.

    Enter Nagios folder and run './configure'

    Enter Nagios folder and run ‘./configure’

     

  8. ./configure --with-group=nagcmd
    make all
    make installConfigure the package with group ‘nagcmd’. Then use ‘make all’. Only ‘make’ command won’t work. Then enter ‘make install’.

    ./configure

    ./configure

    make

    make all

    make install

    make install.

     

  9. make install-init
    make install-config

    make install-commandmodeThese commands will install init scripts for nagios ( ‘init’ ) , install the sample nagios files ( ‘config’ ) and  use nagios via
    command line ( ‘commandmode’ )  .

    Install init scripts and commandmode

    Install init scripts and config

    install commandmode

    Install commandmode

     

  10. vi /usr/local/nagios/etc/objects/contacts.cfg
    Open the ‘contacts.cfg’ file in ‘/etc/objects‘ directory of ‘nagios‘.
    Edit the Email address of admin. Put your own Email address. The alerts would be directly sent to the admin.

    Open contacts.cfg

    Open contacts.cfg

    Enter your mail id.

    Enter your mail id.

     

  11. make install-webconf
    htpasswd -c -s /usr/local/nagios/etc/htpasswd.users nagiosadmin
    service httpd restart
    First install the web interface for Nagios. A new user nagiosadmin would be created.
    Set password for nagios admin using htpasswd. ‘-c‘ switch is used to create the ‘htpasswd.users‘ file, and ‘-s‘ is used too set its place, Then restart apache.

    Install webconf, set password for nagiosadmin and restart apache.

    Install webconf, set password for nagiosadmin and restart apache.

     

  12. cd .. or cd /root/nagios
    tar -zxvf nagios-plugins-1.5.tar.gzCurrently you’re in /root/nagios/nagios-4.0.1.
    Come one directory up, that is to /root/nagios.
    Now extract ‘nagios-plugins’.

    Go one directory up, and extract nagios plugins.

    Go one directory up, and extract nagios plugins.

     

  13. cd nagios-plugins-1.5
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    make
    make install
    Once extracted a new folder would be created. Go in that folder, and run ./configure for user and group ‘nagios’ . Next run ‘make’ and ‘make install’.

    Configure it for nagios user and nagios group.

    Configure it for nagios user and nagios group.

    make and make install

    make and make install

     

  14. /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    Verify your commands by running the above command.

    Verify your commands.

    Verify your commands.

    No errors.

    No errors.

     

  15. chkconfig --add nagios
    chkconfig nagios on
    Add nagios to Startup usingchkconfig.

    Chkconfig

    Chkconfig

     

  16. /etc/init.d/nagios start
    StartNagios.

    Start nagios service.

    Start nagios service.

     

  17. http://10.0.2.15/nagios
    Enter in your browser ‘http://[ IP ]/nagios
    Enter Username asnagiosadmin, and enter the password you gave in step 11.

    Enter username and password.

    Enter username and password.

    Nagios home

    Nagios home

    Current hosts.

    Current hosts.

    Note : Set Selinux in Permissive mode 🙂

Leave a Reply