`
丶安颜丨
  • 浏览: 16514 次
  • 性别: Icon_minigender_1
  • 来自: 淮安
社区版块
存档分类
最新评论

基于nagios的监控环境(一):Nagios监控基本环境安装

阅读更多

本文原创,转载请注明出处:

http://teartao.iteye.com/blog/2173109

相关附件下载链接:

链接: http://pan.baidu.com/s/1pJODHvd 密码: ygs9(选中文本可见)

一、说明

nagios相关的说明,网上很多,这里不作赘述,网上很多教程中也有介绍,也可以下载官网的pdf,本文主要介绍nagios的简单工作原理、安装步骤以及安装过程中遇到的一些问题。

本文为个人学习记录,仅供参考,如有错误,还望批评指正


二、Nagios简单工作原理

nagios的监控分为监控端(Monitor Server)和被监控端(Remote Server)。监控端安装nagios core,它本身没有监控功能,在监控过程中nagios core仅为一个平台,或者说是一个环境,在nagios core环境下,通过安装各种各样的插件(nagios plugins)来实现对机器的监控。

 

nagios plugins 有的自带远程监控功能,有的只有本地监控的功能,这时,我们可以通过nrpe来实现对远程机进行监控,nrpe又分为check_nrpe插件 和nrpe daemon两部分,监控机安装check_nrpe,被监控机安装nrpe daemon。监控机执行check_nrpe向被监控机请求相应的监控信息,被监控机上的nrpe daemon来调用本地的nagios plugins对本机进行监控,并将监控结果返回给监控机。

 

详细工作原理及说明请自行百度、google、访问官网,资料很多

三、监控环境安装

1、监控机安装

1)nagios core安装

#用yum命令安装系统组建以满足插件的安装环境
yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp
#创建nagios用户、用户组,并将nagios加入到相应组
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

#进入下载的nagios core文件目录,解压文件,进入解压目录
#cd /home/taolei/copy/pkg/
#【nagios core install】
rm -rf nagios-4.0.8
tar zxvf nagios-4.0.8.tar.gz
cd nagios-4.0.8

#编译安装
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

#拷贝文件至nagios安装目录
rm -rf /usr/local/nagios/libexec/eventhandlers/
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

#改变文件夹属主,使nagios插件可以获得权限
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

#nagios安装已完成,检查nagios配置文件正确性
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#启动相关服务:nagios服务和apache的服务
/etc/init.d/nagios restart
/etc/init.d/httpd restart

#用apache的命令,创建web访问的用户及密码
htpasswd -bc /usr/local/nagios/etc/htpasswd.users nagiosadmin admin


#此时可以在浏览器输入http://ip/nagios 登录nagios页面,通过登录认证后便可以查看nagios的监控情况了
#如:http://localhost/nagios

 

2)nagios plugins安装

监控机其实无需安装nagios plugins ,这里安装只是为了检测nagios core是否安装正确

进入安装包所在目录,解压并进入解压文件夹
cd /home/taolei/copy/pkg/
rm -rf nagios-plugins-2.0.3
tar zxvf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3

#编译安装nagios plugins
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
make
make install

#为服务设置开机启动
chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --add httpd
chkconfig --level 35 httpd on

 

3)check_nrpe安装

用yum命令安装系统组建以满足插件的安装环境
yum -y install openssl-devel
#cd /home/taolei/copy/pkg/

#进入安装包所在目录,解压并进入解压文件夹
rm -rf nrpe-2.15
tar zxvf nrpe-2.15.tar.gz
cd nrpe-2.15

#编译安装
./configure
make all
make install-plugin
     
#开启防火墙端口,以便远程的被监控机访问(这里是为了本机测试使用)
/sbin/iptables -I INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
#保存防火墙配置:
/etc/rc.d/init.d/iptables save
#重启防火墙
/etc/rc.d/init.d/iptables restart

#通过监测命令测试check_nrpe插件检查插件版本来反映插件是否安装完成
#假设本监控机IP 192.168.52.132,被监控机(远程机)ip为192.168.52.131
#本机开启了防火墙的端口号可以通过如下命令检查本地插件版本
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

#若已有远程机安装了nrpe daemon 则可以使用如下命令检查远程机nrpe版本
/usr/local/nagios/libexec/check_nrpe -H 192.168.52.131
#当返回了nrpe 版本信息时说明check_nrpe安装正确,若提示connect refused之类信息,则说明远程机#的nrpe防火墙或端口没开启,或有其它原因我没遇到过

 

2、被监控机安装

1)nagios plugins安装:同上

2)nrpe daemon安装

yum -y install openssl-devel xinetd
chown nagios:nagios /usr/local/nagios
chown -R nagios:nagios /usr/local/nagios/libexec
 
tar zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
 
#编辑/etc/xinetd.d/nrpe文件
nano /etc/xinetd.d/nrpe
 
#在only_from 后面加上nagios core所在的监控机ip,与前一ip之间用空白隔开
#only_from       = 127.0.0.1 <nagios_ip_address>  ,如:
#only_from       = 127.0.0.1 129.168.52.132
 
#编辑/etc/services 文件
nano /etc/services
 
#在其中加入NRPE端口的配置
nrpe            5666/tcp                        # NRPE
 
#开启防火墙5666端口
    /sbin/iptables -I INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
 
#保存防火墙配置:
    /etc/rc.d/init.d/iptables save
 
#编辑nrpe.cfg文件
    nano /usr/local/nagios/etc/nrpe.cfg
 
#找到allowed_hosts = 127.0.0.1,在后面加入监控机的ip,如:
    allowed_hosts = 127.0.0.1,192.168.52.132

 

 3、常见问题解决

【问题描述】按照NRPE官方安装文档的步骤安装nrpe daemon输入make all命令时,提示

make: *** No rule to make target `all'.  Stop.

【解决方法】安装openssl-devel:yum -y install openssl-devel

重新执行./configure命令后,再执行make all命令,即可解决

 

【问题描述】按照官方文档步骤,输入/usr/local/nagios/libexec/check_nrpe -H localhost命令时,报错提示:CHECK_NRPE: Error - Could not complete SSL handshake.

【解决方法】将localhost也添加至/etc/xinetd.d/nrpe文件中的only_from=后面,即

only_from  = 127.0.0.1 localhost

 

【问题描述】按照NRPE安装文档的步骤输入iptables -I RH-Firewall-1-INPUT -p tcp -m tcp –dport 5666 -j ACCEPT命令时报错

【解决方法】官方文档中上述命令书写有误,改为/sbin/iptables –I INPUT -p tcp -m tcp --dport 5666 -j ACCEPT 即可 

 

check_linux_status.pl安装

【问题描述】make test报错Can't locate Time/HiRes.pm in @INC.....

【解决方法】yum -y  install perl-Time-HiRes    安装perl相关插件

 

 

修改配置文件nrpe.cfg后需要重启nrpe,否则配置不会生效,重启方法如下

pkill nrpe;
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics