vivion32 发表于 2019-1-14 12:50:37

部署Nagios监控系统(三)NRPE监控远程主机系统状况

  NRPE总共由两部分组成:
check_nrpe插件:运行在监控主机上 (即nagios主机)
NRPE daemon:运行在远程的linux主机上(通常就是被监控机)

  http://blog.运维网.com/attachment/201308/205007588.jpg
  当Nagios需要监控某个远程linux主机的服务或者资源情况时:
1、nagios运行check_nrpe插件,我们要在nagios配置文件中告诉它要检查什么。
2、check_nrpe插件会通过SSL连接到远程的NRPEdaemon。
3、NRPE daemon会运行相应的nagios插件来执行检查本地资源或服务。
4、NRPE daemon将检查的结果返回给check_nrpe插件,插件将其递交给nagios做处理。
注意:NRPE daemon需要nagios插件和Nrpe一起安装在远程被监控linux主机上,否则,daemon不能做任何的监控。 别外因为它们间的通信是加密的SSL,所以需要安装SSL,这个插件需要openssl的支持,没有就直接安装一下(yuminstall openssl-devel)。
  

  在被监控端安装nagios-plugins和nrpe
  1、创建nagios用户
  #useraddnagios
  2、编译安装nagios-plugins插件
  #./configure --with-nagios-user=nagios --with-nagios-group=nagios
  #make && make install
  3、检查xinetd是否安装,没有则安装(默认已安装)。
  #yum -y install xinetd
  4、编译安装nrpe
  #./configure
  #make all
  #make install-plugin
  
  #make install-daemon            //安装守护进程
  #make install-daemon-config   //安装配置文件
  #make install-xinetd            //安装xinetd脚本
  5、修改nrpe的配置文件,添加监控端的主机地址。修改内容如下:

  #vim /etc/xinetd.d/nrpe
  only_from = 127.0.0.1 192.168.10.100          //在后面增加监控主机(即nagios服务器)

  6、修改/etc/services文件,增加NRPE服务,修改内容如下:
  
  #vim /etc/services       //在该文件尾部添加如下行
  nrpe    5666/tcp   #nrpe
  7、修改nrpe.cfg配置文件,修改内容如下:
  #vim /usr/local/nagios/etc/nrpe.cfg
  http://blog.运维网.com/attachment/201308/230648382.jpg
  修改上图中的内容,修改后如下图所示:

  http://blog.运维网.com/attachment/201308/230859559.jpg
  并添加如下选项,如果默认有的话则不用添加,添加没有的项即可。
  
  command=/usr/local/nagios/libexec/check_users -w 5 -c 10
  command=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
  command=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
  command=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
  command=/usr/local/nagios/libexec/check_procs -w 150 -c 200
  command=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
  上面这5行定义的命令分别是检测登陆用户数,cpu负载,hda1的容量,僵尸进程,总进程数,SWAP分区的使用情况。

  如果需要检测其他信息可自行添加其他命令。
  8、开启xinetd服务,查看NRPE是否已经启动。

  http://blog.运维网.com/attachment/201308/231206376.jpg
  9、在本机测试上述配置命令是否有误,执行如下命令。
  #/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
  #/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
  #/usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1
  #/usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs
  #/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
  #/usr/local/nagios/libexec/check_nrpe -H localhost -c check_swap
  
此时客户端配置完成了,接着我们到nagios监控端进行配置。
  

  在监控端安装nrpe软件包(即nagios服务器)
  1、编译安装nrpe软件包
  
  #./configure --with-nagios-user=nagios --with-nagios-group=nagios
  #make all
  #make all && make install-plugin
  
  2、测试是否可以连接到被检测端。
http://blog.运维网.com/attachment/201308/231738905.jpg
  3、在nagios的commands.cfg文件中添加nrpe命令。
  #vim /usr/local/nagios/etc/objects/commands.cfg
  http://blog.运维网.com/attachment/201308/231836976.jpg
  4、在nagios的hosts.cfg文件中添加被监控端主机的相关信息。
  #vim /usr/local/nagios/etc/objects/hosts.cfg
  http://blog.运维网.com/attachment/201308/231924254.jpg
  5、在nagios的services.cfg文件中添加需要检测的服务。

  #vim /usr/local/nagios/etc/objects/services.cfg
  http://blog.运维网.com/attachment/201308/232142409.jpg
http://blog.运维网.com/attachment/201308/232153943.jpg
http://blog.运维网.com/attachment/201308/233631475.jpg
http://blog.运维网.com/attachment/201308/232218762.jpg
  6、执行“nagios -v”命令检测配置文件语法是否正确。

  #/usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg
  http://blog.运维网.com/attachment/201308/232526523.jpg
  7、重新加载nagios服务
  http://blog.运维网.com/attachment/201308/232621990.jpg
  8、访问nagios的web界面,可以发现能够监控指定服务器的运行情况。
  http://blog.运维网.com/attachment/201308/235903397.jpg
  

  

  

  

  

  

  




页: [1]
查看完整版本: 部署Nagios监控系统(三)NRPE监控远程主机系统状况