溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Cacti與nagios結(jié)合所需插件的安裝與報(bào)錯(cuò)處理

發(fā)布時(shí)間:2020-05-22 14:39:27 來(lái)源:網(wǎng)絡(luò) 閱讀:1297 作者:neijiade10000 欄目:數(shù)據(jù)庫(kù)

Cacti和Nagios安裝這里就不做介紹了

 

我們這里介紹的是nagios與cacti的整合,首先需要安裝php json模塊和ndoutils,其中Ndoutilsnagios的一個(gè)插件,就是可以用來(lái)把nagios的獲取的數(shù)據(jù)存入到mysql數(shù)據(jù)庫(kù)中。也可以實(shí)現(xiàn)與cacti的插件npc的集成,這個(gè)工具的安裝是個(gè)關(guān)鍵。還需要安裝使用npc插件。下面我們來(lái)一一介紹安裝的方法。

 

一、安裝Php-json 

tar xzf json-1.2.1 ;

cd json-1.2.1 ;

/usr/bin/phpize ;

./configure ;

make ;

make install 

安裝完后,然后執(zhí)行如下語(yǔ)句添加json模塊:

echo "extension=json.so" >/etc/php.d/json.ini

 

使用php -m|grep json應(yīng)該可以顯示json這個(gè)字符

Cacti與nagios結(jié)合所需插件的安裝與報(bào)錯(cuò)處理

 

如果沒(méi)顯示這個(gè)字符,證明模塊沒(méi)有安裝正確

解決方法:yum remove php-common,然后重新安裝php-common

 

二、安裝Ndoutils

 

Ndoutils安裝

1.DBI的安裝

到官網(wǎng)http://www.cpan.org/modules/by-module/DBI/ 下載

這里下載的是DBI-1.633.tar.gz

tar -zxvf DBI-1.633.tar.gz

cd DBI-1.633

perl Makefile.PL

make

make test

這里出現(xiàn)test錯(cuò)誤,不用管他,繼續(xù)安裝。

make install

2. DBD的安裝

DBD-mysql-4.025

tar -zxvf DBD-mysql-4.025.tar.gz

cd DBD-mysql-4.025

perl  Makefile.PL --libs="-L/usr/lib64/mysql #mysql 使用yum裝的,檢查配置時(shí)系統(tǒng)一般能找到頭文件和庫(kù)文件的位置,不用過(guò)多配置一些選項(xiàng)

make

make test

make install

3.NDOUTILS安裝

編譯安裝NDOUtils

tar -zxvf ndoutils-2.0.0

cd ndoutils-2.0.0

./configure --prefix=/usr/local/nagios --enable-mysql

make

4.拷貝文件
我的Nagios是3.5.1,所以拷貝的是ndomod-3x.o、ndo2db-3x,如果你的是2.X.x請(qǐng)拷貝ndomod-2x.o、ndo2db-2x

cd  ndoutils-2.0.0

cd src

cp ndo2db-3x ndomod-3x.o file2sock log2ndo /usr/local/nagios/bin

cd /usr/local/nagios/bin

mv ndo2db-3x ndo2db

cd config

cp ndo2db.cfg-sample ndomod.cfg-sample /usr/local/nagios/etc/

cd  /usr/local/nagios/etc

mv ndo2db.cfg-sample ndo2db.cfg

mv ndomod.cfg-sample ndomod.cfg

5.編輯ndo2db.cfg配置文件

vim /usr/local/nagios/etc/ndo2db.cfg

lock_file=/usr/local/nagios/var/ndo2db.lock

ndo2db_user=nagios

ndo2db_group=nagios

socket_type=tcp

socket_name=/usr/local/nagios/var/ndo.sock

tcp_port=5668

use_ssl=0

db_servertype=mysql

db_host=localhost

db_port=3306

db_name=cacti#數(shù)據(jù)庫(kù)名稱

db_prefix=npc_

db_user=cactiuser#數(shù)據(jù)庫(kù)使用者

db_pass=huaxia#數(shù)據(jù)庫(kù)密碼

max_timedevents_age=1440

max_systemcommands_age=10080

max_servicechecks_age=10080

max_hostchecks_age=10080

max_eventhandlers_age=44640

max_externalcommands_age=44640

debug_level=0

debug_verbosity=1

debug_file=/usr/local/nagios/var/ndo2db.debug

max_debug_file_size=1000000

6.配置ndomod.cfg文件

vim /usr/local/nagios/etc/ndomod.cfg

instance_name=default

output_type=tcpsocket

output=127.0.0.1

tcp_port=5668

use_ssl=0

output_buffer_items=5000

buffer_file=/usr/local/nagios/var/ndomod.tmp

file_rotation_interval=14400

file_rotation_timeout=60

reconnect_interval=15

reconnect_warning_interval=15

data_processing_options=-1

config_output_options=2 

8.配置nagios.cfg文件

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

# 修改下面參數(shù)的值為-1(一般默認(rèn)如此)。

event_broker_options=-1

# 復(fù)制下面內(nèi)容粘貼到#broker_module...下面。

# 注意broker_module= config_file是在一行上

# Uncomment the line below if you're running Nagios 3.x

broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

process_performance_data=1#注意該參數(shù)修改成啟動(dòng)狀態(tài)

9.配置啟動(dòng)腳本

cd  /usr/local/src/ndoutils-1.5.2

cp daemon-init /etc/init.d/ndo2db

chmod +x ndo2db

10、啟動(dòng)ndo2db服務(wù)

Service ndo2db start 

11.重啟nagios

service nagios restart

12.查看啟動(dòng)日志信息

[root@BestTone-zabbix var]# tail -f nagios.log

[1468292167] Successfully shutdown... (PID=29500)

[1468292167] ndomod: Shutdown complete.

[1468292167] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' deinitialized successfully.

[1468292167] Nagios 3.5.1 starting... (PID=14197)

[1468292167] Local time is Tue Jul 12 10:56:07 CST 2016

[1468292167] LOG VERSION: 2.0

[1468292167] ndomod: NDOMOD 1.5.2 (06-08-2012) Copyright (c) 2009 Nagios Core Development Team and Community Contributors

[1468292167] ndomod: Could not open data sink!  I'll keep trying, but some output may get lost...

[1468292167] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.

[1468292167] Finished daemonizing... (New PID=14198)

[1468293079] ndomod: Still unable to connect to data sink.  721 items lost, 5000 queued items to flush.

 查看到報(bào)錯(cuò)信息ndomod: Could not open data sink!  I'll keep trying, but some output may get lost...

[1468293079] ndomod: Still unable to connect to data sink.  721 items lost, 5000 queued items to flush.

從報(bào)錯(cuò)的信息可以看到ndomod沒(méi)有把數(shù)據(jù)存到cacti數(shù)據(jù)庫(kù)里,錯(cuò)誤解決方法:

vim /usr/local/nagios/etc/ndo2db.cfg

ndo2db_group=apache#修改數(shù)據(jù)庫(kù)的屬組為apache

cd /usr/local/nagios/bin

chown nagios:apache ndo*#把兩個(gè)主程序的屬組改為apache

 cd ../etc

chown nagios:apache ndo*#把兩個(gè)配置文件的屬組改為apache

13、重啟相關(guān)服務(wù) 

service ndo2db restart

service nagios restart

14、再次查看啟動(dòng)日志,發(fā)現(xiàn)啟動(dòng)成功,ndomod已經(jīng)連接上cacti數(shù)據(jù)庫(kù)

[root@localhost ~]# tail -f /var/log/messages
Mar 24 09:31:25 localhost nagios: ndomod registered for retention data'
Mar 24 09:31:25 localhost nagios: ndomod registered for contact data'
Mar 24 09:31:25 localhost nagios: ndomod registered for contact notification data'
Mar 24 09:31:25 localhost nagios: ndomod registered for acknowledgement data'
Mar 24 09:31:25 localhost nagios: ndomod registered for contact status data'
Mar 24 09:31:25 localhost nagios: ndomod registered for adaptive contact data'
Mar 24 09:31:25 localhost nagios: Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
Mar 24 09:31:25 localhost nagios: Finished daemonizing... (New PID=1828)
Mar 24 10:31:25 localhost nagios: Auto-save of retention data completed successfully.
Mar 24 10:47:35 localhost kernel: hrtimer: interrupt took 3738538 ns

三、安裝npc軟件

 

tar  -vxzf  npc-2.0.4.tar.gz ;

 

mv  npc  /var/www/html/cacti/plugins/

 

1、通過(guò)界面啟動(dòng)npc

Cacti與nagios結(jié)合所需插件的安裝與報(bào)錯(cuò)處理

 

2、在Cacti的"console"的"Settings"里設(shè)置好nagios命令文件的主路徑和nagios的URL的路徑,注意勾上"Romote Commands"項(xiàng),點(diǎn)擊"Save"按鈕

 

Cacti與nagios結(jié)合所需插件的安裝與報(bào)錯(cuò)處理

 

3、再cacti數(shù)據(jù)庫(kù)里,執(zhí)行下面的sql語(yǔ)句

mysql里面執(zhí)行如下sql即可:

mysql> use cacti;

alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;

alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output; 

alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output; 

alter table npc_notifications add long_output TEXT NOT NULL default '' after output; 

alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output; 

alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output; 

alter table npc_statehistory add long_output TEXT NOT NULL default '' after output; 

alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output; 

 

4、執(zhí)行成功后,重啟nagios和ndo2db,下面界面是nagios與cacti的整合效果圖:

Cacti與nagios結(jié)合所需插件的安裝與報(bào)錯(cuò)處理

 

遇到的問(wèn)題

1)、假如這里的Nagios的狀態(tài)是off

我也曾遇到,主要是檢查ndo2db連cacti庫(kù)是否正常,可以查看/var/log/messages

里的日志信息,看不到信息可能是你的ndomod.cfg和ndo2db.cfg配置有錯(cuò)誤!建議檢查配置文件。同時(shí)在cacti數(shù)據(jù)庫(kù)里執(zhí)行上面提示的幾條sql語(yǔ)句。

 

2)、假如nagios狀態(tài)欄無(wú)信息

在cacti的數(shù)據(jù)庫(kù)中找到表npc_programstatus,從表中選取programstatus_id、instance_id、status_update_time、last_command_check、last_log_rotation等幾個(gè)字段并刪除前面的一條記錄,刷新一會(huì),應(yīng)該就可以出圖。如下圖所示:

Cacti與nagios結(jié)合所需插件的安裝與報(bào)錯(cuò)處理

 

 

 

 

 

 

 

 

 

 

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI