Introduction
Nagios is a monitoring tool under GPL licence. This tool lets you monitor servers, network hardware (switches, routers, ...) and applications. A lot of plugins are available and its big community makes Nagios the biggest open source monitoring tool. This tutorial shows how to install Nagios 4.0.2 on CentOS 6.5.
Note: you should config postfix mail running correctly first. please setup NTP for time synchronization Prerequisites
Make sure you've set the hostname correctly, otherwise to modify /etc/sysconfig/network file.
After installing your CentOS server, you have to disable selinux & install some packages to make nagios work.
To disable selinux, open the file: /etc/selinux/config
# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive // change this value to disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted Now, download all packages you need:
# yum -y install gd gd-devel httpd php gcc glibc glibc-common make net-snmp net-snmp-devel net-snmp-utils openssl-devel mysql-devel (使用check_mysql所需) openssh-clients (使用check_by_ssh所需)
Next, add apache user to the nagios group.
[root@tecmint]# usermod -G nagios apache
Nagios Installation
Create a directory:
# mkdir /root/nagios
Navigate to this directory:
# cd /root/nagios
Download nagios-core & plugin:
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.2.tar.gz.
# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.5.tar.gz
Untar nagios core:
# tar xvzf nagios-4.0.2.tar.gz
Go to the nagios dir:
# cd nagios
Configure before make:
# ./configure --with-command-group=nagios --enable-nanosleep --enable-event-broker
Make all necessary files for Nagios:
# make all
Installation:
# make install
# make install-init
# make install-commandmode
# make install-config
Open the “contacts.cfg” file with your choice of editor and set the email address associated with the nagiosadmin contact definition to receiving email alerts.
# vi /usr/local/nagios/etc/objects/contacts.cfg
# make install-webconf
Create a password to log into the web interface:
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
chown nagios.nagios /usr/local/nagios/etc/htpasswd.users Note: more users can be added with htpasswd /usr/local/nagios/etc/htpasswd.users username, this username should be matched with contacts in the contacts.cfg
Now, you have to install the plugins:
# cd ..
# tar xvzf nagios-plugins-1.5.tar.gz
# cd nagios-plugins-1.5
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
Start the service and start it on boot:
# chkconfig --add nagios
# chkconfig --level 35 nagios on
# chkconfig --level 35 httpd on
vi /etc/hosts to add ip_address and hostname
vi /etc/httpd/conf/httpd.conf to modify "ServerName"
touch /var/www/html/index.html to avoid get localhost HTTP error “Nagios HTTP WARNING: HTTP/1.1 403 Forbidden”
# service nagios start
# service httpd start
Now, connect to your nagios system:
http://Your-Nagios-IP/nagios and enter login : nagiosadmin & password you have chosen above.
And after the installation ?
After the installation you have to configure all your host & services in nagios configuration files.This step is performed in command line and is complicated, so I recommand to install tool like Centreon, that is a beautiful front-end to add you host & services.
Install NRPE: On Remote Linux Host:
1. yum -y install gcc glibc glibc-common gd gd-devel make net-snmp net-snmp-devel net-snmp-utils openssl-devel mysql-devel (使用check_mysql所需)
iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
service iptables save On Monitoring Host:
1. cd /root/nagios
wget http://garr.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar xzf nrpe-2.15.tar.gz
2. cd nrpe-2.15
./configure
make all
make install-plugin