wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.4.3/nagios-3.4.3.tar.gz/download
我本地DVD上沒有gd-devel,是以我又加一一個163的鏡像源
yum install -y httpd php gcc glibc glibc-common gd gd-devel perl make
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378817705KGS4.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378817779fsuT.jpg" target="_blank"></a>
建立一個名為nagios的帳号并給定登入密碼
/usr/sbin/useradd nagios
passwd nagios #密碼123456
建立一個使用者組名為nagcmd用于從Web接口執行外部指令。将nagios使用者和apache使用者都加到這個組中。
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818187WLPD.jpg" target="_blank"></a>
[root@gjp nagios]# yum install sendmail –y
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818202l4lO.jpg" target="_blank"></a>
cd /root nagios下載下傳目錄
tar xzf nagios-3.4.3.tar.gz
cd nagios
運作Nagios配置腳本并使用先前開設的使用者及使用者組:
./configure --with-command-group=nagcmd
下面這個,我這裡沒指定
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818205bzTE.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818209Gnkd.jpg" target="_blank"></a>
make all
make install
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818210noss.jpg" target="_blank"></a>
make install-init
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788182103VPH.jpg" target="_blank"></a>
make install-config
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818212mZrJ.jpg" target="_blank"></a>
make install-commandmode
把Nagios加入到服務清單中以使之在系統啟動時自動啟動
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818216bXqn.jpg" target="_blank"></a>
現在還不能啟動Nagios-還有一些要做的...
客戶後配置
樣例配置檔案預設安裝在這個目錄下/usr/local/nagios/etc,這些樣例檔案可以配置Nagios使之正常運作,隻需要做一個簡單的修改...
用你擅長的編輯器軟體來編輯這個/usr/local/nagios/etc/objects/contacts.cfg配置檔案,更改email位址nagiosadmin的聯系人定義資訊中的EMail資訊為你的EMail資訊以接收報警内容。
vi /usr/local/nagios/etc/objects/contacts.cfg
配置WEB接口
安裝Nagios的WEB配置檔案到Apache的conf.d目錄下
nagios-3.4.3.tar.gz解壓後的nagios中執行
[root@gjp ~]# cd nagios
[root@gjp nagios]# make install-webconf
在ls /etc/httpd/conf.d/下,會出現nagios.conf 檔案
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818302kaMB.jpg" target="_blank"></a>
下面使用的版本與上面不同:
展開Nagios插件的源程式包
cd /root
tar xzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
yum install -y openssl openssl-devel
編譯并安裝插件
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818372YRNv.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818394sdLY.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818411z7ME.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818451NWcJ.jpg" target="_blank"></a>
我在這裡采用的yum安裝!
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818481PLXe.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818506qL0k.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818537RSuY.jpg" target="_blank"></a>
以上,是參考文檔,我這裡如下配置:
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818566mk6u.jpg" target="_blank"></a>
建立一個nagiosadmin的使用者用于Nagios的WEB接口登入。記下你所設定的登入密碼,一會兒你會用到它。
htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin #密碼123456
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818574ynIN.jpg" target="_blank"></a>
重新開機Apache服務以使設定生效。
service httpd restart
如果出現服務啟動不了,出現這樣
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818578yjMT.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788185810ucc.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818585xVxh.jpg" target="_blank"></a>
啟動Nagios
驗證Nagios的樣例配置檔案
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果沒有報錯,可以啟動Nagios服務
service nagios start
[root@gjp nagios-plugins-1.4.16]# service nagios start
Starting nagios: done.
界面:
<a href="http://192.168.1.104:1080/nagios/" target="_blank">http://192.168.1.104:1080/nagios/</a>
通路時,輸入使用者名和密碼:則是vim /usr/local/nagios/etc/htpasswd 該檔案中的使用者和密碼!
<a href="http://blog.51cto.com/attachment/201309/211524500.jpg" target="_blank"></a>
這時,監控端已配置好:
通路時,卻發現,通路不到
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818594rJFo.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818597yyrO.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818601VmtP.jpg" target="_blank"></a>
Apache重新開機才能生效!
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788186034yg0.jpg" target="_blank"></a>
如果無法通路,檢視apache服務是否開啟,如果啟動不了,查原因,我這裡是由于selinux沒關閉,導緻的,vim /etc/selinux/config 把#SELINUX=enforcing
SELINUX=disabled
如果apache正常,扔無法打開web,則檢視iptables
如iptables –F 規則,清理下,ok
tar xvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all && make install-plugin
在檔案/usr/local/nagios/etc/objects/commands.cfg後面增加:
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
}
定義主機:
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818608WuyO.jpg" target="_blank"></a>
vim /usr/local/nagios/etc/nagios.cfg
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788186130M9e.jpg" target="_blank"></a>
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
監測看到如下: 這裡有1個警告,是沒問題的!
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818616kMpb.jpg" target="_blank"></a>
/etc/init.d/nagios restart
看到界面如下:
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818621e1O9.jpg" target="_blank"></a>
定義相應的服務:
vim /usr/local/nagios/etc/objects/service.cfg (自己建立的)
[root@root objects]# cat service.cfg
define service{
use generic-service;
host_name test;
service_description users;
check_command check_nrpe!check_users;
service_description load;
check_command check_nrpe!check_load;
service_description disk;
check_command check_nrpe!check_disk;
service_description zombie;
check_command check_nrpe!check_zombie_procs;
define servicegroup{
servicegroup_name servergroup;
alias server-group;
members test,users,test,load,test,disk,test,zombie;
}(這個文檔對應的是被監控端的vim /usr/local/nagios/etc/nrpe.cfg 中定義的指令,如command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 16)
寫完後,進行驗證:
然後記着重新開機nagios
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788186256B9Z.jpg" target="_blank"></a>
出現上面:
在被監控端192.168.1.106:
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_137881862886HZ.jpg" target="_blank"></a>
在監控端:
[root@root objects]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.106 -c check_disk
DISK OK - free space: / 6666 MB (72% inode=95%);| /=2521MB;9188;9488;0;9688
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818631adTF.jpg" target="_blank"></a>
上面的HTTP錯誤,開放80端口,在httpd.conf中,增加Listen 80,然後,apache服務重新開機,解決!
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818636WZrn.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818639UQng.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_137881864119pA.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818644488O.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818647tKVx.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818652oh3w.jpg" target="_blank"></a>
在被監控機上:
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818656ii7U.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818659o77D.jpg" target="_blank"></a>
在這裡,我的操作如下:
groupadd nagios
useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios
cd /tmp/
tar xvf nagios-plugins-1.4.16.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
make && make install
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818659wSv2.jpg" target="_blank"></a>
tar xvfz nrpe-2.13.tar.gz
make install-plugin
make install-daemon
make install-daemon-config
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818661pHC7.jpg" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818663kQe7.jpg" target="_blank"></a>
具體操作如下:
更改/usr/local/nagios/etc/nrpe.cfg檔案,在參數allowed_hosts後添加監控機ip(多個ip以逗号分隔,目前監控及ip為222.189.237.136,112.84.184.111)
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818665DtJh.jpg" target="_blank"></a>
可以在/etc/services結尾增加:
echo 'nrpe 5666/tcp # NRPE' >> /etc/services
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818668gOKa.jpg" target="_blank"></a>
/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.13
<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818671Wpx4.jpg" target="_blank"></a>
更改 /usr/local/nagios/etc/nrpe.cfg,把原來command都注釋掉
nrpe.cfg檔案裡包含需要監控遠端主機的指令,如:
echo '
command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 16
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 500 -c 200 -p /
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_cpu_procs]=/usr/local/nagios/libexec/check_procs -w 40 -c 80 -m CPU
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 ' >> /usr/local/nagios/etc/nrpe.cfg
7)手工啟動
手工啟動方法 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
8)添加開機啟動
echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d' >> /etc/rc.local
9)驗證nrpe是否監聽
netstat -tanp | grep nrpe
上述部分參考截圖來自:
《高性能Linux伺服器建構實戰:運維監控、性能調優與叢集應用%28完整%29.pdf》
本文轉自 gjp0731 51CTO部落格,原文連結:http://blog.51cto.com/guojiping/1293933