Skip to content

Instantly share code, notes, and snippets.

@evanjuang
Last active April 17, 2019 08:01
Show Gist options
  • Save evanjuang/d81ca6f05aa02e2d92ad68f5f867235c to your computer and use it in GitHub Desktop.
Save evanjuang/d81ca6f05aa02e2d92ad68f5f867235c to your computer and use it in GitHub Desktop.
[nagios - install on centos 7] #nagios

Nagios on CentOS 7

Install Nagios Core

  1. Install package
$ yum install wget httpd php glibc glibc-common gd gd-devel 
make net-snmp unzip openssl-devel gcc
  1. Add user
$ useradd nagios -p nagios
$ usermod -a -G nagios apache
  1. Install
$ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.4.tar.gz
$ tar zxvf nagios-4.2.4.tar.gz
$ cd nagios-4.2.4
$ ./configure
$ make all
$ make install
$ make install-init
$ make install-config
$ make install-commandmode
$ make install-webconf

Install Nagios Plugin

  1. Install package
$ yum install epel-release
$ yum install perl-Net-SNMP

$ yum install openssl-devel radiusclient-ng-devel libdbi libdbi-devel 
samba-devel libsmbclient-devel samba-client net-snmp-devel net-snmp-utils 
gnutls-devel openldap-devel postgresql-devel
  1. Install
$ wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz
$ tar zxvf nagios-plugins-2.1.4.tar.gz
$ cd nagios-plugins-2.1.4.tar.gz
$ ./configure
$ make
$ make install

Start Nagios

  1. Start service
    $ systemctl start nagios
    $ systemctl enable nagios
  2. Set firewall (TCP 80 port)
    $ firewall-cmd --add-service=http
    $ firewall-cmd --add-service=https
    $ firewall-cmd --reload
  3. Set password for Web administrator Default admin: nagiosadmin
    $ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  4. Start httpd
    $ systemctl start httpd
  5. Login to Web http://<ip>/nagios
  6. Set system time
    $ yum install chrony
    Add NTP server: server watch.stdtime.gov.tw
    $ vim /etc/chrony.conf
    
    $ timedatectl set-timezone "Asia/Taipei" 
    $ timedatectl set-ntp yes
    

Install NRPE(Nagios Remote Plugin Executor)

Remote Host

  1. Install package
    yum install openssl-devel gcc xinetd
  2. Update /etc/services
    $vim /etc/services
    add item
    nrpe            5666/tcp                # Nagios addon NRPE
    
  3. Intall Nagios Plugin
    $ yum install epel-release
    $ yum install perl-Net-SNMP
    $ yum install openssl-devel radiusclient-ng-devel libdbi 
    libdbi-devel samba-devel libsmbclient-devel net-snmp-devel 
    gnutls-devel openldap-devel postgresql-devel
    
    $ wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz
    $ tar zxvf nagios-plugins-2.1.4.tar.gz
    $ cd nagios-plugins-2.1.4/
    $ ./configure
    $ make
    $ make install
  4. Install NRPE
    $ wget https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.0.1.tar.gz
    $ tar zxvf tar zxvf nrpe-3.0.1.tar.gz
    $ cd nrpe-nrpe-3.0.1/
    $ ./configure
    $ make all
    $ make install
    $ make install-config
    $ make install-inetd
    $ make install-init
    $ make install-groups-users
  5. Start NRPE and xinetd
    $ systemctl restart xinetd
    $ systemctl enable nrpe
    $ systemctl start nrpe
  6. Check service If only tcp6, it's need to disable IPv6 function.
    $ netstat -at | egrep "nrpe|5666"
    tcp        0      0 0.0.0.0:nrpe            0.0.0.0:*               LISTEN
    tcp6       0      0 [::]:nrpe               [::]:*                  LISTEN
  7. Check command
    $ /usr/local/nagios/libexec/check_nrpe -H localhost
    NRPE v3.0.1
    $ /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
    USERS OK - 2 users currently logged in |users=2;5;10;0
  8. Update nrpe.cfg
    $ vim /usr/local/nagios/etc/nrpe.cfg
    Add allowed_hosts for nagios server(10.136.160.119)
    allowed_hosts=127.0.0.1
    allowed_hosts=10.136.160.119

Nagios Server

  1. Install NRPE
    $ wget https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.0.1.tar.gz
    $ tar zxvf tar zxvf nrpe-3.0.1.tar.gz
    $ cd nrpe-nrpe-3.0.1/
    $ ./configure
    $ make check_nrpe
    $ make install-plugin
  2. Check command for remote host
    $ /usr/local/nagios/libexec/check_nrpe -H 10.136.161.101 -c check_users
    USERS OK - 2 users currently logged in |users=2;5;10;0

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment