在被監控主機上安裝Nagios-plugins插件程序:
1.添加Nagio用戶
[root@KCentOS5A ~]# useradd nagios
[root@KCentOS5A ~]# tar -zxvf nagios-plugins-1.4.10.tar.gz 4.進入Nagios-plugins插件包目錄
[root@KCentOS5A ~]# cd nagios-plugins-1.4.10
5.預配置Nagios-plugins的安裝路徑
[root@KCentOS5A nagios-plugins-1.4.10]# ./configure --prefix=/usr/local/nagios
6.預配置完成後會反饋信息並生成Makefile
-------------------------------------------------------
config.status: creating po/Makefile
--with-apt-get-command:
--with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: no
--with-openssl: yes
--with-gnutls: no
--with-perl: /usr/bin/perl
--enable-perl-modules: no
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
-------------------------------------------------------
7.編譯Nagios-plugins插件程序
[root@KCentOS5A nagios-plugins-1.4.10]# make
8.安裝Nagios-plugins插件程序
[root@KCentOS5A nagios-plugins-1.4.10]# make install
9.查看Nagios-plugins插件程序的安裝
[root@KCentOS5A nagios-plugins-1.4.10]# ll /usr/local/nagios/
total 8
drwxr-xr-x 2 root root 4096 Oct 7 01:02 libexec
drwxr-xr-x 3 root root 4096 Oct 7 01:02 share
10.遞歸更改Nagios主路徑的屬主
[root@KCentOS5A ~]# chown -R nagios.nagios /usr/local/nagios/
11.檢查Nagios主路徑的屬性
[root@KCentOS5A ~]# ll /usr/local/|grep nagios
drwxr-xr-x 4 nagios nagios 4096 Oct 7 01:02 nagios
[root@KCentOS5A ~]# ll /usr/local/nagios/
total 8
drwxr-xr-x 2 nagios nagios 4096 Oct 7 01:02 libexec
drwxr-xr-x 3 nagios nagios 4096 Oct 7 01:02 share
四.再在被監控主機上安裝NRPE擴展插件程序:
1.解壓NRPE的壓縮包
[root@KCentOS5A ~]# tar -zxvf nrpe-2.9.tar.gz
2.進入NRPE包目錄
[root@KCentOS5A ~]# cd nrpe-2.9
3.預配置NRPE安裝程序
[root@KCentOS5A nrpe-2.9]# ./configure
4.預配置完畢後會反饋提示信息以及建立Makefile
-------------------------------------------------------
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating subst
config.status: creating include/config.h
*** Configuration summary for nrpe 2.9 08-13-2007 ***:
General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
Review the options above for accuracy. If they look okay,
type 'make all' to compile the NRPE daemon and client.
最後提示繼續使用“make all”命令來對NRPE守護程序以及客戶端程序進行編譯。
-------------------------------------------------------
5.對NRPE程序進行編譯
[root@KCentOS5A nrpe-2.9]# make all
6.編譯成功後會反饋提示信息
-------------------------------------------------------
*** Compile finished ***
If the NRPE daemon and client compiled without any errors, you
can continue with the installation or upgrade process.
Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.
在NRPE的包目錄中有一份NRPE.pdf的手冊,接下來就可以參考那份手冊進行後續的操作了。
-------------------------------------------------------
安裝NRPE插件程序,守護程序以及模板守護程序配置文件。
Install the NRPE plugin (for testing), daemon, and sample daemon config file.
7.安裝NRPE插件程序
[root@KCentOS5A nrpe-2.9]# make install-plugin
8.安裝NRPE守護程序
[root@KCentOS5A nrpe-2.9]# make install-daemon
9.安裝NRPE守護程序配置文件
[root@KCentOS5A nrpe-2.9]# make install-daemon-config
10.檢查NRPE程序的安裝
[root@KCentOS5A nrpe-2.9]# ll /usr/local/nagios/
-------------------------------------------------------
total 16
drwxrwxr-x 2 nagios nagios 4096 Oct 7 01:16 bin
drwxrwxr-x 2 nagios nagios 4096 Oct 7 01:16 etc
drwxr-xr-x 2 nagios nagios 4096 Oct 7 01:15 libexec
drwxr-xr-x 3 nagios nagios 4096 Oct 7 01:02 share
-------------------------------------------------------
五.在被監測主機上配置並運行NRPE:
1.配置NRPE的主配置文件
[root@KCentOS5A ~]# vi /usr/local/nagios/etc/nrpe.cfg
這裏主要交待一些關鍵重要的設定。
-------------------------------------------------------
pid_file=/var/run/nrpe.pid
設定NRPE運行的PID文件,這個默認就設定好了,不用更改。
server_port=5666
這個是NRPE守護進程佔用的系統端口。
#server_address=0.0.0.0
server_address=192.168.1.9 #這是被控端IP地址
設定系統監聽NRPE的網絡接口。一般設定具體的IP地址,如果要多個網卡的話就用逗號“,”來分隔多個IP地址。如果要監聽系統全部的網絡接口的話,可以使用“0.0.0.0”這個表示全部網絡接口的特殊地址,但是不可以用通配符“*”。
nrpe_user=nagios
nrpe_group=nagios
設定NRPE的宿主用戶。
allowed_hosts=192.168.1.12 #這是充許監控服務器IP地址
這裏是設定允許與本機進行NRPE交互的主機的IP地址,也就是Nagios監測服務器的地址,如果要指定多個Nagios服務器的話,那麼用逗號“,”來分隔多個IP地址。
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
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
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
以上是NRPE默認就有的擴展插件命令,這是至關重要的地方了。當被監測主機運行NRPE守護進程的時候,同時就運行起來了這些在NRPE配置文件中定義的NRPE擴展命令了。可以看出這些擴展命令都已經指定了好了命令名、插件路徑以及選項參數了。格式如下:
command[NRPE命令名]=插件路徑/插件 選項1 參數1 選項2 參數2 ...
注意,如果要指定該被監測主機需要被監控的服務的話,就必須在這裏都配置好NRPE命令並運行在NRPE守護進程裏。這裏沒有配置的NRPE命令則Nagios監測服務器是無法監控到的。
-------------------------------------------------------
2.找到NRPE運行的執行程序
[root@KCentOS5A ~]# ll /usr/local/nagios/bin/nrpe
-rwxrwxr-x 1 nagios nagios 93420 Oct 7 01:16 /usr/local/nagios/bin/nrpe
3.瞭解NRPE的執行程序的使用方式
[root@KCentOS5A ~]# /usr/local/nagios/bin/nrpe -h
-------------------------------------------------------
Usage: nrpe [-n] -c <config_file><mode>
運行方法:nrpe -c NRPE配置文件路徑 運行模式
Options:
可用選項
-n = Do not use SSL
不使用SSL方式,一般都使用SSL。
<config_file> = Name of config file to use
指定NRPE配置文件路徑,這個NRPE主配置文件就是nrpe.cfg。
<mode> = One of the following two operating modes:
指定NRPE的運行方式,一共有2種可用的NRPE運行方式:
-i = Run as a service under inetd or xinetd
以超級守護進程inetd或xinetd方式運行NRPE,要通過這種方式運行的話還要安裝和配置xinetd,一般不用。
-d = Run as a standalone daemon
以獨立守護進程方式運行NRPE,一般常用這種運行方式。
-------------------------------------------------------
4.運行NRPE守護進程
[root@KCentOS5A ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
5.查看系統日誌檢查NRPE運行情況:
[root@KCentOS5A ~]# tail /var/log/messages
-------------------------------------------------------
Oct 7 01:45:10 KCentOS5A nrpe[21659]: Starting up daemon
說明已經順利啓動了NRPE守護進程。
Oct 7 01:45:10 KCentOS5A nrpe[21659]: Listening for connections on port 5666
說明已經啓動了5666端口爲NRPE的監聽端口。
Oct 7 01:45:10 KCentOS5A nrpe[21659]: Allowing connections from: 192.168.1.12
說明已經打開對指定的Nagios監測服務器的訪問允許。
-------------------------------------------------------
如果啓動失敗,提示已綁定,是因爲nrpe服務已經啓動過了,所以需要我們先把nrpe服務殺死,重新啓動。
-------------------------------------------------------
[root@KCentOS5A ~]# netstat -nap | grep nrpe
tcp 0 0 192.168.1.9:5666 0.0.0.0:* LISTEN 21659/nrpe
unix 2 [ ] DGRAM 23374 21659/nrpe
-------------------------------------------------------
6.檢查NRPE的進程信息
[root@KCentOS5A ~]# ps aux | grep nrpe
-------------------------------------------------------
nagios 21659 0.0 0.3 4396 868 ? Ss 01:45 0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
-------------------------------------------------------
7.檢查NRPE的網絡連接信息
-------------------------------------------------------
[root@KCentOS5A ~]# netstat -nap | grep nrpe
tcp 0 0 192.168.1.9:5666 0.0.0.0:* LISTEN 21659/nrpe
unix 2 [ ] DGRAM 23374 21659/nrpe
-------------------------------------------------------
8.將NRPE運行添加加入系統啓動腳本中
[root@KCentOS5A ~]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local
到此,被監控主機要做的工作已經完成了。
在Nagios監測服務器上安裝NRPE核心擴展插件程序
相對被檢測主機來說,Nagios監測服務器上做的NRPE安裝就比較簡單了,而且它主要監測別人而不是被別人監測,所以它不需要將NRPE作爲守護進程運行起來,只要擁有NRPE的擴展插件功能就可以了。
1.解壓NRPE壓縮包
[root@KCentOS5C ~]# tar -zxvf nrpe-2.9.tar.gz
2.進入NRPE包目錄
[root@KCentOS5C ~]# cd nrpe-2.9
3.預配置NRPE安裝程序
[root@KCentOS5C nrpe-2.9]# ./configure
4.編譯NRPE程序
[root@KCentOS5C nrpe-2.9]# make all
5.安裝NRPE擴展插件程序
[root@KCentOS5C nrpe-2.9]# make install-plugin
Nagios 只要擁有NRPE的擴展插件功能就可以了,所以在Nagios監測服務器安裝NRPE工作到這步就可以了。接下來要做的就是在Nagios監測服務器上配置NRPE的擴展插件命令,使得Nagios監測服務器能夠定義nrpe命令,從而可以定義出“遠程系統監測服務”。
七.在監控主機上配置NRPE的服務
1.查看新擴展插件check_nrpe的使用方法
[root@KCentOS5C ~]# /usr/local/nagios/libexec/check_nrpe -h|less
-------------------------------------------------------
Usage: check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>]
使用方式:check_nrpe -H 主機名 -p NRPE端口 -c NRPE命令名
Options:
選項:
<host> = The address of the host running the NRPE daemon
主機,運行着NRPE守護進程的遠程被監測主機名,並且該主機名必須在host裏定義過。
[port] = The port on which the daemon is running (default=5666)
端口,被監測的遠程主機上運行NRPE的端口,默認是5666,如果是默認就不用指定。
[command] = The name of the command that the remote daemon should run
命令,這些命令名必須是被監測主機上NRPE守護進程運行着的。
-------------------------------------------------------
2.在command.cfg命令定義文件中添加NRPE命令。
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/commands.cfg
-------------------------------------------------------
# NRPE Command
添加NRPE功能命令。
define command(
command_name nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
-------------------------------------------------------
這裏要說明幾點:
(1)這裏定義的命令名就叫作nrpe。
(2)$USER1$/check_nrpe會通過引用resource.cfg獲得/usr/local/nagios/libexec/check_nrpe這個絕對路徑。
(3)-H $HOSTADDRESS$ 用來獲得指定被監測主機的IP地址,$HOSTADDRESS$變量會通過定義主機名查找到host段中的IP地址。
(4)-c $ARG1$ 用來指定被監測主機上NRPE守護進程運行着的NRPE命令名。
6.在Nagios監控服務器上然後按照NRPE命令定義來添加NRPE遠程監控服務:
在service.cfg裏面添加服務。
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use generic-service ; Name of service template to use
host_name node2
service_description SSH
check_command check_nrpe!check_ssh
notifications_enabled 1
normal_check_interval 10
retry_check_interval 1
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use generic-service ; Name of service template to use
host_name node2
service_description HTTP
check_command check_nrpe!check_http
notifications_enabled 0
normal_check_interval 10
retry_check_interval 1
}
用nrpe做代理收到服務器端信息之後,發給被監控的機器,被監控的機器在去查詢nrpe.cfg裏面的相關命令定義:command[check_http]=/usr/local/nagios/libexec/check_http
-l 192.168.132.133
command[check_ssh]=/usr/local/nagios/libexec/check_ssh -4 -p 22 192.168.132.133,提取自身服務器的響應之後再回送給服務器端。