2.2 nagios 监控客户端

2017-06-12

nagios 监控客户端

配置客户端

安装 epel 扩展源

[root@localhost ~]# yum install -y epel-release

安装 nagios 以及 nagios-plugins

[root@localhost ~]# yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

编辑配置文件

[root@localhost ~]# vim /etc/nagios/nrpe.cfg

找到“allowed_hosts=127.0.0.1”改为“allowed_hosts=127.0.0.1,192.168.56.133”后面的 ip 为服务端 ip

找到“dont_blame_nrpe=0”改为“dont_blame_nrpe=1”

allowed_hosts=127.0.0.1,192.168.56.133
dont_blame_nrpe=1

启动客户端

[root@localhost ~]# /etc/init.d/nrpe start
Starting nrpe:                                             [确定]

服务端配置:(!!!服务端操作)

客户端 ip 为 192.168.56.128,下面定义子配置文件。

[root@localhost ~]# cd /etc/nagios/conf.d/
[root@localhost conf.d]# vim 192.168.56.128.cfg
define host{
   use            linux-server
   host_name      192.168.56.128
   alias          56.128
   address        192.168.56.128
}
define service{
   use            generic-service
   host_name      192.168.56.128
   service_description   check_ping
   check_command  check_ping!100.0,20%!200.0,50%
   max_check_attempts 5
   normal_check_interval 1
}
define service{
   use            generic-service
   host_name      192.168.56.128
   service_description   check_ssh
   check_command   check_ssh
   max_check_attempts  5
   normal_check_interval  1
   notification_interval  60
}
define service{
   use            generic-service
   host_name      192.168.56.128
   service_description   check_http
   check_command     check_http
   max_check_attempts   5
   normal_check_interval  1
}

说明:“max_check_attempts 5”表示,当 nagios 检测到问题时,一共尝试检测 5 次都有问题才会告警,如果该数值为 1,那么检测到问题就立即告警。“normal_check_interval 1”表示,重新检测的时间间隔,单位是分钟,默认是 3 分钟。“notification_interval 60”表示,在服务出现异常后,故障一直没有解决,nagios 再次对使用者发出通知的时间,单位是分钟。如果认为所有的事件只需要一次通知就够了,可以把这里的选项设为 0。

以上服务不依赖客户端 nrpe 服务,比如我们在自己电脑上可以使用 ping 或者 telnet 探测远程任何一台机器是否存活、是否开启某个端口或服务。而当检测客户端上的某个具体服务的情况时,就需要借助于 nrpe 了,比如想知道客户端机器的负载或磁盘使用情况。

编辑完配置文件后,在服务端重启一下 nagios 服务。

[root@localhost conf.d]# service nagios restart
Running configuration check...done.
Stopping nagios: .done.
Starting nagios: done.

然后在浏览器中访问 nagios,刷新会多出来一个主机,并且多出来三个服务。

wKiom1d6Wq3gKEFoAAEKqm_cKEI365.png

只不过这三个服务并不是我们想要的,我想要监控负载和磁盘使用率等服务,这时候就要使用 nrpe 服务了。继续在服务端添加服务。

(!!!服务端操作)

编辑配置文件

[root@localhost ~]# vim /etc/nagios/objects/commands.cfg

增加:

define command{
        command_name   check_nrpe
        command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

继续编辑

[root@localhost ~]# vim /etc/nagios/conf.d/192.168.56.128.cfg
define service{
   use            generic-service
   host_name      192.168.56.128
   service_description  check_load
   check_command    check_nrpe!check_load
   max_check_attempts   5
   normal_check_interval   1
}
define service{
   use            generic-service
   host_name      192.168.56.128
   service_description  check_disk_hda1
   check_command    check_nrpe!check_hda1
   max_check_attempts  5
   normal_check_interval  1
}
define service{
   use            generic-service
   host_name      192.168.56.128
   service_description check_disk_hda2
   check_command   check_nrpe!check_hda2
   max_check_attempts  5
   normal_check_interval  1
}

说明:“check_nrpe!check_load”这里的 check_nrpe 就是在 commands.cfg 刚刚定义的,check_load 是远程主机上的一个检测脚本。

(!!!以下客户端操作)

在远程主机上编辑 nrpe.cfg 配置文件

[root@localhost ~]# vim /etc/nagios/nrpe.cfg

找到 check_load 这一行,这行就是在客户端上要执行的脚本。然后把 check_hda1 更改一下:/dev/hda1 改为 /dev/sda1。再加一行检测 sda2 的语句。

command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
command[check_hda2]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2

客户端重启 nrpe 服务

[root@localhost ~]# service nrpe restart
Shutting down nrpe:                                        [确定]
Starting nrpe:                                             [确定]

服务端重启 nagios 服务

[root@localhost ~]# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

浏览器刷新,又有三个服务出来,稍等一会儿就能看到状态了。
wKioL1d6WtySI3HNAAFIuWhtdfI611.png

wKiom1d6WtyAaQnEAAFUd0j5tgE245.png


标题:2.2 nagios 监控客户端
作者:散宜生
地址:https://17kblog.com/articles/2017/06/12/1497262292876.html