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



發佈了55 篇原創文章 · 獲贊 5 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章