20309 发表于 2019-1-15 10:45:53

Nagios-Linux主机监控

  本文转自:http://www.yylog.org/?p=4282
  Nagios客户端配置
  安装nagios-plugins
  # groupadd nagios
  # useradd -g nagios nagios -s /sbin/nologin
  # tar -zxvf nagios-plugins-1.4.14.tar.gz
  # cd nagios-plugins-1.4.14
  # ./configure –prefix=/usr/local/nagios
  # make && make install
  安装nrpe
  # tar -zxvf nrpe-2.12.tar.gz
  # cd nrpe-2.12
  # ./configure
  # make all
  # make install-plugin
  # make install-daemon
  # make install-daemon-config
  # make install-xinetd
  # chown -R nagios.nagios /usr/local/nagios
  配置NRPE
  修改/etc/xinetd.d/nrpe 将only_from = 127.0.0.1指定为only_from = 192.168.1.66(Nagios服务器地址)
  # vi /etc/xinetd.d/nrpe
  # default: on
  # description: NRPE (Nagios Remote Plugin Executor)
  service nrpe
  {
  flags = REUSE
  socket_type = stream
  port = 5666
  wait = no
  user = nagios
  group = nagios
  server = /usr/local/nagios/bin/nrpe
  server_args = -c /usr/local/nagios/etc/nrpe.cfg –inetd
  log_on_failure += USERID
  disable = no
  only_from = 192.168.1.66
  }
  添加NRPE服务端口
  # vi /etc/services
  nrpe 5666/tcp # nrpe
  启动NRPE守护进程
  # /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
  # netstat -natp|grep 5666
  tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 21235/nrpe
  检查NRPE状态,返回版本信息则NRPE正常。
  # /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
  NRPE v2.12
  Nagios服务端配置
  # cd /usr/local/nagios/etc/objects/
  创建被监控主机配置文件
  # cp localhost.cfg 192.168.1.60.cfg
  修改192.168.1.60.cfg配置文件
  将192.168.1.60.cfg中localhost替换成192.168.1.60(被监控端主机IP),将hostgroup_name注释或将名称改为其他,不要和localhost.cfg重名。
  将address 127.0.0.1,修改为address 192.168.1.60。
  # vi 192.168.1.60.cfg
  define host{
  use linux-server ; Name of host template to use
  ; This host definition will inherit all variables that are defined
  ; in (or inherited by) the linux-server host template definition.
  host_name 192.168.1.60
  alias 192.168.1.60
  address 192.168.1.60
  }
  define hostgroup{
  # hostgroup_name linux-servers ; The name of the hostgroup
  alias Linux Servers ; Long name of the group
  members 192.168.1.60 ; Comma separated list of hosts that belong to this group
  }
  检查配置nagios配置文件
  # /usr/local/nagios/bin/nagios -v nagios.cfg
  最后重启nagios服务
  root@localhost etc]# service nagios restart
  Running configuration check…done.
  Stopping nagios: done.
  Starting nagios:This account is currently not available.
  done.
  访问nagios监控页面,此时nagios已经成功获取到被监控端的主机状态,如图:
http://www.yylog.org/wp-content/uploads/2012/08/nagios_20120809_01.png
http://www.yylog.org/wp-content/uploads/2012/08/nagios_20120809_02.png

页: [1]
查看完整版本: Nagios-Linux主机监控