使用mysql建立nagios数据库
# yum install mysql mysql-devel mysql-server gcc-c++
# service mysqld start
# chkconfig mysqld on
为root账号登陆数据库添加密码
# /usr/bin/mysqladmin -u root password xxxxxxxx
# mysql –p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database nagios;
Query OK, 1 row affected (0.03 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| nagios |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> GRANT ALL ON nagios.* TO nagios@localhost IDENTIFIED BY "nagios";
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
为方便管理数据库,安装phpMyAdmin
# cd /opt/nagios
安装php组件
# yum install php-mysql php-mbstring
从上下载符合系统组件的安装包
# tar zxf phpMyAdmin-2.11.10-all-languages.tar.gz
# mv phpMyAdmin-2.11.10-all-languages pma
# cp -a config.sample.inc.php config.inc.php
# vi config.inc.php
给blowfish_secret添加任意一串字符
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$cfg['blowfish_secret'] = 'nws'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
并修改mysql访问的账户和密码
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
$cfg['Servers'][$i]['controluser'] = 'root';
$cfg['Servers'][$i]['controlpass'] = 'xxxxxxxx';
保存退出
# cd ..
# cp -r pma/ /usr/local/nagios/share
打开IE输入正确登陆到phpmyadmin中,但页面提示"无法载入 mcrypt 扩展,
请检查 PHP 配置".网上查了下,mcrypt是加密用的,这个错误不影响phpmyadmin的使用.
使用NDOUtils将Nagios监控信息存入数据库
从nagios站点下载最新的ndoutils
# cd /opt/nagios
# tar zxf ndoutils-1.4b9.tar.gz
# cd ndoutils-1.4b9
# cd db
# ./installdb -u nagios -p nagios -h localhost -d nagios
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51.
** Creating tables for version 1.4b9
Using mysql.sql for installation...
** Updating table nagios_dbversion
Done!
# cd /opt/nagios/ndoutils-1.4b9
编译启动mysql
# ./configure --enable-mysql
执行完成后,注意向上看看打印出的信息,看看是否找到了MySQL的库文件和include文件.
MySQL library and include file(s) were found!
# make
# cd src/
安装的Nagios版本为3.2.0,所以拷贝的是ndomod-3x.o、ndo2db-3x,如果是2.x.x需拷贝ndomod-2x.o、ndo2db-2x
# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin
拷贝配置文件
# cd ../config
# cp ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
# cp ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
# cd /usr/local/nagios/etc/
# chmod 644 ndo*
# vi /usr/local/nagios/etc/ndo2db.cfg
db_user=ndouser
db_pass=ndopassword
修改为
db_user=nagios
db_pass=nagios
(因为之前在mysql中建立时使用命令mysql> GRANT ALL ON nagios.* TO nagios@localhost IDENTIFIED BY "nagios";)
# vi /usr/local/nagios/etc/nagios.cfg
复制broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg到
#broker_module=/somewhere/module2.o arg1 arg2=3 debug=0的下面
修改/usr/local/nagios/etc/nagios.cfg配置文件下面参数的值为-1(一般默认如此).
event_broker_options=-1
启动ndo2db
# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
重启Nagios
# service nagios restart
查看Nagios日志,看是否正常启动。
# tail -20 /usr/local/nagios/var/nagios.log
[1265163252] Nagios 3.2.0 starting... (PID=16042)
[1265163252] Local time is Wed Feb 03 10:14:12 CST 2010
[1265163252] LOG VERSION: 2.0
[1265163252] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1265163252] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1265163252] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
[1265163252] Finished daemonizing... (New PID=16044)
安装使用nagvis插件
安装php相关软件包php-mysql php-xml php-mbstring
# yum install php-mysql php-xml php-mbstring
# service httpd restart
从Nagios站点上下载Nagvis并导入到相关目录中
# cd /opt/nagios
# tar zxf nagvis-1.3.2.tar.gz
# cp -r nagvis-1.3.2 /usr/local/nagios/share/ nagvis
# cd /usr/local/nagios/share/
# cd nagivs/etc/
# cp -a nagvis.ini.php-sample nagvis.ini.php
# vi nagvis.ini.php
在[paths]模块修改URL path
; path options
[paths]
; absolute physical NagVis path
base="/usr/local/nagios/share/nagvis/" ###取消注释
; absolute html NagVis path
htmlbase="/nagios/nagvis" ###取消注释
; absolute html NagVis cgi path
htmlcgi="/nagios/cgi-bin" ###取消注释
在[backend_ndomy_1]模块修改连接数据库的一下信息(dbuser和dbpass改为nagios,原因同上)
; options for the NDO-Backend
; in this example the ID of the Backend is "ndomy_1" you can define another ID.
[backend_ndomy_1]
; type of backend - MUST be set
;backendtype="ndomy" ###取消注释
; hostname for NDO-db
;dbhost="localhost" ###取消注释
; portname for NDO-db
;dbport=3306 ###取消注释
; database-name for NDO-db
;dbname="nagios" ###取消注释
; username for NDO-db
;dbuser="root" ###取消注释,并修改用户为nagios
; password for NDO-db
;dbpass="" ###取消注释,并添加密码为nagios
; prefix for tables in NDO-db
;dbprefix="nagios_" ###取消注释
; instace-name for tables in NDO-db
;dbinstancename="default" ###取消注释
; maximum delay of the NDO Database in Seconds
;maxtimewithoutupdate=180 ###取消注释
; path to the cgi-bin of this backend
;htmlcgi="/nagios/cgi-bin" ###取消注释
修改nagvis文件权限
# chown apache:apache /usr/local/nagios/share/nagvis/ -R
# chmod 664 /usr/local/nagios/share/nagvis/etc/nagvis.ini.php
# chmod 775 /usr/local/nagios/share/nagvis/nagvis/images/maps
# chmod 664 /usr/local/nagios/share/nagvis/nagvis/images/maps/*
# chmod 775 /usr/local/nagios/share/nagvis/etc/maps
# chmod 664 /usr/local/nagios/share/nagvis/etc/maps/*
# chmod 775 /usr/local/nagios/share/nagvis/var
# chmod 664 /usr/local/nagios/share/nagvis/var/*(这条命令会提示报个错,因为暂时这个目录下还没有文件)
<安装到这步就可以使用nagvis了,实际中打开nagvis后无法使用Edit current map编辑图片的功能,一旦点击,nagvis提示缺少php-mbstring组件,需要安装之后再进行操作,但是该组件已经安装上去了,由于mbstring起到在php中进行编码转换的作用,于是将httpd,nagvis和nagios重启了一遍之后,上述错误不再发生.>
如果需要使用nagvis的Automap功能,需要安装graphviz组件.
下载文件放到/etc/yum.repos.d/目录下
# yum install graphviz graphviz-devel graphviz-doc graphviz-gd graphviz-graphs graphviz-guile graphviz-java graphviz-perl graphviz-python graphviz-ruby graphviz-tcl
安装完成重启Nagios和Ndoutils
重启ndo的方法
# rm /usr/local/nagios/var/ndo.sock
# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
The process will start normally.
使用即可登陆,使用方法很简单,点击页面上部的“Edit current map”即可进入配置界面,在页面上右键可以调出控制菜单,多尝试几次就会用了。使用nagvis还有点好处,可以将自己制作的图片作为背景图片,这样也方便查看。自己制作的图片像素控制为760*530左右,放到目录/usr/local/nagios/share/nagvis/nagvis/images/maps中,权限分配apache:apache 664即可,这样在新建监控图时就可以拿自己的图片做背景了。
阅读(2855) | 评论(0) | 转发(0) |