|
|
使用NDOUtils将Nagios监控信息存入MySQL
( E* T9 M% {7 B. M$ @. B1.NDOUtils安装需求& G/ A o5 |( Z5 R. o4 |
nagios
/ b" z. p) _" `# n0 I6 k. a/ bmysql
1 O: m6 f$ a" t: ^; S1 Ucpan DBI #非必需
. \; |8 H d, s _0 [4 Vcpan DBD::mysql #非必需
* |* n. L9 U7 u+ v+ @7 y2.关联mysql头文件和库
3 `; R- g H! J+ M7 N- `不做关联可能在config或make时出错1 f0 b' w! l- P& V2 i1 Y
ln -s /opt/mysql/include/* /usr/include/
$ w' v/ c' S4 U ]5 ~. jln -s /opt/mysql/lib/* /usr/lib/* U9 v3 R& s1 T
echo ‘/usr/lib’ >> /etc/ld.so.conf
' D! A0 d- A; k1 R4 H7 ?$ q3 F# L$ G* rldconfig -v; f/ `/ K: S7 C( F8 X* n
3.安装ndoutils0 a3 _4 ~$ G/ H- N1 p
http://sourceforge.net/project/showfiles.php?group_id=26589+ d" _5 L; H2 V. v( W
wget -c http://nchc.dl.sourceforge.net/s ... outils-1.4b7.tar.gz
! M' ?% B$ S0 ?1 Ntar zxvf ndoutils-1.4b7.tar.gz
0 P/ r* h7 J7 [3 H$ ~7 Vcd ndoutils-1.4b7
7 \' |5 }8 n4 \5 j, @./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
/ w5 Z) [3 {! u% c2 \# F! x5 G# b/ n*config时使用以下mysql参数$ C+ W2 |8 G$ t. l- @7 Z; X
–with-mysql-inc=/opt/mysql/include –with-mysql-lib=/opt/mysql/lib* a, F/ ?$ B" |. x6 t/ v
#config成功3 s/ M4 D. P2 d- D
#make出错
$ T6 L8 n B) E2 D: p0 K7 A*config时使用以下mysql参数
2 Y+ ^5 ]: F. D" {' ]–with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql4 R! a4 l' c1 C, q. t5 G* x
#config出错, d8 D; y7 _5 r# X1 D+ O7 J
#make成功并生成文件! y/ s( y) N! N. n
#启动ndo2db会出错# f" I- c1 c$ c4 v3 K! ]- H
*没有LDFLAGS=-L/opt/mysql/lib
7 l" P2 D0 D; d<del datetime="2009-05-27T06:58:24+00:00">LDFLAGS=-L/opt/mysql/lib </del>5 Z$ G* {/ t( e' ^7 h- P
#ndo2db不能导入到数据库$ @$ i* Z$ X X" \ I
相关错误( s7 M( ?3 ]- h& A; F0 w4 w
In file included from io.c:10:2 m) C: I& | ?+ @! z+ L
../include/config.h:261:25: mysql/mysql.h: 没有那个文件或目录0 Y$ C6 V. n F
../include/config.h:262:26: mysql/errmsg.h: 没有那个文件或目录; x6 V7 m3 Z, O1 p& c* W5 x* ]
make[1]: *** [io.o] 错误 1" y% N+ v* z h. W3 G/ o
checking for mysql/mysql.h… no+ Z0 ?5 x9 a( K1 l2 l2 b- s
2 w- z2 H) j+ O9 ?( T
*** MySQL include file could not be located… **********************) O* ?! d! V, `. W2 j; D
. @1 n9 n3 `. c8 o+ B
You chose to compile NDBXT with MySQL support, but I was unable to
7 _" i5 G6 w$ Q/ b* N) Q# ylocate on your system. If the include file is
% c P# G3 f# R/ B$ M8 [2 ^4 Einstalled, use the –with-mysql-inc argument to specify the location5 {7 p1 S6 R, ], {. {% n- y
of the MySQL include file.
2 ?8 c" @. }( i" Q: Rmake
. ]/ B i4 l8 A {: G- Fll ./src
, W+ @+ J3 L W& v& d2 H. c看看是否有以下文件
7 Z0 V" w9 o( {ndo2db-2x
3 ~0 J+ V. @1 w1 V, X4 Yndo2db-3x* M: k9 L+ \* K; ]3 h
ndomod-2x.o- r& f1 X4 r/ t5 m) }
ndomod-3x.o. i* `8 T1 k+ _9 ]8 [
4.拷贝文件) i/ Z; I) }1 ~; e6 L2 `
# 我的Nagios是3.0.6,所以拷贝的是ndomod-3x.o、ndo2db-3x,如果你的是2.X.x请拷贝ndomod-2x.o、ndo2db-2x' J( v0 U; E6 f; b& S x2 M
cp ./src/ndomod-3x.o /usr/local/nagios/bin
7 @) s$ U) Q$ i. qcp ./src/ndo2db-3x /usr/local/nagios/bin
4 d* z8 f- S1 W# i& E9 {& \cp ./src/log2ndo /usr/local/nagios/bin; x ]. B1 [: C3 _/ K
cp ./src/file2sock /usr/local/nagios/bin+ G; p+ R2 ?3 a5 e" _
chown nagios:nagios /usr/local/nagios/bin/*! A! l0 E' i9 n7 `& D
5.拷贝配置文件
9 d# P6 }4 j; lcp ./config/ndo* /usr/local/nagios/etc/
. L3 Z$ {9 x' S* \4 @chown nagios:nagios /usr/local/nagios/etc/*3 b- t' j; K! f$ d0 S# V
6.创建ndo的mysql 数据库及用户
( h: ~+ p' R2 `3 Z0 ?: _+ j3 jCREATEDATABASE`nagios`DEFAULTCHARACTERSETutf8COLLATEutf8_general_ci;
1 B0 H" @( B) M7 M8 i- P5 NGRANT select,insert,update,deleteONnagios.*TOnagiosndo@localhostidentifiedby’password123′;# [- b) k2 V0 e+ _+ {
FLUSH PRIVILEGES;
! I2 q( R8 ]/ B! Z, H6 Q7.导入数据库结构
' u* T4 s$ | |, L# N, k: b使用db/installdb脚本
2 \4 ^' D' C. [0 C6 m2 C9 c需要以下支持& G5 x4 z# T, R! l3 c6 ~7 S" h
cpan DBIcpan DBD::mysql
3 B$ m% W% Q. H0 Q. {cd ./db/
) t6 V# k/ ~& p# T/ E5 }./installdb -u root -p 123456 -h localhost -d nagios
1 r, L( p+ N9 o! u ]用命令导入(其实和用脚本是一回事,也可以用phpmyadmin来导入)/ m, F5 J0 r* X8 O* d) [
/opt/mysql/bin/mysql -u root -p -D nagios -h localhost < ./db/mysql.sql
# D* h/ X) e9 |- |) \- ?% J输入密码" t7 r+ p8 a, t2 b( C, j
成功导入59张表
1 \/ j, N+ R- w3 b) U, w+ s. O/ i8.修改配置文件' P* W' E/ B8 D' k% I% t G5 r
vi /usr/local/nagios/etc/ndo2db.cfg
5 v% X' W& `" c4 T' C0 [( ?" @db_user=nagiosndo
7 ~& j. L) x3 J, U `' B% Rdb_pass=password123
. r; r: f+ a. D# J, Gvi /usr/local/nagios/etc/nagios.cfg. \+ m$ n1 h3 Y2 a2 ~2 w
# 修改下面参数的值为-1(一般默认如此)。
5 B6 U. c( D. I, s3 Tevent_broker_options=-17 T* a) f' Z) Z, i
# 复制下面内容粘贴到#broker_module=…下面。/ k7 o; d- T b$ z* t
# 注意broker_module= 和config_file是在一行上
) b- T# W: m; ^# P# Uncomment the line below if you’re running Nagios 3.x
" r* ?9 J! J) @& f% K. a) {* obroker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
4 h$ D; v& q$ t/ `; D1 `. {# b9.启动ndo2db
; t& ^8 R# F! m/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg9 N* g& ], n* m6 |1 l- f2 f6 O
$ @; s( k) K3 T' X" [3 j3 }) P
echo ‘rm -f /usr/local/nagios/var/ndo.sock’ >> /etc/rc.local2 t; w7 v3 D8 Y0 H+ _
echo ‘/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg’ >> /etc/rc.local9 \+ o ^0 ]* Q3 o( X
#开机启动
: ~! H- G" r$ X8 H/ SSupport for the specified database server is either not yet supported, or was not found on your system.
4 q c) f, z+ b5 a/usr/local/nagios/bin/ndo2db-3x: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory8 M0 \% O, A7 p2 r( t
出现以上错误请执行第2步
2 x- r& W/ h+ K8 F! p10.重启动nagios% _/ U9 i; U3 A4 k+ }' R% J! U
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg) j8 H, f* d& j n+ N; ^
service nagios restart* o3 b- N6 ^4 C
一般情况下到此已完成安装,可以去数据库里看下记录有无增加
* k. x V: J5 c6 ]11.检查安装是否正确
5 _8 n+ R+ N; Y* g0 T9 ?6 ntail -20 /usr/local/nagios/var/nagios.log
! e# Z% }' J+ v0 y0 B$ z( D% C8 a[1242971625] ndomod: Successfully flushed 80 queued items to data sink.[1242971625] ndomod: Error writing to data sink! Some output may get lost…
/ x5 t' K9 C; _3 w/ F5 i貌似有点问题
6 @( B, ]$ F, _- U- c6 N8 Q8 S先改成输出成文件#vi ndomod.cfg
9 m3 |' R1 i4 E% v0 T; Linstance_name=default' F- p$ q8 S7 D( K% t; c% u, r
#output_type=tcpsocket# Q" i3 h. `0 u8 D0 g
#output=127.0.0.1/ Z* T# l7 `. ]9 Z9 a% q
$ B8 P* @! R+ x3 Q. n7 `
output_type=file! n2 x- k7 U& Y% W
output=/usr/local/nagios/var/ndo.dat7 z b7 j, K: ?# V
service nagios restart
/ R3 I( m W# y2 m! D看看有没有/usr/local/nagios/var/ndo.dat文件,ok,发现文件,说明第一步可以生成文件查看文件内容
" {' i+ R& c8 W9 kcd /usr/local/nagios/var/
9 ~8 i; A: {, q3 F! ^head -30 ndo.dat
/ r8 c0 A6 X0 \. ]5 V0 ]. Z: C% r( n
7 `" }& k+ G F QHELLO3 m4 v8 n1 D4 _, E; f% O, T
PROTOCOL: 2
- _/ s# w* a$ Y9 VAGENT: NDOMOD
, `' d$ k0 [4 t( q8 yAGENTVERSION: 1.4b7
* e0 s7 Y5 o, s9 }: Q M# gSTARTTIME: 1243393299! H9 O9 L0 _7 r2 Q
DISPOSITION: REALTIME
5 z2 j H6 \0 m3 o2 p; ?9 ?4 JCONNECTION: FILE
* C7 [" i. `7 I+ D3 j6 DCONNECTTYPE: INITIAL
# f" N' J+ K1 YINSTANCENAME: default' i& S# t; ~: |. d
STARTDATADUMP* Q R4 n: g8 y a* ?) X: m
! E0 {, D% D( p; q4 _, l v; P
+ O" T% ^. b/ ^1 _
202:
9 R9 \- a; d2 m3 r" z3 K4 l# \% o/ Q1=300
2 R; A; A* a* |3 y+ I2=0: P' k" a2 M9 v9 y# f
3=0
2 N9 X8 A% M2 J h, y( O4=1243393292.450675( e" }8 H$ A8 _
73=1243393292
( H+ U4 \5 M- J5 h5 r. O0 H74=262144
3 m+ l' s& ?# d, ?$ J7 \ {72=ndomod: Error writing to data sink! Some output may get lost…8 O- M8 N8 C% j
999
9 @: C3 |4 M3 K! i) ?' G: C % a' Q, c b9 m' t; \5 E
1 b' d) J1 e- T3 N% f( G1 t
* T8 Y5 n& h d4 z/ T& }. B, O. v9 A201:1 a( Y; T; G" W3 y3 y
1=205) y" \2 }7 I3 _' g2 `; K
2=0
6 {, \( n0 H- Q: w( ?( i8 |使用file2sock尝试socket方式
: X$ s$ A2 i$ b8 Z9 p; x../bin/file2sock -s /usr/local/nagios/var/ndo.dat -d /usr/local/nagios/var/ndo.sock -t unix -p 5668
. n( N1 W2 [3 |0 }1 ~Error while writing to destination socket: Connection reset by peer
c* Y" y6 r3 N0 q, R% m尝试tcp方式1 T& v' v d2 k
vi ndo2db.cfg) p4 E2 X& v1 e7 h6 \
#socket_type=unix
/ W' v4 t1 |6 [7 a, E, qsocket_type=tcp- r7 X) Q2 g% `5 B$ z# p2 `- h f( h
重新载入ndo2db, ^4 w' X. O! r
ps aux|grep ndo2db
' c+ r# i6 J1 p8 ?% r! X( kkill $pid
: f" y$ I4 ?* C2 G- R8 @/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg; R1 K0 o/ p7 T# `( X
3 d& t$ e# K+ {4 h% W6 A" U3 N
../bin/file2sock -s ndo.dat -d localhost -t tcp -p 5668! j; \/ F; x7 ?7 r! F
Error while writing to destination socket: Connection reset by peer8 R/ X" K" {7 x0 C! z; e: G
依然不行,重新编译ndoutils并加上 LDFLAGS=-L/opt/mysql/lib1 s1 Y4 s/ B( E M4 X, f
./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) _8 Z. @% i# _; ^6 g
make u) V; R1 F% ?3 e! ^& @6 [
#再执行一下安装过程后,通过
0 Q9 g j: G8 X* Z=================200912-07 更新
! {" k: k% D+ otail /var/log/messages
8 K7 j, I2 O hDec 7 14:09:13 localhost nagios: ndomod: Still unable to connect to data sink. 10547 items lost, 5000 queued items to flush.$ v* c$ N( W, L* X2 D: h7 b
Dec 7 14:09:29 localhost nagios: ndomod: Still unable to connect to data sink. 10746 items lost, 5000 queued items to flush.
/ ?4 m; ?* F3 f2 i, J" x1 J" w连接不到mysql,重启一下
* W& Z1 J. {" ?% Z' k% L/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
# H4 K/ y) f8 m/ C0 s( DCould not bind socket: Address already in use
. z3 _+ D. a! {* B" l0 p3 Qps aux|grep ndo2db没有) ?# Q: O1 W# J
查看套接字文件是否存在,删除之; h% m$ ?4 U$ f- f2 k
ll /usr/local/nagios/var/ndo.sock
* D' r2 A5 U- X J2 E3 ^rm /usr/local/nagios/var/ndo.sock0 H, L2 J" Y: p
重启/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg+ L' z7 Q- x; Q n; J: q
tail /var/log/messages, c1 Q( I6 R4 C6 z$ s( M
Dec 7 14:09:45 localhost nagios: ndomod: Successfully connected to data sink. 10861 items lost, 5000 queued items to flush.
8 c, c3 v$ z w- L- kDec 7 14:09:45 localhost nagios: ndomod: Successfully flushed 5000 queued items to data sink.
: f; F; b( Z3 g) ~9 dDec 7 14:09:45 localhost ndo2db-3x: Successfully connected to MySQL database |
|