One of Nagios monitoring installations

Source: Internet
Author: User
Tags install perl

Configuring Nagios Monitoring System files
Nagios configuration file:
Nagios.cfg: Master profile, defining the name and location of various configuration files
CGI.CFG: Controlling the CGI configuration file
Resource.cfg: Resource file, define various variables so that other files can be called
Objects: Other configuration file directory, this directory is mainly:
COMMAND.CFG: Command configuration file, define various command formats for other file calls
Contacts.cfg: Contacts and groups, send messages and other alarm information can be called
LOCALHOST.CFG: Monitor the configuration file for this machine
TIMEPERIODS.CFG: A configuration file that defines the monitoring time for other file calls
Hostgroups.cfg: The host (group) that defines the monitoring needs to be created manually.

The relationship between configuration files

Several of the definitions involved in Nagios configuration include hosts, host groups, services, service groups, contacts, contact group, monitoring time, and monitoring commands.
As you can see from these definitions, Nagios's various profiles are interrelated and referenced to each other. Successfully configured a Nagios monitoring system with each configuration
The dependencies between files are dependent on the relationship, the most important of which is four points:
1, define monitoring of those hosts, host groups, services and service group
2, define what command to use for this monitor
3, define the time period for monitoring
4. Define the contacts and contact groups to notify when there is a problem with the host or server

Configure Nagios

In order to be able to explain the problem more clearly and for ease of maintenance, it is recommended that you create a separate configuration file for each of the Nagios defined objects.
Create a conf directory to define host hosts
Create a hostgroups.cfg file to define a host group
Define contacts and contact groups with the default Contacts.cfg file
Define the command with the default commands.cfg file
Define the monitoring time period with the default Timeperiods.cfg
Use the default Templetes.cfg file as a resource reference file
installation environment, software preparation:
CentOS Release 6.5 (Final)
Nagios-3.5.1.tar.gz
Nagios-plugins-1.4.16.tar.gz
Nrpe-2.12.tar.gz
Nagios-server 192.168.0.151 client:192.168.0.152,192.168.0.150
Pre-Installation Preparation:
1, configuring the Yum source
2, configuring environment variables
[Email protected] soft]# echo ' export lc_all=c ' >>/etc/profile
[Email protected] soft]# tail-1/etc/profile
Export Lc_all=c
[Email protected] soft]# Source/etc/profile
3, turn off firewall, SELINUX
[[email protected] soft]#/etc/init.d/iptables stop
[Email protected] soft]# chkconfig iptables off
[Email protected] soft]# sed-i ' s#selinux=enforcing#selinux=disabled#g '/etc/selinux/config
[Email protected] soft]# Setenforce 0
4. Configure Scheduled Tasks
[Email protected] soft]# CRONTAB-E
#time sync by Tony at 2018-01-29
/5 /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
5, install GCC and lamp environment
[[email protected] soft] #yum install gcc glibc glibc-common-y
[[email protected] soft] #yum install GD gd-devel-y
[[email protected] soft] #yum install httpd php php-gd-y
[[email protected] soft] #yum install MySQL
-Y
6, adding users and user groups
[Email protected] soft]#/usr/sbin/useradd-m Nagios
[Email protected] soft]#/usr/sbin/useradd Apache
[Email protected] soft]#/usr/sbin/groupadd nagcmd
[Email protected] soft]#/usr/sbin/usermod-a-G nagcmd Nagios
[Email protected] soft]#/usr/sbin/usermod-a-G nagcmd Apache
7, install Nagios-core
[Email protected] soft]# Tar XF nagios-3.5.1.tar.gz
[[email protected] soft] #cd Nagios
[Email protected] nagios]#/configure--with-command-group=nagcmd
[[email protected] nagios]# make all
[[email protected] nagios]# make install
[email protected] nagios]# make Install-init
[email protected] nagios]# make Install-config
[email protected] nagios]# make Install-commandmode
[email protected] nagios]# make install-webconf
8. Configure Web authentication:
[Email protected] nagios]# htpasswd-cb/usr/local/nagios/etc/htpasswd.users Tony Hwg123
Adding Password for user Tony
9. Installing the Nagios Plugin
[Email protected] soft]# yum-y install Perl-devel
[Email protected] soft]# Tar XF nagios-plugins-1.4.16.tar.gz
[Email protected] soft]# CD nagios-plugins-1.4.16
[Email protected] nagios-plugins-1.4.16]#/configure--with-nagios-user=nagios--with-nagios-group=nagios-- Enable-perl-modules
[[email protected] nagios-plugins-1.4.16] #make && make install
[[email protected] nagios-plugins-1.4.16] #cd. /
[Email protected] soft]# ls/usr/local/nagios/libexec/|wc-l
10, install Nrpe
[Email protected] soft]# Tar XF nrpe-2.12.tar.gz
[Email protected] soft]# CD nrpe-2.12
[Email protected] nrpe-2.12]#./configure
[[email protected] nrpe-2.12]# make all
[email protected] nrpe-2.12]# make Install-plugin
[email protected] nrpe-2.12]# make Install-daemon
[email protected] nrpe-2.12]# make Install-daemon-config
[Email protected] nrpe-2.12]# CD. /
11, start Nagios and HTTP
[[email protected] soft]#/etc/init.d/nagios start
[[email protected] soft]#/etc/init.d/httpd start
[[email protected] soft]# lsof-i: 80

Client Configuration:
1. Configure the Yum Source:
2. Configure Environment variables:
[Email protected] ~]# echo ' export lc_all=c ' >>/etc/profile
[Email protected] ~]# tail-1/etc/profile
Export Lc_all=c
[Email protected]lient ~]# source/etc/profile
3, turn off firewall, SELINUX
[[email protected] soft]#/etc/init.d/iptables stop
[Email protected] soft]# chkconfig iptables off
[Email protected] soft]# sed-i ' s#selinux=enforcing#selinux=disabled#g '/etc/selinux/config
[Email protected] soft]# Setenforce 0
4. Configure Scheduled Tasks
[Email protected] soft]# CRONTAB-E
#time sync by Tony at 2018-01-29
/5 */usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
5,
[Email protected] ~]#/usr/sbin/useradd-m nagios-s/sbin/nologin
6, upload the installation package
[Email protected] nagios-plugins-1.4.16]# yum-y install Perl-devel Perl-cpan
[Email protected] data]# Tar XF nagios-plugins-1.4.16.tar.gz
[Email protected] data]# CD nagios-plugins-1.4.16
[Email protected] nagios-plugins-1.4.16]#/configure--prefix=/usr/local/nagios--enable-perl-modules-- Enable-redhat-pthread-workaround
[[email protected] nagios-plugins-1.4.16]# make && make install
7,
[Email protected] nagios-plugins-1.4.16]# CD. /
[Email protected] data]# Tar XF nrpe-2.12.tar.gz
[Email protected] data]# CD nrpe-2.12
[Email protected] nrpe-2.12]#./configure
[[email protected] nrpe-2.12]# make all
[email protected] nrpe-2.12]# make Install-plugin
[email protected] nrpe-2.12]# make Install-daemon
[email protected] nrpe-2.12]# make Install-daemon-config
[Email protected] nrpe-2.12]# CD.
8, install plug-in monitoring disk IO
[Email protected] data]# Tar XF params-validate-0.91.tar.gz
[Email protected] data]# CD params-validate-0.91
[[email protected] params-validate-0.91] #perl makefile.pl
[[email protected] params-validate-0.91]# make
[[email protected] params-validate-0.91]# make install

[Email protected] data]# Tar XF class-accessor-0.31.tar.gz
[Email protected] data]# CD class-accessor-0.31
[Email protected] class-accessor-0.31]# Perl makefile.pl
[[email protected] class-accessor-0.31]# make
[[email protected] class-accessor-0.31]# make install

[Email protected] data]# Tar XF config-tiny-2.12.tar.gz
[Email protected] data]# CD config-tiny-2.12
[Email protected] config-tiny-2.12]# Perl makefile.pl
[[email protected] config-tiny-2.12]# make
[[email protected] config-tiny-2.12]# make install

[Email protected] data]# Tar XF math-calc-units-1.07.tar.gz
[Email protected] data]# CD math-calc-units-1.07
[Email protected] math-calc-units-1.07]# Perl makefile.pl
[[email protected] math-calc-units-1.07]# make
[[email protected] math-calc-units-1.07]# make install

[Email protected] data]# Tar XF regexp-common-2010010201.tar.gz
[Email protected] data]# CD regexp-common-2010010201
[Email protected] regexp-common-2010010201]# Perl makefile.pl
[[email protected] regexp-common-2010010201]# make
[[email protected] regexp-common-2010010201]# make install
[Email protected] regexp-common-2010010201]# CD.

[Email protected] data]# Tar XF nagios-plugin-0.34.tar.gz
[Email protected] data]# CD nagios-plugin-0.34
[Email protected] nagios-plugin-0.34]# Perl makefile.pl
[[email protected] nagios-plugin-0.34]# make
[[email protected] nagios-plugin-0.34]# make install

[email protected] data]# Yum install sysstat-y
[Email protected] data]#/BIN/CP./check_memory.pl/usr/local/nagios/libexec
[Email protected] data]#/BIN/CP./check_iostat/usr/local/nagios/libexec
[Email protected] data]# chmod 755/usr/local/nagios/libexec/check_memory.pl
[Email protected] data]# chmod 755/usr/local/nagios/libexec/check_iostat
[Email protected] data]# dos2unix/usr/local/nagios/libexec/check_memory.pl
[Email protected] data]# Dos2unix/usr/local/nagios/libexec/check_iostat

[email protected] etc]# CP nrpe.cfg Nrpe.cfg.ori
[Email protected] etc]# sed-i ' 199,203d '/usr/local/nagios/etc/nrpe.cfg
[[email protected] etc] #echo "command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,6-c 30,25,20" > >/usr/local/nagios/etc/nrpe.cfg
[[email protected] etc] #echo "command[check_mem]=/usr/local/nagios/libexec/check_memory.pl-w 6%-C 3%" >>/usr/ Local/nagios/etc/nrpe.cfg
[[email protected] etc] #echo "command[check_disk]=/usr/local/nagios/libexec/check_disk-w 20%-C 8%-P/" >>/usr/ Local/nagios/etc/nrpe.cfg
[[email protected] etc] #echo "command[check_swap]=/usr/local/nagios/libexec/check_swap-w 20%-C 10%" >>/usr/ Local/nagios/etc/nrpe.cfg
[email protected] etc] #echo "command[check_iostat]=/usr/local/nagios/libexec/check_iostat-w 6-c" >>/usr/ Local/nagios/etc/nrpe.cfg
[Email protected] ~]# Pkill Nrpe
[[email protected] ~]# sleep 2
[Email protected] ~]#/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d
[Email protected] ~]# echo "#nagios Nrpe process cmd by Tony 2018-2-2" >>/etc/rc.local
[Email protected] ~]# echo "/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d" >>/etc/rc.local
[Email protected] ~]# netstat-lnt|grep 5666 && echo "Nagios client is OK"
TCP 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
Nagios client is OK

Third, configure the server-side Nagios monitoring service
[Email protected] ~]# ll/usr/local/nagios/
Total 32
Drwxrwxr-x 2 Nagios nagios 4096 Feb 1 22:33 bin #可执行文件
Drwxrwxr-x 3 Nagios nagios 4096 Feb 8 14:25 etc #Nagios主要配置文件
Drwxr-xr-x 2 root root 4096 Feb 1 22:25 include
Drwxrwxr-x 2 Nagios nagios 4096 Feb 1 22:32 libexec
Drwxr-xr-x 5 root root 4096 Feb 1 22:25 perl
Drwxrwxr-x 2 Nagios nagios 4096 Feb 1 22:09 sbin #cgi程序
Drwxrwxr-x Nagios nagios 4096 Feb 1 22:25 share #Nagios展示程序PHP
Drwxrwxr-x 5 Nagios nagios 4096 Feb 8 21:57 var #数据及日志文件

[Email protected] etc]# vim nagios.cfg
Cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
Cfg_file=/usr/local/nagios/etc/objects/services.cfg
Cfg_file=/usr/local/nagios/etc/objects/services

Definitions for monitoring the local (Linux) host

#cfg_file =/usr/local/nagios/etc/objects/localhost.cfg
1, host Services
[Email protected] objects]# vim hosts.cfg
Define Host{
Use Linux-server
HOST_NAME 152-nfs
Alias 152-nfs
Address 192.168.0.152
}
Define Host{
Use Linux-server
HOST_NAME 151-nagios
Alias 152-nagios
Address 192.168.0.151
}

Define an optional HostGroup for Linux machines

Define Hostgroup{
Hostgroup_name linux-servers
Alias Linux Servers
Members 152-nfs,151-nagios
}

2, service configuration
[Email protected] objects]# vim services.cfg
Define Service {
Use Generic-service
HOST_NAME 152-nfs
Service_description Disk Partition
Check_command check_nrpe! Check_disk

              }

Define Service {
Use Generic-service
HOST_NAME 152-nfs
Service_description Swap useage
Check_command check_nrpe! Check_swap

              }

Define Service {
Use Generic-service
HOST_NAME 152-nfs
Service_description MEM useage
Check_command check_nrpe! Check_mem

              }

Define Service {
Use Generic-service
HOST_NAME 151-nagios
Service_description Disk Partition
Check_command check_nrpe! Check_disk

              }

Define Service {
Use Generic-service
HOST_NAME 151-nagios
Service_description Swap useage
Check_command check_nrpe! Check_swap

              }

Define Service {
Use Generic-service
HOST_NAME 151-nagios
Service_description MEM useage
Check_command check_nrpe! Check_mem

              }

3, command configuration
[Email protected] objects]# vim commands.cfg
Add the content at the end of the configuration file
# ' Check_nrpe ' command definintion
Define Command{
Command_name Check_nrpe
Command_line $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ARG 1$
}

One of Nagios monitoring installations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.