Minggu, 24 Maret 2019

How to Install and Configure Nagios on CentOS


Nagios is one of the most popular open source monitoring systems. Nagios keeps an inventory of your entire IT infrastructure and ensures your networks, servers, applications, services, and processes are up and running. In case of failure or suboptimal performance Nagios will send notification alerts via various methods.

This tutorial describes how to install and configure Nagios Core on a CentOS 6 and CentOS 7 server.

Prerequisites

Disable SELinux or set in permissive mode as instructed here.

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

Update your CentOS system and install Apache, PHP and all the packages necessary to download and compile the Nagios main application and Nagios plugins:

# yum update
# yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget
# yum install make gettext autoconf net-snmp-utils epel-release perl-Net-SNMP postfix unzip automake


Installing Nagios on CentOS

Perform the following steps to install the latest version of Nagios Core from source.

  1. Downloading Nagios

    We’ll download Nagios source in the /usr/src directory which is the common location to place source files.

    Navigate to the directory with:

    # cd /usr/src/

    Download the latest version of Nagios from the project Github repository using the following wget command:

    # wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.3.tar.gz
    # tar xzf nagioscore.tar.gz

    Before continuing with the next steps, make sure you change to the Nagios source directory by typing:

    # cd nagioscore-nagios-4.4.3/


  2. Compiling Nagios

    To start the build process run the configure script which will perform a number of checks to make sure all of the dependencies on your system are present:

    # ./configure
    # make all


  3. Creating Nagios User And Group

    Create a new system nagios user and group by issuing:

    # make install-groups-users

    Add the Apache apache user to the nagios group:

    # usermod -a -G nagios apache


  4. Installing Nagios Binaries

    Run the following command to install Nagios binary files, CGIs, and HTML files:

    # make install


  5. Creating External Command Directory

    Nagios can process commands from external applications. Create the external command directory and set the proper permissions by typing:

    # make install-commandmode


  6. Install Nagios Configuration Files

    Install the sample Nagios configuration files with:

    # make install-config


  7. Install Apache Configuration Files

    Run the command below to install the Apache web server configuration files:

    # make install-webconf


  8. Creating Service and Daemon httpd

    ===== CentOS 6.x | RHEL 6.x | Oracle Linux 6.x =====

    # make install-daemoninit
    # chkconfig --level 2345 httpd on

    ===== CentOS 7.x | RHEL 7.x | Oracle Linux 7.x =====

    # make install-daemoninit
    # systemctl enable httpd.service


  9. Creating User Account

    To be able to access the Nagios web interface wel’ll create an admin user called nagiosadmin, Run the following htpasswd command to create a user called nagiosadmin

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

    You will be prompted to enter and confirm the user’s password.

    Restart the Apache service for changes to take effect :

    ===== CentOS 6.x | RHEL 6.x | Oracle Linux 6.x =====

    # service httpd restart

    ===== CentOS 7.x | RHEL 7.x | Oracle Linux 7.x =====

    # systemctl restart httpd


  10. Configuring Firewall

    The firewall will secure your server against unwanted traffic.

    You need to allow port 80 inbound traffic on the local firewall so you can reach the Nagios Core web interface.

    ===== CentOS 6.x | RHEL 6.x | Oracle Linux 6.x =====

    # iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
    # service iptables save
    # ip6tables -I INPUT -p tcp --destination-port 80 -j ACCEPT
    # service ip6tables save

    ===== CentOS 7.x | RHEL 7.x | Oracle Linux 7.x =====

    # firewall-cmd --zone=public --add-port=80/tcp
    # firewall-cmd --zone=public --add-port=80/tcp --permanent


Installing Nagios Plugins

Switch back to the /usr/src directory:

# cd /usr/src/

Download the latest version of the Nagios Plugins from the project Github repository:

# wget -O nagios-plugins.tar.gz http://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

When the download is complete extract the tar file:

# tar zxf nagios-plugins.tar.gz

Change to the plugins source directory:

# cd nagios-plugins-2.2.1

Run the following commands one by one to compile and install the Nagios plugins:

# ./configure
# make
# make install


Starting Nagios

Now that both Nagios and its plugins are installed, start the Nagios service with:

===== CentOS 6.x | RHEL 6.x | Oracle Linux 6.x =====

# service nagios start
# chkconfig --level 2345 nagios on

===== CentOS 7.x | RHEL 7.x | Oracle Linux 7.x =====

# systemctl start nagios.service
# systemctl enable nagios.service


Accessing the Nagios Web Interface

To access the Nagios web interface open your favorite browser and type your server’s domain name or public IP address followed by /nagios:

http(s)://your_domain_or_ip_address/nagios

Enter the nagiosadmin user login credentials and you will be redirected to the default Nagios home page as shown on the image below:


Conclusion

You have successfully installed the latest Nagios version from source on your CentOS system.


Tidak ada komentar: