參考此文檔 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
/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主機的本地信息
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