|
|
使用NDOUtils将Nagios监控信息存入MySQL
/ ^: J- w, x: g' \2 K4 d9 C) L+ D1.NDOUtils安装需求
! g" {% @& N3 e: f" Jnagios
X' [) ]0 ^' X0 Fmysql( B# ^0 s/ ?# }0 K
cpan DBI #非必需( y: _& V u+ u7 L
cpan DBD::mysql #非必需! T0 ^/ N7 s8 T" L' ~9 t
2.关联mysql头文件和库( T! T- v; r! j2 @* i, c i
不做关联可能在config或make时出错7 ]6 H/ ?5 r- V4 t
ln -s /opt/mysql/include/* /usr/include/
3 u* O( I- l: G; j* p4 |7 k tln -s /opt/mysql/lib/* /usr/lib/1 t2 A- _" z' P
echo ‘/usr/lib’ >> /etc/ld.so.conf
8 z2 a! C+ |7 v g- o$ lldconfig -v3 C- f: M* W7 L$ B
3.安装ndoutils
9 @& A* c4 N3 L# D) l, s0 n' ohttp://sourceforge.net/project/showfiles.php?group_id=265896 ]* ^0 G1 ?" ~) o
wget -c http://nchc.dl.sourceforge.net/s ... outils-1.4b7.tar.gz, }/ O, I/ J8 R
tar zxvf ndoutils-1.4b7.tar.gz8 P5 q% v$ O! Z! N) G" D
cd ndoutils-1.4b7- r& _) A( c0 w. Q d, p3 }9 y6 L# N
./configure –prefix=/usr/local/nagios –enable-mysql –disable-pgsql LDFLAGS=-L/opt/mysql/lib –with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql
$ m% w$ {) M0 t" A# e4 x2 p+ T*config时使用以下mysql参数
! l% G0 N0 D; ^–with-mysql-inc=/opt/mysql/include –with-mysql-lib=/opt/mysql/lib) G! V# c: ~2 \3 b
#config成功
# C1 ~3 N4 p! T& ? w6 I#make出错9 q$ i" n4 s! J5 w& Y
*config时使用以下mysql参数
. {. u2 D P7 N4 x: B# @ P$ o–with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql2 ]; |) i6 X- N* M, N" O* }9 K
#config出错
$ o2 b5 b* y: z/ g4 q! O#make成功并生成文件8 j. _3 h9 M$ H A# C& E
#启动ndo2db会出错, ]8 N" F5 ^7 d( c( }. }4 |- {- j( z
*没有LDFLAGS=-L/opt/mysql/lib4 s! r5 R1 v7 O! I+ o: V. c$ k0 w2 d4 N
<del datetime="2009-05-27T06:58:24+00:00">LDFLAGS=-L/opt/mysql/lib </del>9 ]- z9 L! {' W( \0 p( n
#ndo2db不能导入到数据库
3 ?8 E: J7 C" i9 E/ O相关错误
. d! I* _' l0 e" t- h. e8 pIn file included from io.c:10:
& O2 Q x* w& o# A../include/config.h:261:25: mysql/mysql.h: 没有那个文件或目录
6 q; w, ^0 C% g9 b9 P# t, Y3 l../include/config.h:262:26: mysql/errmsg.h: 没有那个文件或目录4 C, _* a! C9 u+ `' Z" {! {
make[1]: *** [io.o] 错误 16 P8 X0 w$ ~& P" i% |* ^
checking for mysql/mysql.h… no, J1 ], M' K5 |: m
; S9 i! }6 v, r
*** MySQL include file could not be located… **********************
& D; k, I% ~ L; b % H0 a" q( }) M- s1 c e* `
You chose to compile NDBXT with MySQL support, but I was unable to
* x1 c; X" G. w! ^locate on your system. If the include file is# W; j/ u8 F& U
installed, use the –with-mysql-inc argument to specify the location) E' W$ I4 d1 E7 a
of the MySQL include file.7 O- a2 n- m, }; F- s5 A
make7 x y5 z0 m* _# S
ll ./src
$ H9 i+ M8 @% F% y9 ?- B# `看看是否有以下文件
& A( t* ` O5 x3 Hndo2db-2x
+ f2 e+ T4 J! U* Pndo2db-3x
, z6 R, i% v$ N' e; Qndomod-2x.o* U: O, J) `! j( s
ndomod-3x.o
& H& V; J$ c. d! F' `4.拷贝文件
" |8 _ K( r: |( W& u# 我的Nagios是3.0.6,所以拷贝的是ndomod-3x.o、ndo2db-3x,如果你的是2.X.x请拷贝ndomod-2x.o、ndo2db-2x, q) f6 t6 N) @6 ]
cp ./src/ndomod-3x.o /usr/local/nagios/bin
3 A% o& o+ ^8 @0 v- ?6 jcp ./src/ndo2db-3x /usr/local/nagios/bin8 W/ Q ~1 ~/ F# Z
cp ./src/log2ndo /usr/local/nagios/bin
f) E8 h3 p. b, L i/ |cp ./src/file2sock /usr/local/nagios/bin
1 U, P& V' k' t# `chown nagios:nagios /usr/local/nagios/bin/*
# D" z9 r8 u+ }$ G, L8 m5 [5.拷贝配置文件
6 ?# J: b' J0 w7 Ncp ./config/ndo* /usr/local/nagios/etc/
3 \; i) m3 I$ t: I7 qchown nagios:nagios /usr/local/nagios/etc/*
) H _! ]1 {. J0 Y6.创建ndo的mysql 数据库及用户
% P1 \ b( i( HCREATEDATABASE`nagios`DEFAULTCHARACTERSETutf8COLLATEutf8_general_ci;
: z i, q+ I5 Z7 k$ IGRANT select,insert,update,deleteONnagios.*TOnagiosndo@localhostidentifiedby’password123′;/ W6 X7 [; Y7 X0 y/ r0 T# P/ b
FLUSH PRIVILEGES;
+ d; [2 n" L7 R! J6 Q1 [7.导入数据库结构: c! u2 m2 x) L$ q. N$ w$ I
使用db/installdb脚本
( m9 B5 q8 ]. b) l需要以下支持# f5 [8 ?$ j: ^8 R5 N+ o
cpan DBIcpan DBD::mysql
$ B) [5 }6 I0 m" bcd ./db/- L2 \, }4 t. I% J/ P7 J
./installdb -u root -p 123456 -h localhost -d nagios; M- K. c6 w# y0 b1 ^
用命令导入(其实和用脚本是一回事,也可以用phpmyadmin来导入)' ~, I. Q6 i% f+ F6 \+ M
/opt/mysql/bin/mysql -u root -p -D nagios -h localhost < ./db/mysql.sql
' R/ p6 \1 B8 y输入密码" I8 d7 b C# |0 T; A. y
成功导入59张表5 h' N& s5 f, D; Q$ n0 X
8.修改配置文件1 ~3 }# I3 E9 u) z6 I
vi /usr/local/nagios/etc/ndo2db.cfg/ D: @& |6 e' k: Z8 [) k7 R
db_user=nagiosndo3 M8 a1 S4 p$ F) v @7 c$ X, e. s
db_pass=password123' t5 y8 j; }1 O$ e) H$ p: ^
vi /usr/local/nagios/etc/nagios.cfg
. P2 I+ V8 W7 U0 l! n2 C# 修改下面参数的值为-1(一般默认如此)。) i3 Q7 o: Y! F
event_broker_options=-1
# l( M* ?& S9 I) x" P3 Y' u# 复制下面内容粘贴到#broker_module=…下面。
$ X, @# D& O' R V! r |+ \- [: Z# 注意broker_module= 和config_file是在一行上
* y6 x! f E/ a: j0 \0 t0 Q# Uncomment the line below if you’re running Nagios 3.x% T3 a0 `$ ?1 g
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg2 [' d4 P5 ]1 v# T+ a: V+ A5 g
9.启动ndo2db; M4 G# ?! Y# j; f# \
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
& i3 s: m& J2 S& J% I+ b
, c" z2 M t! f8 Gecho ‘rm -f /usr/local/nagios/var/ndo.sock’ >> /etc/rc.local1 U7 S7 T7 [3 Z* X
echo ‘/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg’ >> /etc/rc.local+ b1 W. y8 i* M4 \
#开机启动2 q' h; C0 B S2 f
Support for the specified database server is either not yet supported, or was not found on your system.+ X- @5 ^% S; T
/usr/local/nagios/bin/ndo2db-3x: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
3 r5 l3 b$ z% {( v2 T# ^出现以上错误请执行第2步1 o( `) r; I7 m% f. Y+ m- o6 A/ |
10.重启动nagios, l4 b5 @3 ^/ }
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
9 m: S& ^8 Z/ M$ d9 kservice nagios restart8 p8 E' h. j' t) F. r
一般情况下到此已完成安装,可以去数据库里看下记录有无增加
5 X& }8 @* Z5 }( |" x4 b11.检查安装是否正确. Q0 d- z! v4 H) e- m+ ^# d; p& E
tail -20 /usr/local/nagios/var/nagios.log( C* S- d4 c2 ~
[1242971625] ndomod: Successfully flushed 80 queued items to data sink.[1242971625] ndomod: Error writing to data sink! Some output may get lost…& [: v: ?$ f* P# c
貌似有点问题
% R( q& S# C5 B% Z先改成输出成文件#vi ndomod.cfg6 \( Y8 W4 A& O
instance_name=default5 t& ]) N4 F2 k* ?. U. Z+ z# x% M
#output_type=tcpsocket
" {2 C1 T+ u% S2 i- f#output=127.0.0.1* j* L3 N% j8 x3 c; S
+ W* n) W' _' U5 Boutput_type=file
( e& v! r! p4 J1 C/ k6 g5 Soutput=/usr/local/nagios/var/ndo.dat: Y! R2 U9 O- }$ R2 B
service nagios restart
" {1 y8 V" \+ I7 ~ |看看有没有/usr/local/nagios/var/ndo.dat文件,ok,发现文件,说明第一步可以生成文件查看文件内容& }# M" Y8 f8 m! Z1 Y+ f( E
cd /usr/local/nagios/var/8 |1 Q- o7 F4 P$ B, \
head -30 ndo.dat5 C G. [1 z8 K/ l
; K! e7 {6 ]3 A3 E' u+ s1 n$ rHELLO
% _7 ?- X5 A& S( \0 VPROTOCOL: 2
+ f8 N3 e( `7 Y% i( `AGENT: NDOMOD% T! d' C6 a- W
AGENTVERSION: 1.4b7
' b0 L& z5 T2 X, s: d2 D, _STARTTIME: 1243393299
6 g+ ^7 ?- M' p; D" s0 `; ODISPOSITION: REALTIME4 x/ c2 Y- j. Q9 g: t
CONNECTION: FILE
) O) [1 r+ U( ]! p6 E$ G' oCONNECTTYPE: INITIAL s& Z8 A& }( |# Q
INSTANCENAME: default) n' P- T. I) I# I- v( K5 S
STARTDATADUMP5 ]& C! |9 ~& W5 U
4 n# j# }8 {4 R1 C
2 C6 ~/ K) e$ h4 g' g& V' y$ S* d202:
- L, u* H; }8 [6 S* v$ u1=300( @6 I2 W) R( i
2=0( G& c% ^: g1 o- v& ]. Z
3=0
7 w3 e+ {0 z M# H# O5 G4=1243393292.450675 t6 Q- \3 T7 L
73=1243393292
9 F6 h- I% N) K7 A74=262144/ ]( z% u' e0 y
72=ndomod: Error writing to data sink! Some output may get lost…- ?: p; b) x# q: M0 v8 q9 u
999+ `; b9 v7 N. C6 ?
( F4 l9 K. T% {# m
: j' r& |. i) W% R
2 V% D( T1 g* j201:, K6 Y; y* g% |7 R9 F3 M
1=205
/ x9 H8 C- o2 { ]" Z) s2=0& J c2 V6 c. h0 A3 O/ ?
使用file2sock尝试socket方式
' |. o' B y! T1 [../bin/file2sock -s /usr/local/nagios/var/ndo.dat -d /usr/local/nagios/var/ndo.sock -t unix -p 5668) X2 T& }: D) X% D$ F8 u" H8 y
Error while writing to destination socket: Connection reset by peer
+ b1 G6 v5 |8 S: q尝试tcp方式
3 N) f, Q5 m7 d( N# ~vi ndo2db.cfg2 V& N* X) Z3 v* e o! f4 f" g
#socket_type=unix% T# p ?& ]. s, W
socket_type=tcp
7 h" K* B- I! H1 j5 ~$ {! a重新载入ndo2db
9 n# J- ~2 O/ Y2 w' G d. v) Fps aux|grep ndo2db
& p8 e6 t; M- h. ~kill $pid
& i4 l: A B% r/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
+ H4 I v5 T- ? / h b+ _7 U- K, e; L# x2 H
../bin/file2sock -s ndo.dat -d localhost -t tcp -p 5668- ~# l3 @" d' k% A
Error while writing to destination socket: Connection reset by peer. e; j5 x0 _. _# b- O& t3 m
依然不行,重新编译ndoutils并加上 LDFLAGS=-L/opt/mysql/lib6 H7 f1 p0 W7 ^/ l9 V' X) D5 p
./configure –prefix=/usr/local/nagios –enable-mysql –disable-pgsql LDFLAGS=-L/opt/mysql/lib –with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql1 E/ \5 |6 G, i! a/ L
make
; q8 J* f0 [) P$ x" R/ s! X# z#再执行一下安装过程后,通过/ D7 Y2 q0 ~6 i
=================200912-07 更新, }1 b2 g/ S" P6 w2 u+ r3 j$ e
tail /var/log/messages p- t2 o1 k! {. f
Dec 7 14:09:13 localhost nagios: ndomod: Still unable to connect to data sink. 10547 items lost, 5000 queued items to flush.; @. d9 U1 j2 G5 b6 y- Y
Dec 7 14:09:29 localhost nagios: ndomod: Still unable to connect to data sink. 10746 items lost, 5000 queued items to flush." C) s' F: Q8 N5 E, X8 b
连接不到mysql,重启一下; ]. g5 W! F8 E) ]
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg* Z3 e, e& P/ U% ^$ q+ O9 \( P, o. z
Could not bind socket: Address already in use4 K# r5 M3 k3 x
ps aux|grep ndo2db没有
7 X4 z) |/ Z8 R5 P. n5 D查看套接字文件是否存在,删除之4 J) }9 q' m# R7 |
ll /usr/local/nagios/var/ndo.sock
/ k& \4 A. R! ~: m a5 Zrm /usr/local/nagios/var/ndo.sock
5 m+ h# m+ h8 H8 g8 d1 a重启/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
/ Q, [2 u: t5 J/ dtail /var/log/messages9 n+ v( ^9 k8 h) @3 d
Dec 7 14:09:45 localhost nagios: ndomod: Successfully connected to data sink. 10861 items lost, 5000 queued items to flush.5 j% l% @) N) O# D# b0 b
Dec 7 14:09:45 localhost nagios: ndomod: Successfully flushed 5000 queued items to data sink.
/ }9 H, F5 C/ V6 ^ y$ HDec 7 14:09:45 localhost ndo2db-3x: Successfully connected to MySQL database |
|