Nagios监控安装之一
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nagios监控安装之一相关的知识,希望对你有一定的参考价值。
配置nagios监控系统文件
Nagios的配置文件:
Nagios.cfg:主配置文件,定义各种配置文件的名称和位置
Cgi.cfg:控制CGI的配置文件
Resource.cfg:资源文件,定义各种变量,以便于其他文件调用
Objects:其他配置文件存放目录,此目录下主要有:
Command.cfg:命令配置文件,定义各种命令格式,以备其他文件调用
contacts.cfg:联系人和组,发邮件等告警信息时可以调用
localhost.cfg:监控本机的配置文件
timeperiods.cfg:定义监控时间的配置文件,便于其他文件调用
Hostgroups.cfg:定义监控的主机(组),需手动创建。
配置文件之间的关系
在nagios的配置过程中涉及的几个定义有主机、主机组、服务、服务组、联系人、联系人组、监控时间和监控命令等。
从这些定义可以看出,nagios各个配置文件之间互为关联、彼此引用的。成功配置出一台nagios监控系统,每个配置
文件之间依赖与被依赖的关系,最重要的有四点:
1,定义监控那些主机,主机组,服务和服务组
2,定义这个监控要用什么命令实现
3,定义监控的时间段
4,定义主机或服务器出现问题时要通知的联系人和联系人组
配置nagios
为了能更清楚的说明问题,同时也为了维护方便,建议将nagios各个定义的对象创建独立的配置文件。
创建conf目录来定义host主机
创建hostgroups.cfg文件来定义主机组
用默认的contacts.cfg文件来定义联系人和联系人组
用默认的commands.cfg文件来定义命令
用默认的timeperiods.cfg来定义监控时间段
用默认的templetes.cfg文件作为资源引用文件
安装环境、软件准备:
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
正式安装前准备:
1,配置YUM源
2,配置环境变量
[[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,关闭防火墙、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,配置定时任务
[[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,安装gcc和lamp环境
[[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,添加用户和用户组
[[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,安装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,配置web认证:
[[email protected] nagios]# htpasswd -cb /usr/local/nagios/etc/htpasswd.users tony hwg123
Adding password for user tony
9,安装Nagios插件
[[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,安装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,启动Nagios和Http
[[email protected] soft]# /etc/init.d/nagios start
[[email protected] soft]# /etc/init.d/httpd start
[[email protected] soft]# lsof -i :80
客户端配置:
1,配置YUM源:
2,配置环境变量:
[[email protected] ~]# echo ‘export LC_ALL=C‘>> /etc/profile
[[email protected] ~]# tail -1 /etc/profile
export LC_ALL=C
[[email protected] ~]# source /etc/profile
3,关闭防火墙、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,配置定时任务
[[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,上传安装包
[[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,安装插件监控磁盘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 10">>/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
第三,配置server端Nagios监控服务
[[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 11 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,主机服务
[[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,服务配置
[[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,命令配置
[[email protected] objects]# vim commands.cfg
在配置文件结尾加上这些内容
#‘check_nrpe ‘command definintion
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
以上是关于Nagios监控安装之一的主要内容,如果未能解决你的问题,请参考以下文章