Chinaunix首页 | 论坛 | 博客
  • 博客访问: 312204
  • 博文数量: 103
  • 博客积分: 1590
  • 博客等级: 上尉
  • 技术积分: 1075
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-02 10:17
文章分类

全部博文(103)

文章存档

2013年(32)

2012年(7)

2010年(64)

我的朋友

分类: LINUX

2010-03-15 00:37:14

环境介绍
系统:红帽企业版5.4
Nagios正确安装运行,版本3.0.6 安装目录:/usr/local/nagios,这部分可以参考http://hi.baidu.com/naruto6006/blog/item/49d243d8688877e239012fa0.html

MySQL正确安装并运行,安装目录:/usr/local/mysql,这部分可以参考http://hi.baidu.com/naruto6006/blog/item/67aff4125a046728dd54011f.html

1:安装DBI包
[root@server2 ~]# cd /usr/local/src/tarbag/
[root@server2 tarbag]# wget
[root@server2 tarbag]# tar zxvf DBI-1.605.tar.gz -C ../software/
[root@server2 tarbag]# cd ../software/DBI-1.605/
[root@server2 DBI-1.605]# perl Makefile.PL
[root@server2 DBI-1.605]# make && make install

2:安装DBD-mysql
[root@server2 DBI-1.605]# cd -
/usr/local/src/tarbag
[root@server2 tarbag]# wget
[root@server2 tarbag]# tar -zxvf DBD-mysql-3.0008.tar.gz -C ../software/
[root@server2 tarbag]# cd ../software/DBD-mysql-3.0008/
[root@server2 DBD-mysql-3.0008]# unset LANG
[root@server2 DBD-mysql-3.0008]# perl Makefile.PL --libs="-L/usr/local/mysql/lib/mysql -lmysqlclient -L/usr/lib -lz " --cflags=-I/usr/local/mysql/include/mysql --mysql_config=/usr/local/mysql/bin/mysql_config -testhost=127.0.0.1 --testsocket=/tmp/mysql.sock --testdb=nagios --testuser=root --testpassword=password

………………………………………………………输出省略………………………………………………
I will use the following settings for compiling and testing:

cflags        (User's choice) = -I/usr/local/mysql/include/mysql
embedded      (mysql_config ) =
libs          (User's choice) = -L/usr/local/mysql/lib/mysql -lmysqlclient -L/usr/lib -lz
mysql_config (Users choice ) = /usr/local/mysql/bin/mysql_config
nocatchstderr (default      ) = 0
nofoundrows   (default      ) = 0
ssl           (guessed      ) = 0
testdb        (User's choice) = nagios
testhost      (User's choice) = 127.0.0.1
testpassword (default      ) = password
testsocket    (User's choice) = /tmp/mysql.sock
testuser      (User's choice) = root

To change these settings, see 'perl Makefile.PL --help' and
'perldoc INSTALL'.
Using DBI 1.605 (for perl 5.008008 on i386-linux-thread-multi) installed in /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/DBI/
Writing Makefile for DBD::mysql

[root@server2 DBD-mysql-3.0008]# make && make install

3:创建mysql头文件和库文件的链接到/usr相关目录下
[root@server2 DBD-mysql-3.0008]# cd
[root@server2 ~]# ln -s /usr/local/mysql/include/* /usr/include/
[root@server2 ~]# ln -s /usr/local/mysql/lib/* /usr/lib/

4:安装ndoutils
[root@server2 ~]# cd /usr/local/src/tarbag/
[root@server2 tarbag]# wget
--00:56:40--

[root@server2 tarbag]# tar -zxvf ndoutils-1.4b7.tar.gz -C ../software/
[root@server2 tarbag]# cd ../software/ndoutils-1.4b7/
[root@server2 ndoutils-1.4b7]# ./configure --prefix=/usr/local/nagios --enable-mysql
………………………………………………………输出省略………………………………………………
MySQL library and include file(s) were found!
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating subst
config.status: creating include/config.h

*** Configuration summary for ndoutils 1.4b7 10-31-2007 ***:

General Options:
-------------------------
NDO2DB user:    nagios
NDO2DB group:   nagios

Review the options above for accuracy. If they look okay,
type 'make' to compile the NDO utilities.

[root@server2 ndoutils-1.4b7]# make
[root@server2 ndoutils-1.4b7]# cd src/
[root@server2 src]# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin/
[root@server2 src]# cd ../db
[root@server2 db]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.36-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database nagios;
Query OK, 1 row affected (0.06 sec)

[root@server2 db]# ./installdb -u root -p password -d nagios
install_driver(mysql) failed: Can't load '/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.16: cannot open shared object file
出现上面的错误,是因为找不到libmysqlclient.so.16这个库文件,解决办法如下:
[root@server2 db]# ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib
[root@server2 db]# ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib64/ (针对服务器64位系统)

[root@server2 db]# ./installdb -u root -p 123456 -d nagios
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51.
** Creating tables for version 1.4b7
Using mysql.sql for installation...
** Updating table nagios_dbversion
Done!

DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51(这个错误可以忽略…)

若出现错误提示“failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at ./installdb line 41“,原因是找不到mysql.sock,编译安装的msyql一般sock的位置是在/tmp下,解决办法有两个,一是修改/etc/my.cnf文件中sock的位置,二是创建一个软链接到/var/lib/mysql下面

[root@server2 db]# cd ../config
[root@server2 config]# cp ndo* /usr/local/nagios/etc/

5:修改/usr/local/nagios/etc/ndo2db.cfg文件的数据库信息
[root@server2 ~]# grep -v '^#' /usr/local/nagios/etc/ndo2db.cfg |sort |uniq
db_host=localhost
db_name=nagios
db_pass=password
db_port=3306
db_prefix=nagios_
db_servertype=mysql
db_user=root
debug_file=@localstatedir@/ndo2db.debug
debug_level=0
debug_verbosity=1
max_debug_file_size=1000000
max_eventhandlers_age=44640
max_hostchecks_age=10080
max_servicechecks_age=10080
max_systemcommands_age=10080
max_timedevents_age=1440
ndo2db_group=nagios
ndo2db_user=nagios
socket_name=/usr/local/nagios/var/ndo.sock
socket_type=unix
tcp_port=5668

6:修改nagios.cfg
#复制下面内容粘贴到/usr/local/nagios/etc/nagios.cfg配置文件的#broker_module=...下面。
#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
#修改/usr/local/nagios/etc/nagios.cfg配置文件下面参数的值为-1(一般默认如此)。

[root@server2 ~]# grep 'broker' /usr/local/nagios/etc/nagios.cfg |grep -v '^#'
event_broker_options=-1
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

# 启动ndo2db
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
若出现提示信息“Support for the specified database server is either not yet supported, or was not found on your system“ 应该是没找到mysql.h等头文件导致的,请确保所必须的库已安装,并在./configure时指定头文件目录!

7:重启nagios服务
[root@server2 ~]# service nagios restart
Running configuration check...done.
Stopping nagios: .done.
Starting nagios: done.

8:查看日志
[root@server2 ~]# tail -f /usr/local/nagios/var/nagios.log
[1264575689] Caught SIGTERM, shutting down...
[1264575689] Successfully shutdown... (PID=17653)
[1264575691] Nagios 3.2.0 starting... (PID=19072)
[1264575691] Local time is Wed Jan 27 02:01:31 EST 2010
[1264575691] LOG VERSION: 2.0
[1264575691] ndomod: NDOMOD 1.4b7 (10-31-2007) Copyright (c) 2005-2007 Ethan Galstad (nagios@nagios.org)
[1264575691] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1264575691] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
[1264575691] Finished daemonizing... (New PID=19075)

附上效果图:


参考网站:
http://blog.c1gstudio.com/archives/635
%20&do=blog&id=16089
http://blog.csdn.net/yang_dk/archive/2007/10/17/1828737.aspx


阅读(1591) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~