天天看點

實戰CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

Nagios網上的教程百度一下一大把,發現有些教程講法有點出入,估計有些都是拷貝亂貼亂飛,按有些說法去做,根本就做不下去,今天我親自實踐,現場抓圖讓你看得清楚看得明白,以及中間遇到什麼問題,怎麼解決,都會分享給大家,抓圖再寫出來有點辛苦,關鍵能學到東西一切都是值得滴,Follow me~!

下載下傳centOS 6.0然後安裝好系統,最好用vmware來做最好.

自行裝好系統以後現在開始裝備安裝前的環境準備

我把指令貼出來,為了友善大家操作你隻要跟着我把指令拷貝和粘貼即可,省去敲打指令的麻煩也避免失誤出錯(小技巧提醒:裝好centOS以後進入x-windows裡面裝個vmware tools就可以實作實體機和虛拟機之間的拷貝和粘貼,方法很簡單這裡就不說了)

yum -y install httpd gettext mysql mysql-server mysql-devel php php-mysql php-pear

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217469IvCP.png"></a>

yum install php-mysql mysql perl mysql-server perl-DBI perl-DBD-MySQL httpd gcc glibc glibc-common gd gd-devel php

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217474LER6.png"></a>

線上下載下傳nagios程式和插件

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217476YHru.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217479ED58.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217481Zn13.png"></a>

使用者群組的準備

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217482d5qg.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182174842u03.png"></a>

開始安裝主程式

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182174865iiA.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217487WM2e.png"></a>

完成以後發現執行make all指令的時候出現以下錯誤

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217488AEyU.png"></a>

貌似CentOS下預設系統沒有安裝編譯器,安裝一下:

yum -y install gcc automake autoconf libtool make

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182174892y5i.png"></a>

繼續做make all操作,發現最後報錯了,

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217490RQVu.png"></a>

先執行make clean操作,然後再執行 ./configure &amp;&amp; make all 操作通過(問題分享)接着再執行以下指令即可,沒有出現任何狀況.

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217492xUWR.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217492bASk.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217493TZ8K.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217494nm7p.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217494YiVY.png"></a>

接下來安裝插件

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217495gbQ7.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217496ka7S.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217496sffY.png"></a>

添加通路頁面使用者nagiosadmin及密碼,這裡要記住此密碼不要忘記了.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217497KvQa.png"></a>

接下來啟動相關服務

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217498XirC.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217500R9yh.png"></a>

檢查配置檔案是否正确

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182175019f5E.png"></a>

[經驗分享:由于這一串檢查的指令很長,應用率也比較高,這裡我們可以自定義一個指令來代替這一長串的指令

編輯.bashrc這個檔案

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217502JpEu.png"></a>

在裡面用alias 來自定義一個指令來代替,這裡我用check

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217503umwl.png"></a>

用source指令在目前bash環境下讀取并執行bashrc中的指令

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217504XzcD.png"></a>

這樣我們自定義的指令就生效了,以後隻要輸入check就可以檢查nagios配置檔案是否存在錯誤了,簡單友善.]

發現沒有警告和錯誤就表示通過了

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217505K4Bj.png"></a>

開了防火牆記得要開放80端口,要不然連接配接不到,或者直接關閉防火牆用指令service iptables stop關閉即可.

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217506u11D.png"></a>

問題分享:進入頁面的時候點主機或其它選項的時候報此錯誤,後面百度一下原來是開啟了selinux強制通路控制安全子產品所緻

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182175101qA1.png"></a>

注意:如果你開啟了selinux 需要配置如下二步: 

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/ 

chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217516UMYY.png"></a>

這樣正宗的中文版出來了,總算邁出了成功的一小步,耐心堅持讓我們繼續吧~~!

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217521Heh5.png"></a>

[經驗分享:我這裡用虛拟機做的,記得系統和網絡相關參數配置好以後做一個系統的快照,配到這裡nagios安裝成功以後我們再做一個快照,以免後面配亂出問題的時候我們可以傳回到這裡重新再配置,友善快捷,記住做快照的時候先把虛拟機關閉以後再做,要不然快照出來的檔案大得吓人,而關閉以後做快照檔案才幾百KB.]

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217535kBxm.png"></a>

ok下面我們接着來

[nrpe_plugins名額采集程式主要是用來分析nrpe用戶端的plugin腳本采集性能名額資料。目前實作的有cpu、memory、disk、buffer、singleprocess、oracle、sybase等方面的性能名額的分析,這個插件需要分别安裝在主要端和被控端上,這個插件需要openssl的支援,沒有就直接線上安裝一下(yum install openssl-devel)是以還需在nagios主機和被控端安裝,感覺挺麻煩,沒辦法它需要咱們就跟着做哈.]

先把nrpe下載下傳下來先.

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217539vvq3.png"></a>

解壓檔案

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217540Gnz5.png"></a>

編譯安裝

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217541b732.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217541lruz.png"></a>

完成以後沒有出錯就可以看到以下生成的檔案了

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217542PzT5.png"></a>

二:配置PNP

[PNP是一個基于php和perl,用rrdtool将nagios采集的資料繪制圖表的工具,是以安裝pnp之前必須先安裝php perl  and rrdtool這裡用yum直接來安裝rrdtool,單獨下載下傳安裝有很多依存關系,挺麻煩.]

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182175450XZL.png"></a>

我這裡找到最新的版本是0.6.15

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217549R9Ax.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217550KoGj.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182175541THM.png"></a>

編譯的時候報錯了.

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217554RfNw.png"></a>

yum install perl-Time-HiRes

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182175551BTI.png"></a>

繼續編譯發現有個perl modules沒有發現,好像提示用來加速什麼的,暫時不管它了

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217558pQ3T.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217560Tg4d.png"></a>

根據提示需要繼續

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217561AJ6b.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217563eYen.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217564iUBq.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217564tLqT.png"></a>

然後把相關字尾帶sample檔案變更成無sample字尾

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217566tuyv.png"></a>

配置Nagios來啟用PNP

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217569juuh.png"></a>

enable_environment_macros=1預設是開啟了的 

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217571SJoC.png"></a>

pnp4nagios有很多種工作模式,這裡我們選用同步模式,想選其它模式可以看說明都有詳細配置教程(不同模式配置不同)

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217575mwPA.png"></a>

這裡我們按說明的設定方法來做

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217578wuMC.png"></a>

[這裡先把pnp4nagios執行資料收集的檔案拷貝到nagios的libexec下,友善統一指令的執行路徑.]

cp /usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217581Tla8.png"></a>

然後在commands.cfg裡面加入如下(這裡是同步模式設定方法)

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217582xBv3.png"></a>

#process-host-perfdata' command definition 

define command{ 

        command_name    process-host-perfdata 

        command_line    $USER1$/process_perfdata.pl -d HOSTPERFDATA 

        }

#process-service-perfdata' command definition 

        command_name    process-service-perfdata 

        command_line    $USER1$/process_perfdata.pl 

        } 

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217584gWCZ.png"></a>

然後添加小太陽模版,鑲嵌在nagios頁面上

[這裡有兩種檢視圖的方法,第一種方法是你當太陽的圖示的時候會在新視窗中打開圖形檢視,第二種方法是你隻需要把滑鼠移動到太陽圖示上面就會自動彈出圖形出來,以下兩種方法你可以根據自己喜好選其中一種即可]

第一種方法在templates.cfg裡面加入如下

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217585u0DM.png"></a>

define host { 

   name       host-pnp 

   action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&amp;srv=_HOST_ 

   register   0 

}

define service { 

   name       srv-pnp 

   action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&amp;srv=$SERVICEDESC$ 

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182175869OTO.png"></a>

第二種方法按照說明加入如下

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217589fIsM.png"></a>

拷貝status-header.ssi到/usr/local/nagios/share/ssi/目錄下面來(這一步很重要,要不然移動到太陽标記上出不來圖)

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217595jofT.png"></a>

   action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&amp;srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&amp;srv=_HOST_ 

   action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&amp;srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&amp;srv=$SERVICEDESC$ 

第二種方法最終效果圖

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217599pzVk.png"></a>

為目标主機圖示旁邊添加一個小太陽标記

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217607oFY2.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217608LpzG.png"></a>

為相關服務添加一個小太陽标記

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217610wwyB.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217610ewIk.png"></a>

先做一下pnp4nagios環境測試,發現php-gd子產品無效,用指令yum install php-gd安裝成功以後還是不行,後來經老男孩指點用yum install php* -y安裝然後重新開機系統成功通過,

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217614YOuU.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217619snnC.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217621Z9Tn.png"></a>

按要求重命名install.php

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217624iAcv.png"></a>

做好相關配置以後請用指令重新開機一下nagios的服務

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217625etEd.png"></a>

ok,到此總算配置好了PNP,配置了這麼多有點累了,但我們還要繼續,配置本章最後一個Nagios WEB管理工具叫NagiosQL(注:還有同樣一個Nagios WEB管理工具叫Nconf)

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217626kl3Q.png"></a>

NagiosQL是一個WEB管理工具,隻要把其放到下Apache即可。因為這裡它要和Nagios整合到一起,為了友善管理,把其放在Nagios目錄下

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182176272XYu.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_131821762872xP.png"></a>

建立nagiosQL導出nagios配置檔案的目錄,并修改權限

建目錄和改權限

mkdir -p /etc/nagiosql/{hosts,services,backup/{,hosts,services},import}

chown -R apache:nagios /etc/nagiosql/

chmod -R 755 /etc/nagiosql

chmod 777 /usr/local/nagios/nagiosql/config

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217629cK6T.png"></a>

Nagios相關檔案權限的設定

chown nagios:apache /usr/local/nagios/etc

chown nagios:apache /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}

chown nagios:apache /usr/local/nagios/etc/*

chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}

chmod 775 /usr/local/nagios/etc

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217631bs7V.png"></a>

設定nagios二進制檔案的權限,以便其能夠通過Web程式執行

chown nagios:apache /usr/local/nagios/bin/nagios

chmod 750 /usr/local/nagios/bin/nagios

chown -R apache.nagios /usr/local/nagios/var/spool/

chown nagios:apache /usr/local/nagios/var/rw/nagios.cmd

chmod 660 /usr/local/nagios/var/rw/nagios.cmd

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217633CZZz.png"></a>

為apache添加nagiosQL虛拟目錄

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217634Enq3.png"></a>

Alias /nagiosQL "/usr/local/nagios/nagiosql" 

&lt;Directory "/usr/local/nagios/nagiosql"&gt; 

# SSLRequireSSL 

Options None 

AllowOverride None 

Order allow,deny 

Allow from all 

&lt;/Directory&gt;

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217635QYQR.png"></a>

重新加載httpd服務和啟動mysqld服務

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182176378R8p.png"></a>

建立nagiosql安裝檔案

touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217638oDJU.png"></a>

問題分享:我在通路的時候提示沒有權限通路,搞了半天原來是SElinux惹的禍,修改SELinux的實時運作模式,setenforce 0 (設定SELinux 成為permissive模式)這個隻是臨時解決方法,優點是不需重新開機系統生效,但如果要徹底禁用SELinux 需要在/etc/sysconfig/selinux中設定參數selinux=0

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182176399uMw.png"></a>

選取中文然後點開始安裝按鈕

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217644Ytqa.png"></a>

測試所需環境通過,直接按下一步即可

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217654Q2zr.png"></a>

删除安裝目錄,這裡使用改權限:chmod 000 /usr/local/nagios/nagiosql/install

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217658ao5T.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217663r9HX.png"></a>

到這裡安裝步驟總算結束了,下面我們還需要進行相關配置工作.

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217673SIGo.png"></a>

管理-域-localhost---點“修改”

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217691hYof.png"></a>

按如圖所示更改相應的路徑即可

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217700MPXu.png"></a>

工具-導入資料 右邊會列出一些配置檔案,選擇導入即可。

導入隻是把配置檔案内容導入到Mysql資料庫,而使用其配置檔案時,是一個個cfg檔案,是以下面要進行寫入過程

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217710xinc.png"></a>

工具-nagios控制-寫入檢測資料-寫入其他資料

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182177327xG9.png"></a>

檢查配置檔案成功

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217739hcB3.png"></a>

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182177440tVA.png"></a>

寫入之後就可以看到相應的cfg檔案了,檢視寫入是否成功,由下面的輸出可以看出寫入是成功滴.

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217747Dgvz.png"></a>

修改nagios的配置檔案,将原有以cfg_file開頭項全部注釋掉,加入上面新寫入的配置檔案

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217751TvMJ.png"></a>

注釋掉

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_13182177559RMK.png"></a>

加入新的配置檔案路徑

cfg_dir=/etc/nagiosql/hosts/ 

cfg_dir=/etc/nagiosql/services/ 

cfg_file=/etc/nagiosql/commands.cfg 

cfg_file=/etc/nagiosql/contactgroups.cfg 

cfg_file=/etc/nagiosql/contacts.cfg 

cfg_file=/etc/nagiosql/contacttemplates.cfg 

cfg_file=/etc/nagiosql/hostdependencies.cfg 

cfg_file=/etc/nagiosql/hostescalations.cfg 

cfg_file=/etc/nagiosql/hostextinfo.cfg 

cfg_file=/etc/nagiosql/hostgroups.cfg 

cfg_file=/etc/nagiosql/hosttemplates.cfg 

cfg_file=/etc/nagiosql/servicedependencies.cfg 

cfg_file=/etc/nagiosql/serviceescalations.cfg 

cfg_file=/etc/nagiosql/serviceextinfo.cfg 

cfg_file=/etc/nagiosql/servicegroups.cfg

cfg_file=/etc/nagiosql/servicetemplates.cfg 

cfg_file=/etc/nagiosql/timeperiods.cfg

<a href="http://allanfan.blog.51cto.com/attachment/201110/10/520839_1318217763qBaP.png"></a>

檢查nagios的配置檔案是否有問題,然後生重新開機nagios服務,至此整個搭建過程終于完成了,下一節将講解重頭戲,怎麼用nagiosQL添加需要監控的主機以及啟用nagios報警機制,待續~~!

NagiosQL添加監控主機及Nagios上啟用報警機制

<a href="http://allanfan.blog.51cto.com/520839/704288">http://allanfan.blog.51cto.com/520839/704288</a>

     本文轉自allanhi 51CTO部落格,原文連結:http://blog.51cto.com/allanfan/684169,如需轉載請自行聯系原作者