監控linux 主機
下載NRPE
http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
請先安裝openssl 最好用yum [伺服器和linux客戶端都需要]
yum –y install openssl openssl-devel
否則會完成不了ssl 握手
1. 在nagios伺服器端安裝NRPE,
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib
make all && make install-plugin && make install-daemon && make install-daemon-config
配置nrpe
#在commands.cfg中定義nrpe這個外部構件
vi /usr/local/nagios/etc/objects/commands.cfg,增加如下一行
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
2.在nagios客戶端安裝NRPE,
/usr/sbin/useradd nagios
passwd nagios
安裝插件9
tar -zxzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make && make install
chown nagios.nagios /usr/local/nagios/
chown -R nagios.nagios /usr/local/nagios/libexec/
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib(前提是已經安裝了openssl與openssl-devel)
make all && make install-plugin && make install-daemon && make install-daemon-config
cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/bin
Vi /usr/local/nagios/etc/nrpe.cfg
修改nrpe.cfg allow_hosts 加上nagios伺服器IP
啟動NRPE
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
vi /etc/rc.local
可以把以上命令寫入rc.local,開機自動啟動,(vi /etc/rc.local)當然,要開放5666埠
3.驗證
在被監控端/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.12
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
CHECK_NRPE: Error - Could not complete SSL handshake.
此時出現此錯誤表明客戶端沒有安裝openssl 不能完成ssl握手
Connection refused by host
Nrpe進程沒有啟動
參考此鏈接http://www.588k.com/?p=36
在nagios伺服器端
[root@nagios objects]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.44 此處填寫客戶端ip地址
NRPE v2.12
返回NRPE版本號,測試成功
測試不成功,下面就不要進行了
4.監控
在 /usr/local/nagios/etc/ 下新建servers目錄,在該目錄下新建一個被監控端主機的配置文件mylinux.cfg
vi /usr/local/nagios/etc/nagios.cfg 在linux 部分添加一行
cfg_file=/usr/local/nagios/etc/mylinux.cfg
文件位置並不重要,也可以放在/etc/object/下,注意要和nagios.cfg裡面的路徑一致即可
改變文件屬組為nagios
Chown –R nagios.nagios /usr/local/nagios/etc/mylinux.cfg
複製如下配置文件到此文件中
define host{
use linux-server
host_name xxxhotel
alias xxxhotel
address 192.168.1.4
max_check_attempts 5
}
define service{
use generic-service
host_name xxxhotel
service_description HTTP
check_command check_http
}
監控linux的地址及相關的服務,
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
查看有沒有錯誤報警,有可能是沒有定義服務之類
Service nagios restart
重啟nagios服務
到web頁面查看效果
如果監控更多的服務如httpd ssh等等的話,只需要在配置文件中做相應的添加即可
更多請參考官方配置文檔
http://nagios.sourceforge.net/docs/3_0/monitoring-publicservices.html
本文出自 「老五的成長記錄」 博客,請務必保留此出處http://yuzeying.blog.51cto.com/644976/533251
[火星人 ] nagios 3.2.3 nrpe-2.12. 簡單監控linux主機已經有1205次圍觀