nagios监控Linux主机


参考此文档 http://blog.csdn.net/xtdhqdhq/article/details/19197635(Nagios监控服务端与客户端的安装)

假设监控机:192.168.0.10 server1

被监控机:192.168.0.11 server2

此处简要的说明注意的几个点:

在server2上:

1、修改nrpe.cfg

监控主机的nagios是通过调用被监控机的nrpe来获取信息,那么我们先在被监控机的nrpe配置上添加要搜索的信息,也就是一些命令,然后nagios就通过nrpe调用这些命令来获取信息。这些命令是在nrpe.cfg文件中定义:

command[check_mysql_status]=/usr/local/nagios/libexec/check_mysql -H localhost -u nagios -p nagios -P 3306

2、启动nrpe服务

 

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3、测试下面命令是否能执行
/usr/local/nagios/libexec/check_mysql -H localhost -u nagios -p nagios -P 3306
在server1 上:
1、配置nagios监控主机的配置文件
 /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg     #nagios可调用的监控命令
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg     #联系人配置
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg  #监控时间配置
cfg_file=/usr/local/nagios/etc/objects/templates.cfg   #模板配置
cfg_dir=/usr/local/nagios/etc/servers                   #新添加的目录,把需要添加的主机文件放进去,就不必在这里一行行添加
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg   #新添加,主机组配置
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg    #本地信息监迭
2、利用nrpe监控server2主机的本地信

利用nrpe监控server2 主机的本地信息

首先是解决nagios怎么去调用nrpe命令,之前我们配置时有说过nagios调用的命令是从command.cfg文件中定义过的,那么要使用nrpe也须要在该文件中定义

nano command.cfg

在文件中添加以下配置

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

3、添加被监控机
创建server2的cfg文件在/usr/local/nagios/etc/servers目录下,并修改其
cp /usr/local/nagios/etc/objects/localhost.cfg  /usr/local/nagios/etc/servers/192.168.0.11.cfg
nano 192.168.0.11.cfg

# HOST DEFINITION
# Define a host for the local machine
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.0.11
        alias                   linux-server 11
        address                 192.168.0.11
        }

define service{
        use                             local-service         ; Name of service template to use
        host_name                       192.168.0.11
        service_description             MySQL
        check_command                   check_nrpe!check_mysql_status
 #       notifications_enabled           0
        }

 

4、创建hostgroups.cfg

注释掉localhost 中的hostgroup ,在此文件中同意定义

nano hostgroups.cfg

###############################################################################
###############################################################################
# HOST GROUP DEFINITION
###############################################################################
###############################################################################
# Define an optional hostgroup for Linux machines
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 hostgroup{
hostgroup_name linux-servers-jk ; The name of the hostgroup
alias Linux Servers Jk ; Long name of the group
members 192.168.0.11 ; Comma separated list of hosts that belong to this group
}
5、重启nagios

service nagios reload

参考文档:http://lihuipeng.blog.51cto.com/3064864/570698

相关内容