監控linux 主機
下載下傳NRPE
<a href="http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz">http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz</a>
請先安裝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/
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib(前提是已經安裝了openssl與openssl-devel)
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程序沒有啟動
在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
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等等的話,隻需要在配置檔案中做相應的添加即可
更多請參考官方配置文檔
<a href="http://nagios.sourceforge.net/docs/3_0/monitoring-publicservices.html">http://nagios.sourceforge.net/docs/3_0/monitoring-publicservices.html</a>
<a href="http://yuzeying1.blog.51cto.com/attachment/201104/1/644976_1301654752OS54.png"></a>
本文轉自 yuzeying1 51CTO部落格,原文連結:http://blog.51cto.com/yuzeying/533251