|
|
1.ndoutils安装准备 6 C+ r# p, I0 O" r- n8 j+ e
ndoutils是nagios的一个插件,就是可以用来把nagios的获取的数据存入到mysql数据库中。这个工具的安装是个关键。
1 ^: O% y& s8 ^$ H$ c, k9 Z9 j(1)nagios环境的准备,以上环境应该是可用的 ! O/ C1 f3 L& m" k# r5 A9 p) b
(2)mysql数据库环境
; z- G! h5 T+ z( u! L" x下面两条命令用来生成ndoutils所需要的数据库表等,这些表默认以“nagios_”为前缀;install脚本命令必须在db子目录内执行: ( b# u, C. d+ I) B3 m
6 ?3 P. O1 f" Q* @' c
# cd db # ./installdb -u nagios -p nagios -h localhost -d nagios 其中各选项的意义如下:
# K. k9 q9 U# ~4 o" Q: O; V3 `) }+ W2 y
-u用来指定导入时所用的mysql用户帐号 3 G2 s5 Z2 K# [2 M. C
4 ~0 e7 y1 p* m* s% ^- A+ v-p表示前面mysql用户的密码
( E. _0 I+ [/ X
3 }4 t/ F9 P3 ]# i/ a5 u& L-h表示mysql服务器地址,如果是localhost,则可以省略 7 V! |" a4 H1 M4 ?
z: H8 u: X! s-d表示目标数据库 4 L3 b% R& G0 \ C
' x. u' E) d2 l8 i- J: k/ t说明:如果与cacti整合的话,npc插件会在cacti的数据库自动生成ndoutils所需要表,这些表均以“npc_”为前缀。后面讲到整合的文章中会继续对些做出说明。 . H* ^' p% q I: G
, l, U# b' u4 h5 d5 A+ ^
(3)相关软件包的安装确认 1 d# w3 n/ {4 `( W+ i3 R7 D( T
perl-DBD-MySQL
7 n3 Y8 f" T/ Emysql
* G, q N3 j% |7 c# a amysql-devel
$ g4 F& h- n2 lphp-json-ext-1.2.0.tar.bz2
! l, t6 `- C! d6 a& M8 rcd /usr/src
" i# z8 ]+ g; p- w# Uwget http://ncu.dl.sourceforge.net/pr ... outils-1.4b9.tar.gz
, `; R; `2 L3 d. ]. V/ twget http://www.cpan.org/modules/by-module/DBI/DBI-1.624.tar.gz 7 _$ V5 }( ~4 }4 [
wget http://www.cpan.org/modules/by-module/DBD/DBD-mysql-4.024.tar.gz ' z8 r/ M, b/ r* N. h# l! O
2. php-json的安装 ; k4 @6 y1 R1 q5 E4 |8 P
# tar zxvf php-json-ext-1.2.0.tar.bz2 + W% m& Z! v0 i$ [( I; L, i8 |
# cd php-json-ext-1.2.0
' D4 j7 I( a/ Z0 J5 ^3 F$ { k/ f# /usr/bin/phpize
: B6 j9 @1 P! F r. A" }2 O# z# ./configure --with-php-config=/usr/bin/php-config
4 X0 f) E7 k" v! ]# e# G6 ]8 L- s- x# make 4 l. _3 z" j: }8 G% s0 v3 b! i
# make install
: i1 H4 u. H/ F. D2 B. r# 说明:json库的位置 . A8 Y" j/ p8 J) a7 U: S! V
Installing shared extensions: /usr/lib/php/modules/
" T: @9 U. o/ W2 `; K# 把PHP扩展加入配置文件
4 ~2 W! R$ S' T' A Z0 X; @: M( Z& v- g# vi /etc/php.d/json.ini
. C9 E8 f9 l8 j+ a/ F# P- y4 aextension=json.so * b2 }# P3 u& v# [! l% r
3. ndoutils的安装
; W3 A K7 p1 r' o8 ~! G1 ]# [' X& m# cd /usr/src/ : B: X; T; R- T$ ]) }% {
下载ndoutils-1.4b9.tar.gz 2 i% e" B4 H; l' M9 z' _! ?
# wget http://ncu.dl.sourceforge.net/pr ... outils-1.4b9.tar.gz
- }, b, t! E: w* M5 G# tar zxvf ndoutils-1.4b7.tar.gz 2 C( B1 b5 h3 Y, W! W
# cd ndoutils-1.4b7
7 {2 r/ P u m# {; {% N#./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios LDFLAGS=-L/usr/lib64/mysql
! Y3 x7 r! r/ U# make W1 y* R7 e U7 C& R4 o: Q
9 [2 a- H' q. s5 s+ r' v. d
# cd src/
& ` k1 k/ C9 J. w& D" v5 d# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin/
" }, Z! a3 y1 ^6 ^, Z# cd ../config 9 C7 K) Q- D) ], a$ k3 K
# cp ndomod.cfg-sample ndo2db.cfg-sample /usr/local/nagios/etc/
; g) D) q( z0 A# R0 U+ _2 y6 B# cd /usr/local/nagios/etc/ 3 x3 Y8 r4 j, V5 {: L
# mv ndomod.cfg-sample ndomod.cfg
/ V+ z6 C4 a/ F7 @3 j. e# mv ndo2db.cfg-sample ndo2db.cfg " Z2 e# p! B9 g+ g+ A# ^
* ~( C8 r6 j! h/ G# T7 K& I/ G2 Z. j3 F
4. 修改配置文件 $ _1 O. @# x! s( U: w) J
# vi /usr/local/nagios/etc/ndo2db.cfg
( ~* g: I) N' D+ m; Odb_name=nagios
/ G0 `5 I7 R" A0 q+ ]/ `% }db_host=192.168.1.80 (远程数据库地址)
( O* D$ k1 Q* b/ e- ]5 ddb_user=nagios
8 i7 ^+ I7 g; _$ xdb_pass=nagios 4 ^4 x6 W% u5 Z3 O6 q7 u8 B
debug_level=1
* C+ @. d% o3 V: C2 B这里是用Cacti在mysql中使用的用户和密码以及数据库,远程数据库的话应正确指定数据库IP,以及用户名帐号权限。
/ O3 @& M1 A: j! ~0 E# vi /etc/nagios/ndomod.cfg # 可以随便指定一个位置 ; \) o0 N5 u. L
output=/usr/local/nagios/var/ndo.sock
" |. `/ ^' e% u, c7 i" abuffer_file=/usr/local/nagios/var/ndomod.tmp
4 ^) [% k( R* f+ |4 j# vi /usr/local/nagios/etc/nagios.cfg ; D2 r. N" V1 b1 q3 P8 O, I
# 以下三条检查一下,默认就是以下内容 * e7 s5 `4 c, r0 S& _: r
check_external_commands = 1 2 m2 t( ?+ \) ?& @
command_check_interval = -1 ' d7 a( w; w- G4 ~4 _" I( G/ @' }
event_broker_options = -1 - z) X2 o5 e p7 x9 h l8 v8 K
process_performance_data=1
' g- f, p9 t h2 c# 注意是一行内容 , R5 }4 v) b, ]+ Q
broker_module = /usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
! t, ^ m$ H) O5. 启动ndoutils,也是最麻烦的一点 $ w0 U# r+ c- ~
(1) ndoutils的先启动
4 I" N# Q& M0 f, ?. U#/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg 2 X4 [+ D0 ~4 f3 q& ?6 h/ e
测试如果出现以下提示,应删除对应sock文件再次启动OK
0 C/ k, U2 ]. y2 N. mCould not bind socket: Address already in use
0 n: M+ x" [, s( G, d5 M(2) nagios重启 % z% }9 x: e5 p2 |
# service nagios restart
: C6 s- F) e; P6 k说明: 其中的启动日志都记录在/var/log/messages中,可以直接查看有无错误。
/ @4 d6 o8 y1 c/ ^- l$ j q8 r, a3 R7 w4 r' `* ?
故障排除:
& X3 Y5 q) M3 l/ r; u如果/var/log/message里出现 $ U' d- @' }$ t3 {; s' Z: m- y
ndoutils not connect 则 chown -R nagios.nagios /usr/local/nagios/
* b+ K7 I- k2 N+ s# d' Q8 [若出现: . h) ^" s* `2 x7 K* H+ j
Still unable to reconnect to data sink 则 rm -f ndo2db.sock 然后 restart ndoutils服务 |
|