配置nagios客戶端
配置nagios客戶端
一、客戶端安裝配置
1、客戶端安裝:
- wget http://blog.vlvtu.com/nrpe_install.zip
- tar zxvf nrpe_install
- cd nrpe_install
- ./setup.sh
2、添加啟動項:
- echo "/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local
3、啟動:
- /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
4、檢查:
- tail -f /var/log/message
- Oct 20 16:19:38 webhost2 nrpe[3782]: Starting up daemon
- Oct 20 16:19:38 webhost2 nrpe[3782]: Listening for connections on port 5666
- Oct 20 16:19:38 webhost2 nrpe[3782]: Allowing connections from: 127.0.0.1,192.168.1.11
5、測試NEPE本地是否正常啟動
- /usr/local/nrpe/libexec/check_nrpe -H 192.168.1.11
- NRPE v2.12
6、防火墻配置方法:
- iptables -A FORWARD -i eth0 -p tcp –dport 5666 -j ACCEPT
#p#
二、在監(jiān)控主機上配置NRPE的服務
1.查看新擴展插件check_nrpe的使用方法
- /usr/local/nagios/libexec/check_nrpe -h|less
- Usage: check_nrpe -H [-n] [-u] [-p ] [-t ] [-c ]
使用方式:check_nrpe -H 主機名 -p NRPE端口 -c NRPE命令名
選項:
- = The address of the host running the NRPE daemon
主機,運行著NRPE守護進程的遠程被監(jiān)測主機名,并且該主機名必須在host里定義過。
- [port] = The port on which the daemon is running (default=5666)
端口,被監(jiān)測的遠程主機上運行NRPE的端口,默認是5666,如果是默認就不用指定。
- [command] = The name of the command that the remote daemon should run
命令,這些命令名必須是被監(jiān)測主機上NRPE守護進程運行著的。
查看監(jiān)控服務器是否能和遠程Linux 192.168.1.11正常通信。能正常通信返回 NRPE的版本號
- /usr/local/nagios/libexec/check_nrpe -H 192.168.1.11
2.在command.cfg命令定義文件中添加NRPE命令。
- vi /usr/local/nagios/etc/commands.cfg
- # NRPE Command
最下方添加NRPE功能命令。
- #check nrpe
- define command{
- command_name check_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$ 用來獲得指定被監(jiān)測主機的IP地址,$HOSTADDRESS$變量會通過定義主機名查找到host段中的IP地址。
(4)-c $ARG1$ 用來指定被監(jiān)測主機上NRPE守護進程運行著的NRPE命令名。
3.在Nagios監(jiān)控服務器上然后按照NRPE命令定義來添加NRPE遠程監(jiān)控主機和服務:
hosts.cfg 添加定義主機
- vi /usr/local/nagios/etc/object/hosts.cfg
- define host {
- host_name nagios-server
- alias nagios server
- address 202.96.155.155
- contact_groups sagroup
- check_command check-host-alive
- max_check_attempts 3
- notification_interval 10
- notification_period 24×7
- notification_options d,u,r
- }
- define host{
- use linux-server
- host_name test-cnname server
- alias test-cnname server
- address 202.96.155.155
- contact_groups sagroup
- check_command check-host-alive
- max_check_attempts 3
- notification_interval 10
- notification_period 24×7
- notification_options d,u,r
- }
#p#
測試配置文件
- [root@app ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
………………………………..
- Checking services…
- Checked 5 services.
- Checking hosts…
- Warning: Host '202.96.155.155' has no services associated with it!
- Checked 2 hosts.
- Checking host groups…
- Total Warnings: 1
- Total Errors: 0
有一警告,沒配置services.cfg
- vi /usr/local/nagios/etc/objects/services.cfg
- #address 192.168.1.11為遠程Linux服務器的地址
實現(xiàn)監(jiān)控192.168.1.11服務器硬盤使用情況
- vi /usr/local/nagios/etc/objects/services.cfg
- define service{
- host_name test-cnname server
- service_description check-disk
- check_command check_nrpe!check_df
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- check_period 24×7
- notification_interval 10
- notification_period 24×7
- notification_options w,u,c,r
- contact_groups sagroup
- }
通過這樣的方法可以在hosts文件里添加更多的服務器
運行如下命令。如果沒有錯誤就可以重啟Nagios 服務
- /usr/local/nagios/bin/nagios –v /usr/local/ngaios/etc/nagios.cfg
重啟 Nagios Service 使配置生效
- service nagios reload
【編輯推薦】