Nagios is an open-source monitoring software that allows system administrators to monitor the health and performance of servers, applications, and network devices. Nagios provides a comprehensive solution for monitoring the IT infrastructure and can alert administrators of potential problems before they become critical.

Advertisement

In this article, we will go over the steps to install Nagios on CentOS and Red Hat Enterprise Linux (RHEL) 9/8. These steps cover everything from downloading the software to configuring authentication for the Nagios web interface.

By the end of this article, you will have a fully functional Nagios server that can be used to monitor your IT infrastructure. So, let’s get started!

Prerequisites

Before we begin, make sure that you have a server running either CentOS or RHEL 9/8, with root access or a user with sudo privileges. Additionally, ensure that your server is up-to-date by running the following command:

sudo yum update -y 

Step 1: Install Required Dependencies

Before we install Nagios, we need to install a few dependencies: Apache web server, PHP, and GCC. You can install these by running the following command:

sudo yum groupinstall "development tools" 
sudo yum install httpd php php-cli gcc unzip wget glibc glibc-common gd gd-devel net-snmp 

Step 2: Create a Nagios User and Group

Nagios requires a user and group to run its processes. To create these, run the following commands:

sudo useradd nagios 
sudo groupadd nagcmd 
sudo usermod -a -G nagcmd nagios 
sudo usermod -a -G nagcmd apache 

Step 3: Download Nagios Core

To download Nagios Core, we will use the wget command to download the latest version of Nagios Core from the official website. At the time of writing, the latest version is 4.4.5. Run the following command to download it:

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.10.tar.gz 

Once the archive has been downloaded, we can extract it using the following command:

tar xzf nagios-4.4.10.tar.gz 

Step 4: Compile Nagios Core

To compile Nagios Core, navigate to the extracted directory using the following command:

cd nagios-4.4.10 

Next, run the following command to compile Nagios Core:

./configure --with-command-group=nagios 
make all 

Step 5: Install Nagios Core

Once the compilation is complete, we can install Nagios Core by running the following commands:

sudo make install 
sudo make install-commandmode 
sudo make install-init 
sudo make install-config 
sudo make install-webconf 

Step 6: Install Nagios Plugins

Nagios Plugins are required to extend the functionality of Nagios Core. After installing and configuring core service, Download latest nagios-plugins source and install using the following commands.

wget http://nagios-plugins.org/download/nagios-plugins-2.4.3.tar.gz 
sudo tar xzf nagios-plugins-2.4.3.tar.gz 
cd nagios-plugins-2.4.3 

Now compile and install nagios plugins

./configure --with-nagios-user=nagios --with-nagios-group=nagcmd 
sudo make 
sudo make install 

Step 7: Configure Nagios

To configure Nagios, we need to edit the Nagios configuration file. To do this, run the following command:

sudo nano /usr/local/nagios/etc/nagios.cfg 

In the configuration file, check for the following line, add them if not available:

How to Install Nagios Server on CentOS & RHEL
Check Nagios configuration file

Save and close the file.

Step 8: Set up Authentication

By default, Nagios requires authentication to access the web interface. To set up authentication, run the following command to create an admin user:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 

Enter a strong password to complete the process.

Step 9: Verify and Start Services

First, verify the Nagios configuration file using the following command.

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

If there is no error found, run the following command to enable and start Nagios service:

sudo systemctl enable nagios 
sudo systemctl start nagios 

Next, start the Apache web server using the following command:

sudo systemctl start httpd 

Step 10: Access the Nagios Web Interface

Finally, you can access the Nagios web interface by navigating to http://your-server-ip-hostname/nagios in your web browser. You will be prompted to enter the username and password you created in step 8.

Login to nagios core

After successful authentication, you will get the Nagios core dashboard access.

Nagios web interface

Here you can find the detailed information about Nagios hosts, services, notification etc.

Conclusion

In this article, we have gone over the steps to install Nagios on CentOS and RHEL 9/8. Nagios is a powerful open-source monitoring software that can help you monitor the health and performance of your systems and applications. With the steps outlined in this article, you should be able to get Nagios up and running on your server in no time.

Share.

53 Comments

  1. Great information shared. Adding a few lines about Nagios, ” Nagios provides complete monitoring of Linux operating systems and distributions – including operating system metrics, service state, process state, file system usage, and more.”

  2. Your first step successfully done[How to Install Nagios 4 (Monitoring Server) on CentOS/RHEL 7/6] & its very helpful to understand. Would u plz tell me process, how to add host? & what another services are need to installed ? Plz Note I am using centos7 .

    Reagards

    • This is just a simple guide, but check some examples.

      –Open this file
      nano /usr/local/nagios/etc/nagios.cfg

      —search and uncoment
      #cfg_file=/usr/local/nagios/etc/objects/switch.cfg

      —to

      cfg_file=/usr/local/nagios/etc/objects/switch.cfg

      —close file

      —Open and add these command below (host and 2 services to monitoring)
      nano /usr/local/nagios/etc/objects/switch.cfg

      define host{
      use generic-switch
      host_name switchcore01
      alias swtich main num 1
      address 10.10.10.3
      hostgroups switches
      }

      define service{
      use generic-service
      host_name switchcore01
      service_description PING
      check_command check_ping!200.0,20%!600.0,60%
      normal_check_interval 5
      retry_check_interval 1
      }

      define service {
      use generic-service
      host_name switchcore01
      service_description Uptime
      check_command check_snmp!-C MYCOMMUNITYHERE -o sysUpTime.0
      }

      —-close the file

      —–checck the config
      sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

      — now reload the service

      sudo service nagios reload

      —-You can see on the web browser.

      Regards

  3. Hi I followed all lines.
    While i was writing command make make all
    got error “make: *** No rule to make target `all’. Stop.”
    make utility allready installed.
    Please help in this.

  4. hi i am serge
    i have install nagios properly when i run nagios.service i have this message “job for nagios.service failed because the control process exited with error code” thanks for your help

  5. Hi Team,

    I installed Nagios on Linux, with all the steps as mentioned above. but while logging I am not able to login. getting error like
    ” Authorization Required

    This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn’t understand how to supply the credentials required.

    Apache/2.2.15 (Red Hat) Server at 172.29.218.194 Port 80″

    Can some one help on this please.

  6. i have gone through all the commands its open login page where i put the user nagioadmin and password i gave at the time of creation on user, but the user is not authenticated, please tell me whats error. i have changed the password of this user as well but go not log in.

    please tell

    • Hey Bilal,
      Not sure if you have the correct user name. It is nagiosadmin and not nagioadmin . I was able to get it working without any issues

  7. Very good notes

    and i have one question

    if you create a two user u1 and u2
    and first log in to u1 and without logout
    try to log in to u2 it is asking some password
    by defualt what password it is tacking can you please solve this query….

  8. Complete steps! – installed on CentOS 6 x64 after much trying and reading…

    Nagios Centos Install

    # rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
    yum –enablerepo=remi install httpd
    service httpd start
    chkconfig httpd on
    sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
    yum install mysql mysql-server
    service mysqld start
    yum install php php-mysql
    yum install php-common php-cli php-mysql php-devel
    service httpd restart
    service mysqld restart
    yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp
    service httpd start
    useradd nagios
    passwd nagios

    ​ Step 2: Setup User Accounts
    Now create a new nagios user account and setup a password to this account
    # useradd nagios
    # passwd nagios
    Now create a groud for nagios setup “nagcmd” and add nagios user to this group. Also add nagios user in apache group.
    # groupadd nagcmd
    # usermod -a -G nagcmd nagios
    # usermod -a -G nagcmd apache
    ​ Step 3: Install Nagios Core Service
    After installing required dependencies and adding user accounts. Lets start with Nagios core installation. Download latest nagios core service from official site.
    # cd /opt/
    # wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
    # tar xzf nagios-4.0.8.tar.gz
    # cd nagios-4.0.8
    # ./configure –with-command-group=nagcmd
    # make all
    # make install
    # make install-init
    # make install-config
    # make install-commandmode
    Now use below command to setup apache configuration for Nagios installation.
    # make install-webconf
    ​ Step 4: Configure Apache Authentication
    We need to setup apache authentication for user nagiosadmin. Do not change this username. else you would required more changes in configuration.
    # htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
    Now restart Apache service to make the new settings take effect.
    # service httpd restart
    ​ Step 5: Install Nagios Plugins
    After installing and configuring Nagios core service, Download latest nagios-plugins source and install using following commands.
    # cd /opt
    # wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
    # tar xzf nagios-plugins-2.0.3.tar.gz
    # cd nagios-plugins-2.0.3
    Now compile and install nagios plugins
    # ./configure –with-nagios-user=nagios –with-nagios-group=nagios
    # make
    # make install
    ​ Step 6: Verify and Start Nagios
    Use the following commands to verify nagios install and start nagios core service.
    # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    # service nagios start
    Also configure nagios service to start on system start
    # chkconfig –add nagios
    # chkconfig nagios on
    firewall-cmd –add-port=80/tcp –permanent

    # vim /etc/sysconfig/selinux
    SELINUX=disabled

    REBOOT SERVER.

    Service mysqld start
    service https start
    service nagios start

    Logon on to nagios from web brower!

  9. Hosney Osman on

    it’s not comment
    thank you so much for your effort writing this article
    i want to say unzip is a mandatory package for installation

  10. Constantin on

    Hello Rahul,
    i have a question,
    why we have to install apache and not nginx? (I am not asking the differences between them) but it has to do with the nagios program? e.g isn’t compatible or something like that?

    • With Nagios, you can monitor your entire infrastructure (critical servers and network components) with ease, on a web interface. In case anything goes wrong, you receive a notification and the issue gets addressed in timely manner.

      And best thing is that, Nagios Core is Free and Open Source, so you can customize it as per your needs.

      Thanks.

  11. Hi
    I finish all progress . but I can’t see local host status
    Current, My nagios web page show the message ‘unable to get process status’
    Do you know this problem?

  12. I am getting this error when i am trying to open via browser

    Forbidden

    You don’t have permission to access /nagios on this server.

  13. Hi,

    We are trying to install this, and all went well – but on the homepage we get an error saying “Unable to get process status” and no other page will load – internal server error.

    Steve

    • I had this problem as well. Try the selinux suggestion above. When things don’t work and you did everything right with no errors, for me 9 times out of 10 the problem is selinux. I try to remember to try this first now.

  14. Hello,
    I have followed these steps and it is successfully installed on my VM (CentOS) and everything was fine but next day when I again poweered on my VM and tried to take web access it gives me an error I have checked nagios service and process as well but no use I’m not able to get my web access
    any one can help…

  15. muhammad farooq on

    “” FACING PROBLEM WITH FOLLOWING ERROR”
    make[1]: Leaving directory `/opt/nagios-plugins-2.0.3/po’
    make[1]: Entering directory `/opt/nagios-plugins-2.0.3′
    make[2]: Entering directory `/opt/nagios-plugins-2.0.3′
    make[2]: Nothing to be done for `install-exec-am’.
    make[2]: Nothing to be done for `install-data-am’.
    make[2]: Leaving directory `/opt/nagios-plugins-2.0.3′
    make[1]: Leaving directory `/opt/nagios-plugins-2.0.3′
    [root@localhost nagios-plugins-2.0.3]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    bash: /usr/local/nagios/bin/nagios: No such file or directory
    <

  16. It works GREAT and thanks however, when i reboot the server nagios does not start back up.

    I have doen theis on CentOS 6.5 then 7 same results.

    Please help.

  17. Naresh Bhanushali on

    Hi Rahul,

    Recently, I just deleted my /etc/passwd and /etc/group file in my nagios server. Luckily, I restored it from the backup I had. But after that, I am not able to import data to remote nagios server over SSH/SFTP using nagiosql.
    I can login directly without password from local system to remote system, but getting error for permission check. I have also tried to change ownership to apache user and nagios user vice-versa. But no use. Do you have exact idea where should I be wrong going as unluckily, I had restarted the corrupted slave simnagios and due to that getting stale results.

      • Thanks for reply, but terminal was wrote: directory or file does not exist. In directory html/webadmin is created directory config.

        • Hi Hubalda,
          If you are talking about warning “setting file doesn’t exists”, Then no worry, Just continue to next if other issues are fixed. setting.php will automatically created by installer using input given.

  18. I’ve gone through all your steps several times and it still doesn’t work. I can navigate to the site “Settings file not found or not readable (config/settings.php). Upgrade not available!” When i click the Start installation it says “SSH2: Not Available”, “MySQL: Not Available”, “date.timezon: Not Available (cannot be empty and needs to be set)”, “Write test on settings directory (config/): failed”

    Now i’ve installed all of these programs and started/added to services. I’ve edited the php.ini file to have America/Denver as my timezone. I’ve disable the iptables to make sure somethings not being blocked.

    Do you have any input on how i can solve this. Any assistance would be much appreciated.

    • Hi Jon,

      1. make sure you have assigned privileges to apache user on config directory
      2. To install SSH2 use below commands.
      # yum install libssh2-devel libssh2

      # pecl install ssh2
      or
      # pecl install channel://pecl.php.net/ssh2-0.12

      3. For MysQL
      # yum install php-mysql

      I hope above steps will fix your issues.

      • Thank you for your reply. I’m still having issues getting pecl install ssh2 and pecl install channel://pecl.php.net/ssh2-0.12 installed. it gives me an error. ERROR: ‘phpize’ failed. If you have input it would be much appreciated.

        Thanks,

        Jon

          • So I’ve actually resolved the ssh2 issue now. But I’m now unable to get mysql to work. It says “MySQL: Not Available”.
            Now I’m quite sure i’ve installed everything properly. This only thing i’m questionable on is php-mysql. I’ve tried the yum install php-mysql with no success. It returns:

            Loaded plugins: fastestmirror, security
            Loading mirror speeds from cached hostfile
            * base: mirrors.usinternet.com
            * epel: linux.mirrors.es.net
            * extras: mirrors.xmission.com
            * updates: mirrors.easynews.com
            Setting up Install Process
            Resolving Dependencies
            –> Running transaction check
            —> Package php-mysql.x86_64 0:5.3.27-1.el6 will be installed
            –> Processing Dependency: php-pdo(x86-64) = 5.3.27-1.el6 for package: php-mysql-5.3.27-1.el6.x86_64
            –> Running transaction check
            —> Package php-pdo.x86_64 0:5.3.27-1.el6 will be installed
            –> Processing Dependency: php-common(x86-64) = 5.3.27-1.el6 for package: php-pdo-5.3.27-1.el6.x86_64
            –> Finished Dependency Resolution
            Error: Package: php-pdo-5.3.27-1.el6.x86_64 (CentALT)
            Requires: php-common(x86-64) = 5.3.27-1.el6
            Installed: php-common-5.4.19-1.el6.remi.x86_64 (@remi)
            php-common(x86-64) = 5.4.19-1.el6.remi
            Available: php-common-5.3.3-22.el6.x86_64 (base)
            php-common(x86-64) = 5.3.3-22.el6
            Available: php-common-5.3.3-23.el6_4.x86_64 (updates)
            php-common(x86-64) = 5.3.3-23.el6_4
            Available: php-common-5.3.27-1.el6.x86_64 (CentALT)
            php-common(x86-64) = 5.3.27-1.el6
            You could try using –skip-broken to work around the problem
            You could try running: rpm -Va –nofiles –nodigest

            So I’m not sure if its a installation problem or if i need to configure a file or something.

            Thanks,

            Jon Nelson

      • So I see that when I install MySQL it installs mariadb instead. Do you think this would be causing a linking error? Do you know why mariadb is installing instead of MySQL? I’m confused as to why this is being so much trouble.

        Thanks again!

        Jon

Reply To Jon Cancel Reply

Exit mobile version