三、配置nagios监控本机
[root@servera ~]# cat /etc/nagios/objects/localhost.cfg |grep -v ^# |grep -v ^$
define host{
use linux-server
host_name localhost
alias nagios监控器
address 127.0.0.1
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members localhost ; Comma separated list of hosts that belong to this group
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description PING
check_commandcheck_ping!100.0,20%!500.0,60%
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Root Partition
check_commandcheck_local_disk!20%!10%!/
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Users
check_commandcheck_local_users!20!50
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Total Processes
check_commandcheck_local_procs!250!400!RSZDT
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Load
check_commandcheck_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Swap Usage
check_commandcheck_local_swap!20!10
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_commandcheck_ssh
notifications_enabled0
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_commandcheck_http
notifications_enabled0
}
[root@servera objects]# service nagios start
[root@servera objects]# nagios -v /etc/nagios/nagios.cfg 四、配置nagios监控远程主机
在这里,我们被监控的主机为serverb这台服务器,ip地址为172.25.0.11。
NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序。通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等。我们将Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端。
Nagios监控远程主机的方法有多种,其方式包括SNMP、NRPE、SSH、NCSA等。Nagios官方推荐监控主机使用NRPE方式,而监控设备使用SNMP方式。
NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行监测命令的守护进程,它用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果返回给监控端。而其执行的开销远低于基于SSH的检测方式,而且检测过程不需要远程主机上的系统账号信息,其安全性也高于SSH的检测方式。
[root@serverb nagios]# yum -y localinstall nagios-plugins-2.0.3-1.el7.x86_64.rpm nrpe-2.15-2.el7.x86_64.rpm
[root@serverb ~]# yum -y install openssl-devel