Nagios Plugin for Cacti 安裝使用篇(zt)

tonykorn97發表於2007-07-10

作者:Mars_angels(CU之初學vb)
來源:cacti 中文論壇

前言:
Nagios Plugin for Cacti 簡稱 npc,是cacti的一個外掛,這篇文章主要介紹如何在cacti中使用npc外掛。


測試環境:
作業系統:rhel4u4 php4.4.4 mysql-4.1.22 httpd-2.2.4
npc主頁:
npc 當前版本:NPC 0.1.1a
nagios 主頁:
nagios 當前版本:nagios-2.7
nagios 外掛當前版本:nagios-plugins-1.4.6
fruity:圖形化配置nagios的工具,需要php5.x版本才能執行




將HTML_TreeMenu-1.2.0.tgz和adodb471-1.tgz直接解壓複製到fruity 下 分別改名為HTML 和adodb 其他不做修改
修改 fruity/includes下的config.ifg,需要更改的地方有,路徑,mysql資訊
mysql 新增fruity 資料庫和user,password.
這樣,就可以用fruity來進行配置了。
注意:
在cacti伺服器上的mysql版本必須是4.1以上,因為npc是以mysql4.1為基礎進行開發的。

第一章:安裝nagios
我們在cacti中使用nagios,首先我們要安裝nagios環境,安裝過程如下:
# tar –xvzf nagios-2.7.tar.gz
# mkdir /usr/local/nagios
# useradd nagios –d /usr/local/nagios
# passwd nagios 1qazSE$
# chmod 755 /usr/local/nagios
# grep "^User" /etc/httpd/conf/httpd.conf //查詢apache的承託使用者
我這裡是daemon。2.2.0以前的apache版本可能會是nobody
# /usr/sbin/groupadd nagcmd

# /usr/sbin/usermod -G nagcmd daemon-----這個地方就是前面的aapche承託使用者

# /usr/sbin/usermod -G nagcmd nagios


# cd nagios-2.7
#./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include --enable-event-broker
# make all
# make install
# make install-init 安裝啟動指令碼到/etc/init.d/
# make install-commandmode
# make install-config 安裝初始配置檔案到/usr/local/nagios

nagios-plugins的安裝
tar –xvzf nagios-plugins-1.4.6.tar.gz
cd nagiso-plugins-1.4.6
./configure --prefix=/usr/local/nagios-plugins
make all
make install
注意:
nagios-plugins 1.4.6編譯安裝時出錯修正:
Making install in po
make[1]: Entering directory `/opt/software/nagios/nagios-plugins-1.4.6/po'
/bin/sh @MKINSTALLDIRS@ /usr/local/nagios-plugins/share
/bin/sh: @MKINSTALLDIRS@: No such file or directory
make[1]: *** [install-data-yes] Error 127
make[1]: Leaving directory `/opt/software/nagios/nagios-plugins-1.4.6/po'
make: *** [install-recursive] Error 1

需要修改一下po/Makefile檔案:

MKINSTALLDIRS = @MKINSTALLDIRS@
mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
替換為:
MKINSTALLDIRS = $(top_builddir)/./mkinstalldirs
mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
安裝完成以後在/usr/local/nagios-plugins-plugins會產生一個libexec的目錄,將該目錄全部移動到/usr/local/nagios目錄下即可。 如下:
# mv /usr/local/nagios-plugins/libexec /usr/local/nagios
到此,兩個基本的TAR包安裝完成

配置apache過程:

在apache的httpd.conf檔案中加入如下欄位:

ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/

AllowOverride AuthConfig

Options ExecCGI

Order allow,deny

Allow from all

Alias /nagios/ /usr/local/nagios/share/

Options None

AllowOverride AuthConfig

Order allow,deny

Allow from all

注意:

如果你的apache版本是2.2.0,那麼你需要把以上這段加到

之間。

配置頁面訪問許可權:

在/usr/local/nagios/share目錄下

# cd /usr/local/nagios/share

# vi .htaccess

AuthName "Nagios Access"

AuthType Basic

AuthUserFile /usr/local/nagios/etc/.htpasswd

require valid-user

然後在/usr/local/nagios/sbin編輯.htaccess

#vi .htaccess

AuthName "Nagios Access"

AuthType Basic

AuthUserFile /usr/local/nagios/etc/.htpasswd

require valid-user

#/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/.htpasswd nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin

這個apache目錄根據安裝目錄的不同而不同,用htpasswd命令生成使用者名稱和密碼以控制訪問許可權。

配置和啟動nagios過程

# cd /usr/local/nagios/etc

把目錄裡的.cfg-sample檔案全部複製成.cfg

例如:

# cp nagios.cfg-sample nagios.cfg

修改cgi.cfg,把use_authentication=1改為use_authentication=0,即不用驗證.不然有一些頁面不會顯示。

修改後用如下命令檢查配置檔案是否正常:

#/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg

Nagios 2.7

Copyright (c) 1999-2007 Ethan Galstad ()

Last Modified: 01-19-2007

License: GPL

Reading configuration data...

Running pre-flight check on configuration data...

Checking services...

Checked 5 services.

Checking hosts...

Checked 1 hosts.

Checking host groups...

Checked 1 host groups.

Checking service groups...

Checked 0 service groups.

Checking contacts...

Checked 1 contacts.

Checking contact groups...

Checked 1 contact groups.

Checking service escalations...

Checked 0 service escalations.

Checking service dependencies...

Checked 0 service dependencies.

Checking host escalations...

Checked 0 host escalations.

Checking host dependencies...

Checked 0 host dependencies.

Checking commands...

Checked 22 commands.

Checking time periods...

Checked 4 time periods.

Checking extended host info definitions...

Checked 0 extended host info definitions.

Checking extended service info definitions...

Checked 0 extended service info definitions.

Checking for circular paths between hosts...

Checking for circular host and service dependencies...

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...

Total Warnings: 0

Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check

如上紅色字標註,兩個為0就是正常的,如果出錯,那一定是你修改的配置檔案有問題,請返回修改。

這時候你訪問 IP/nagios/可以看到如下圖

但點選其他按鈕只能看到

Whoops!

Error: Could not read object configuration data!

Here are some things you should check in order to resolve this error:

Verify configuration options using the -v command-line option to check for errors.

Check the Nagios log file for messages relating to startup or status data errors.

Make sure you've compiled the main program and the CGIs to use the same object data storage options (i.e. default text file or template-based file).

Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at .

提示,這是因為你還沒有啟動nagios後臺程式,按如下命令啟動nagios

# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

# /usr/local/etc/rc.d/nagios start

這個時候你返回剛才的URL,點選Tactical Overview


證明你已經配置成功nagios了。使用我就不在這裡講了,網上有一些文章專門介紹。讓我們開始進入cacti的世界。

第二章:npc外掛的安裝

就和其他外掛的安裝一樣

# tar xzvf npc-0.1.1a.tar.gz //這會出現一個npc目錄

# mv npc /plugins/

# vi /plugins/npc/neb/inserter.c

修改第143行

&mysql,"localhost","USERNAME","PASSWORD","DATABASE",3306,NULL,CLIENT_MULTI_STATEMENTS

把以上幾個大寫字母地方改成你自己實際情況,不會改的看我下面的例子

&mysql,"localhost","***","***","cactidb",3306,"/tmp/mysql.sock",0

否則make 會出現如下錯誤

# make

gcc -g -O2 -Wall -o inserter.o inserter.c -shared -I../include -I/usr/include/mysql -lmysqlclient -fPIC

inserter.c: In function `nebmodule_init':

inserter.c:143: error: `CLIENT_MULTI_STATEMENTS' undeclared (first use in this function)

inserter.c:143: error: (Each undeclared identifier is reported only once

inserter.c:143: error: for each function it appears in.)

make: *** [all] Error 1

# cp /plugins/npc/neb/* /modules/

# cd /modules/

# make

這裡做的主要是編譯inserter.o檔案,要注意的問題:

gcc -g -O2 -Wall -o inserter.o inserter.c -shared -I../include -I/usr/local/mysql/include/mysql -lmysqlclient -fPIC

/usr/bin/ld: cannot find -lmysqlclient

collect2: ld returned 1 exit status

make: *** [all] Error 1

這個錯誤是不能找到libmysqlclient,這個其實是mysql版本問題,我們當前環境下沒有能包含mysql早期版本的庫,就會出現這個問題,好在mysql官方已經給我想到了解決方法,你下載一個和你當前用的版本一致的MySQL-shared-compat-***.i386.rpm包,它就是原來解決這個問題的。(***是你的版本)

編譯後會發現有個inserter.o檔案

# cp insert.o /usr/local/nagios/modules/

如果沒有modules資料夾,你要自己建立一個。

# vi /usr/local/nagios/etc/nagios.cfg

設定如下

retain_state_information=0

event_broker_options=-1 and

broker_module=/usr/local/nagios/modules/inserter.o

原因作者寫得很清楚:

NOTE: Setting retain_state_information=0 causes all hosts and services to go to a pending state until rechecked by Nagios. Without this setting the inserter module will never update any data in NPC. Its a minor inconvenience that I will try to fix in the inserter module.

# vi /include/config.php

加入$plugins[] = 'npc';到$plugins = array();下面,完成後如下:

$plugins = array();

$plugins[] = 'thold';

$plugins[] = 'monitor';

$plugins[] = 'npc'; //這個需要你自己新增的,如果不是很理解請參考我寫的 外掛安裝

$plugins[] = 'reports';

$plugins[] = 'haloe';

$plugins[] = 'update';

登陸你的cacti

點選--Console--User Management--admin

向下拉看到

Realm permissions control which sections of Cacti this user will have access to.

找到View NPC 副選框,點上鉤,如下圖,為了看得方便我把它圈起來了。


這樣,我們就可以看到如下


NPC外掛出現了!!這個時候你還要檢查你的cactidb中是否多了npc開頭的資料庫,如果沒有,請重新登陸cacti介面。

我們點選npc,就可以看到相應的情況了,如下圖


那麼恭喜你,整合安裝結束了,你想擴充套件什麼,直接按原來的nagios方法進行就可以了,但不同的是cacti也可以提供相應的監控介面來幫助你整合資源。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-245721/,如需轉載,請註明出處,否則將追究法律責任。

相關文章