1. 簡介
1.1設計概覽
NRPE擴展插件包含兩個部分:
a)check_nrpe插件,在監測主機上運行
b)NRPE守護進程,運行在遠程機器上,用於監測遠程Linux/Unix機器
當Nagios需要監測遠程主機的服務資源時:
a)Nagios將執行check_nrpe插件並告訴它需要監測的服務
b)check_nrpe插件通過受保護的加密方式(可選)來連接遠程主機上的NRPE守護進程
c)NRPE守護進程通過運行相應的Nagios插件來監測本機上的服務或資源
d)來自NRPE守護進程的服務監測結果被反饋給監測主機上的check_nrpe插件,這一監測結果表示Nagios進程的監測結果。
注意:NRPE守護進程要求遠程Linux/Unix主機必須安裝Nagios插件,否則,守護進程發揮不了任何作用。
2. 安裝過程
2.1前提條件
爲了完成以下安裝操作,你必須要:
a)以root身份來訪問遠程Linux/Unix主機
b)以nagios用戶賬戶來訪問監測主機
2.2在遠程主機上的操作:
2.2.1 創建用戶
/usr/sbin/useradd nagios –s /sbin/nologin
passwd nagios
2.2.2 下載安裝Nagio插件
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
2.2.3 解壓
tar xvf nagios-plugins-2.0.tar.gz
cd nagios-plugins-2.0
2.2.4 編譯安裝
./configure && make && makeinstall
2.2.5 修改目錄權限
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios/usr/local/nagios/libexec
2.2.6 安裝xinetd
yum install xinetd
2.2.7 安裝NRPE服務
#解壓
tar xvf nrpe-2.15.tar.gz
cd nrpe-2.15
2.2.8 編譯安裝
./configure
make all
2.2.9 安裝NRPE插件(測試用),服務,以及一些簡單的配置文件樣例
make install-plugin
make install-daemon
make install-daemon-config
2.2.10 安裝NRPE進程爲xinetd的一個服務
make install-xinetd
2.2.11 編輯/etc/xinetd.d/nrpe文件,添加監測服務器的IP地址和本機IP地址
vim /etc/xinetd.d/nrpe
only_from = 127.0.0.1<nagios_ip_address>
#我修改的內容如下(逗號之間沒有空格)
only_from =127.0.0.1,10.10.54.111,10.10.54.112
2.2.12 在/etc/services文件中添加NRPE進程的端口號
vim /etc/services
nrpe 5666/tcp # NRPE
2.2.13 重啓xinetd服務
service xinetd restart
2.2.14 測試本地NRPE進程
netstat -at | grep nrpe #顯示下面的結果是正確的
tcp 0 0 *:nrpe *:* LISTEN
如果不正確,請確定您已經完成了一下內容:
– You added the nrpe entry to your /etc/services file
– The only_from directive in the /etc/xinetd.d/nrpe file contains anentry for "127.0.0.1"
– xinetd is installed and started
– Check the system log files for references about xinetd or nrpe andfix any problems that are reported
2.2.15 測試進程
/usr/local/nagios/libexec/check_nrpe -Hlocalhost #出現下面的結果不要擔心,試試下一條命令
CHECK_NRPE: Error - Could not complete SSLhandshake. #我沒有解決這個問題
/usr/local/nagios/libexec/check_nrpe -H127.0.0.1 #下面的結果是正確的,安裝成功
NRPE v2.15
/usr/local/nagios/libexec/check_nrpe -H10.10.54.112 #下面的結果是正確的,安裝成功
NRPE v2.15
2.2.16 修改防火牆規則(我的防火牆一直是關着的,這不是個好習慣)
iptables -I RH-Firewall-1-INPUT -p tcp -mtcp –dport 5666 -j ACCEPT
service iptables save
2.2.17 修改/usr/local/nagios/etc/nrpe.cfg,可以自定義命令
vim /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users-w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20
#被我註釋掉的這個命令沒有用了,因爲現在的磁盤不是/dev/hda1的了
#command[check_hda1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/hda1
#下面這個命令是我添加的,經測試,有效
command[check_sda1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs-w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 150 -c 200
#測試我剛纔自定義的命令
/usr/local/nagios/libexec/check_disk -w 20%-c 10% -p /dev/sda1
DISK OK - free space: /boot 158 MB (86%inode=99%);| /boot=25MB;154;173;0;193
2.2.18 重啓nrpe服務
/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg –d
2.3 在監測主機上操作
2.3.1 在已配置Nagios的主機上,需要進行以下操作:
– Install the check_nrpe plugin
– Create a Nagios command definition for using the check_nrpe plugin
– Create Nagios host and service definitions for monitoring theremote host
2.3.2 下載NRPE源碼包
wget http://ncu.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
2.3.3 解壓
tar xvf nrpe-2.15.tar.gz
cd nrpe-2.15
2.3.4編譯安裝
./configure
make all
2.3.5 安裝插件
make install-plugin
2.3.6 測試NRPE進程,IP地址爲遠程主機的IP
/usr/local/nagios/libexec/check_nrpe -H 10.10.54.112
NRPE v2.15
2.3.7 修改commands.cfg
vim /usr/local/nagios/etc/objects/commands.cfg
#添加以下內容
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
2.3.8 創建host和service定義
#定義host
define host{
name linux-box ; Name of this template
use generic-host ; Inherit default values
check_ period 24x7
check_ interval 5
retry_ interval 1
max_check_ attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS - ITS ATEMPLATE
}
#定義service
#監測CPU
define service{
use generic-service
host_name remotehost
service_description CPU Load
check_command check_nrpe!check_load
}
#監測在線用戶
define service{
use generic-service
host_name remotehost
service_description Current Users
check_command check_nrpe!check_users
}
#檢測/dev/sda1的空間
define service{
use generic-service
host_name remotehost
service_description /dev/sda1 Free Space
check_command check_nrpe!check_sda1
}
#監測進程數
define service{
use generic-service
host_name remotehost
service_description Total Processes
check_command check_nrpe!check_total_procs
}
#監測殭屍進程
define service{
use generic-service
host_name remotehost
service_description ZombieProcesses
check_command check_nrpe!check_zombie_procs
}
2.3.9 檢測配置文件
/usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg
Things look okay - No serious problems weredetected during the pre-flight check
2.3.10 重啓服務
service nagios restart
3. 在監測主機查看
在瀏覽器輸入http://10.10.54.111/nagios查看