当前位置: 首页 > 工具软件 > NagVis > 使用案例 >

cacti + nagios + ndoutility + nagvis安装及配置

段干宏硕
2023-12-01

系统CentOS 5 final
默认安装apache 、php
关闭iptables

iptables - F
chkconfig –level 23456 iptables off

修改/etc/selinux.conf

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
#SELINUXTYPE=targeted

重新启动系统 init 6

用系统光盘安装以下软件
安装net-snmp

rpm -ivh lm_sensors-*
rpm -ivh beecrypt-devel-4.1.2-10.1.1.i386.rpm
rpm -ivh elfutils-0.125-3.el5.i386.rpm elfutils-libs-0.125-3.el5.i386.rpm
rpm -ivh elfutils-devel-*
rpm -ivh net-snmp-*

安装MySQL

rpm -e --nodeps mysql-5.0.22-2.1.0.1.i386
rpm -ivh MySQL-server-community-5.0.51a-0.rhel5.i386.rpm
rpm -ivh MySQL-client-community-5.0.51a-0.rhel5.i386.rpm
rpm -ivh MySQL-shared-community-5.0.51a-0.rhel5.i386.rpm
rpm -ivh MySQL-shared-compat-5.0.51a-0.rhel5.i386.rpm
rpm -ivh MySQL-devel-community-5.0.51a-0.rhel5.i386.rpm

安装php支持

rpm -ivh php-gd-5.1.6-15.el5.i386.rpm
rpm -ivh php-mysql-5.1.6-15.el5.i386.rpm php-pdo-5.1.6-15.el5.i386.rpm
rpm -ivh php-snmp-5.1.6-15.el5.i386.rpm
rpm -ivh php-mbstring-5.1.6-15.el5.i386.rpm
安装gcc
rpm -ivh cpp-4.1.2-14.el5.i386.rpm
rpm -ivh libgomp-4.1.2-14.el5.i386.rpm
rpm -ivh gcc-4.1.2-14.el5.i386.rpm
rpm -ivh libstdc++-devel-4.1.2-14.el5.i386.rpm
rpm -ivh gcc-c++-4.1.2-14.el5.i386.rpm
安装gd-devel
rpm -ivh freetype-devel-2.2.1-19.el5.i386.rpm
rpm -ivh fontconfig-devel-2.4.1-6.el5.i386.rpm
rpm -ivh libX11-devel-1.0.3-8.0.1.el5.i386.rpm libXau-devel-1.0.1-3.1.i386.rpm libXdmcp-devel-1.0.1-2.1.i386.rpm xorg-x11-proto-devel-7.1-9.el5.centos.i386.rpm mesa-libGL-devel-6.5.1-7.5.el5.i386.rpm
rpm -ivh libXpm-devel-3.5.5-3.i386.rpm
rpm -ivh libjpeg-devel-6b-37.i386.rpm
rpm -ivh libpng-devel-1.2.10-7.0.2.i386.rpm
rpm -ivh gd-devel-2.0.33-9.3.fc6.i386.rpm
安装libtool
rpm -ivh imake-1.0.2-3.i386.rpm
rpm -ivh autoconf-2.59-12.noarch.rpm
rpm -ivh automake-1.9.6-2.1.noarch.rpm
rpm -ivh libtool-1.5.22-6.1.i386.rpm
rpm -ivh libtool-ltdl-1.5.22-6.1.i386.rpm
rpm -ivh libtool-ltdl-devel-1.5.22-6.1.i386.rpm

设置mysql密码

mysqladmin -uroot password '123456'

修改apache配置

vi /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php .phtml .php3 .php4
AddType application/x-httpd-php-source .phps

安装phpmyadmin

tar xzvf phpMyAdmin-2.11.6-english.tar.gz
mv phpMyAdmin-2.11.6-english /usr/local/phpMyAdmin
cd /usr/local/phpMyAdmin
cp config.sample.inc.php config.inc.php
vi config.inc.php
$cfg['blowfish_secret'] = 'somewords';
$cfg['Servers'][$i]['controluser'] = 'root';
$cfg['Servers'][$i]['controlpass'] = '123456';
wq
vi /etc/httpd/conf/httpd.conf
Alias /phpmyadmin /usr/local/phpMyAdmin

在DirectoryIndex 后面加上index.php

http://x.x.x.x/phpmyadmin/index.php
http://x.x.x.x/phpmyadmin/browse_foreigners.php
service httpd start

安装Cacti

BUILD_DIR=/tmp/rrdbuild
INSTALL_DIR=/usr/local/rrdtool
export $BUILD_DIR
export $INSTALL_DIR
mkdir -p $BUILD_DIR
mkdir $BUILD_DIR/lb
cd /home/test
tar xzvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
env CFLAGS="-O3 -fPIC" ./configure --prefix=$BUILD_DIR/lb
make
make install
cd ..
 
tar xzvf libpng-1.2.26.tar.gz
cd libpng-1.2.26
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" /
CFLAGS="-O3 -fPIC" ./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
cd ..
 
tar xzvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" ./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
cd ..
 
tar xzvf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
env CFLAGS="-O3 -fPIC" ./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
cd ..
 
tar xzvf cgilib-0.5.tar.gz
cd cgilib-0.5
make CC=gcc CFLAGS="-O3 -fPIC -I."
mkdir -p $BUILD_DIR/lb/include
cp *.h $BUILD_DIR/lb/include
mkdir -p $BUILD_DIR/lb/lib
cp libcgi* $BUILD_DIR/lb/lib
cd ..
 
ranlib $BUILD_DIR/lb/lib/*.a # 优化
IR=-I$BUILD_DIR/lb/include
CPPFLAGS="$IR $IR/libart-2.0 $IR/freetype2 $IR/libpng"
LDFLAGS="-L$BUILD_DIR/lb/lib"
CFLAGS=-O3
export CPPFLAGS LDFLAGS CFLAGS
tar xzvf rrdtool-1.2.23.tar.gz
cd rrdtool-1.2.23
./configure --prefix=$INSTALL_DIR --disable-python --disable-tcl
make
make install
cd ..
 
tar xzvf cacti-0.8.7b.tar.gz
mv cacti-0.8.7b /usr/local/cacti
cd /usr/local/cacti/
mysql -u root -p
create database cacti;
grant all on cacti.* to root;
grant all on cacti.* to root@localhost;
grant all on cacti.* to cactiuser;
grant all on cacti.* to cactiuser@localhost;
set password for cactiuser@localhost=password('123456');
/q
mysql --user=root --password=123456 cacti < cacti.sql
groupadd cacti
useradd -g cacti cactiuser
chown -R cactiuser rra/ log/
chmod -R 777 rra/ log/
vi include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "123456";
$database_port = "3306";
wq
vi /etc/crontab
*/5 * * * * cactiuser php /usr/local/cacti/poller.php > /dev/null 2>&1
wq
vi /etc/httpd/conf/httpd.conf
Alias /cacti /usr/local/cacti
wq
service httpd restart

http://x.x.x.x/cacti

选择new install
安装spine

tar xzvf cacti-spine-0.8.7a.tar.gz
cd cacti-spine-0.8.7a

编译需要libtool

rpm -ivh imake-1.0.2-3.i386.rpm
rpm -ivh autoconf-2.59-12.noarch.rpm
rpm -ivh automake-1.9.6-2.1.noarch.rpm
rpm -ivh libtool-1.5.22-6.1.i386.rpm
rpm -ivh libtool-ltdl-1.5.22-6.1.i386.rpm
rpm -ivh libtool-ltdl-devel-1.5.22-6.1.i386.rpm
./configure
make

把spine 和spine.conf copy到/usr/local/spine

mkdir /usr/local/spine
cp spine spine.conf /usr/local/spine

编辑 spine.conf 文件,输入数据库名、数据库用户名和密码等信息.
指定spine的物理路径
Console -> Configuration -> Settings -> Paths -> Alternate Poller Path -> Spine Poller File Path
路径为/usr/local/spine/spine

Cacti Plugins
Cacti插件是对cacti的扩展。
要使用cacti插件必须先扩展cacti架构,来支持插件。
安装cacti插件架构扩展
下载地址:http://cactiusers.org/downloads/
1).解压下载的tar包,你会得到一个cacti-plugin-arch目录

# tar –zxvf cacti-plugin-arch.tar.gz
# cd cacti-plugin-arch
# ls

2).安装插件扩展

cp cacti-plugin-0.8.7b-PA-v2.1.diff /usr/local/cacti

//备份cacti目录,以备插件扩展安装失败后能恢复到原状态

cd /usr/local
cp –r cacti ./cacti.bak
cd ./cacti

//首先使用以下命令进行测试

# patch -p1 -N --dry-run < cacti-plugin-0.8.7b-PA-v2.1.diff

//以上命令成功后,使用以下命令进行安装

# patch -p1 -N < cacti-plugin-0.8.7b-PA-v2.1.diff

将pa.sql导入数据库,支持Plugin Management

mysql --user=root --password=123456 cacti < pa.sql

3).安装后配置,首先查看你的cacti配置文件,看cacti相关的数据库信息是否被覆盖,如果被覆盖请直接从备份中拷贝一份到配置文件目录。

# cp ../include/config.php ./include/config.php

4).修改global.php以正常访问cacti

vi /usr/local/cacti/include/global.php

将$config['url_path'] = “/”;修改为$config['url_path'] = “/cacti/”;
注:如果cacti安装在 /var/www/html下则不用修改global.php

安装插件 下载地址为:http://cactiusers.org/downloads/
安装Monitor

tar xzvf monitor-0.8.2.tar.gz
mv monitor /usr/local/cacti/plugins/

安装插件,只需要将插件目录拷贝到cacti/plugins/目录下即可。如果是升级安装,只需要完全覆盖原插件目录即可。

vi /usr/local/cacti/include/global.php

在配置中查找$plugins = array();行,在此行下面加入:

$plugins[] = 'monitor';

注意:上面monitor的名字必须与cacti/plugins/目录下插件目录的名字相同。
在console选项卡下,点击左侧菜单中的Settings链接,在右侧出现的web页中点击Misc选项卡来配置Monitor插件。
在console - User Management – admin – 在View Monitoring前打勾

安装thold

tar xzvf thold-0.3.9.tar.gz
mv thold /usr/local/cacti/plugins/
tar xzvf settings-0.5.tar.gz
mv settings /usr/local/cacti/plugins/
vi /usr/local/cacti/include/global.php
$plugins[] = ' thold ';
$plugins[] = ' settings ';

在console – settings里修改thold相关属性
注:thold要和settings一起安装才能使用
用thold插件监控硬盘实现报警功能
适用版本cacti 0.8.7b
在cacti目录下,vi global_arrays.php
搜索custom_data_source_types,修改这一段如下:

$custom_data_source_types = array(
"CURRENT_DATA_SOURCE" => "Current Graph Item Data Source",
"ALL_DATA_SOURCES_NODUPS" => "All Data Sources (Don't Include Duplicates)",
"ALL_DATA_SOURCES_DUPS" => "All Data Sources (Include Duplicates)",
"SIMILAR_DATA_SOURCES_NODUPS" => "All Similar Data Sources (Don't Include Duplicates)",
"SIMILAR_DATA_SOURCES_DUPS" => "All Similar Data Sources (Include Duplicates)",
"CURRENT_DS_MINIMUM_VALUE" => "Current Data Source Item: Minimum Value",
"CURRENT_DS_MAXIMUM_VALUE" => "Current Data Source Item: Maximum Value",
"CURRENT_GRAPH_MINIMUM_VALUE" => "Graph: Lower Limit",
"CURRENT_GRAPH_MAXIMUM_VALUE" => "Graph: Upper Limit",
"VALUE_OF_HDD_TOTAL" => "Value of hdd_total data source");

在cacti界面的Graph Management-cdefs新建cdef模块,名字自己起,添加字段如下:

Item #1 Special Data Source: CURRENT_DATA_SOURCE
Item #2 Custom String: 100
Item #3 Operator: *
Item #4 Special Data Source: VALUE_OF_HDD_TOTAL
Item #5 Operator: /

这样就可以在Threshold Templates里面添加监控硬盘的模块了,我添加的是Host MIB - Hard Drive Space ,最后在Threshold CDEF里面选择刚自定义的cdef,这样就可以正常监控硬盘使用率了。

安装realtime

tar xzvf realtime-0.32.tar.gz
mv realtime /usr/local/cacti/plugins/
vi /usr/local/cacti/include/global.php
$plugins[] = ' realtime ';
mkdir /usr/local/cacti/rcache
chmod a+wx /usr/local/cacti/rcache

在console – settings – Misc 里修改Cache Directory的路径为/usr/local/cacti/rcache
如果安装0.34版则需要修改

1. poller_rt.php
#if (file_exists("./include/global.php")) {
# include("./include/global.php");
#} else {
# include("./include/config.php");
#}
 
include(dirname(__FILE__) . "/../../include/global.php");
 
#include_once($config["base_path"] . "/lib/poller.php");
#include_once($config["base_path"] . "/lib/data_query.php");
#include_once($config["base_path"] . "/lib/graph_export.php");
#include_once($config["base_path"] . "/lib/rrd.php");
 
include_once($config["library_path"] . "/poller.php");
include_once($config["library_path"] . "/data_query.php");
include_once($config["library_path"] . "/graph_export.php");
include_once($config["library_path"] . "/rrd.php");

2. cmd_rt.php

# include("./include/global.php");
#} else {
# include("./include/config.php");
#}
 
include(dirname(__FILE__) . "/../../include/global.php");
 
#include_once($config["base_path"] . "/lib/snmp.php");
#include_once($config["base_path"] . "/lib/poller.php");
#include_once($config["base_path"] . "/lib/rrd.php");
#include_once($config["base_path"] . "/lib/ping.php");
 
include_once($config["library_path"] . "/snmp.php");
include_once($config["library_path"] . "/poller.php");
include_once($config["library_path"] . "/rrd.php");
include_once($config["library_path"] . "/ping.php");

安装syslog
需要的软件syslog-ng 、eventlog 、libol
1. 安装syslog-ng

tar xzvf eventlog-0.2.7.tar.gz
cd eventlog-0.2.7
./configure --prefix=/usr/local/eventlog
make
make install
cd ..
tar xzvf libol-0.3.18.tar.gz
cd libol-0.3.18
./configure --prefix=/usr/local/eventlog/libol
make
make install
cd ..
tar xzvf syslog-ng-2.0.9.tar.gz
cd syslog-ng-2.0.9
export PKG_CONFIG_PATH=/usr/local/eventlog/lib/pkgconfig/
./configure --prefix=/usr/local/syslog-ng
make
make install
mkdir /usr/local/syslog-ng/etc/
cp doc/examples/syslog-ng.conf.sample /usr/local/syslog-ng/etc/syslog-ng.conf

修改syslog-ng.conf文件如下:

需要执行的bash文件如下:(脚本文件放在/usr/local/syslog-ng/sbin下)

安装cacti插件syslog

tar xzvf syslog-0.5.2.tar.gz
mv syslog-0.5.2 /usr/local/cacti/plugins/syslog
vi /usr/local/cacti/include/global.php
$plugins[] = ' syslog ';

将syslog的表导入数据库

mysql –u root –p
use cacti;
source /usr/local/cacti/plugins/syslog/syslog.sql

停止系统自带的syslog

 
pkill -9 syslog

启动syslog-ng

/usr/local/syslog-ng/sbin/syslog-ng

启动bash脚本

nohup /usr/local/syslog-ng/sbin/syslog2mysql.sh

安装advanced ping
0.8.7b本身带有ss_fping.php,需要加入一行

vi /usr/local/cacti/scripts/ss_fping.php
include_once(dirname(__FILE__) . "/../include/global_settings.php");

然后将xml模板导入到Graph Templates即可使用

NTOP

rpm -ivh libpcap-devel-0.9.4-11.el5.i386.rpm
tar xzvf ntop-3.3.6.tar.gz
cd ntop
./autogen.sh
./configure --prefix=/usr/local/ntop --with-rrd-home=/
make
make install
useradd ntop
passwd ntop
chown -R ntop.ntop /usr/local/ntop/share/ntop/
cp packages/RedHat/ntop.conf.sample /usr/local/ntop/etc/ntop/ntop.conf
/usr/local/ntop/bin/ntop -P /usr/local/ntop/share/ntop -u ntop –A
vi /usr/local/ntop/etc/ntop/ntop.conf

#程序运行用户
–user ntop
#设置ntop为服务
–daemon
#数据文件存放目录
–db-file-path /usr/local/ntop/share/ntop
#监控的网卡
–interface eth0
–trace-level 3
#web访问的端口
–http-server 3000
–disable-schedyield
启动ntop服务,指定读取的配置文件,只监控192.168.1.0/24网段
/usr/local/ntop/bin/ntop @/usr/local/ntop/etc/ntop/ntop.conf -m 192.168.1.0/24
设置开机自启动

vi /etc/rc.local
/usr/local/ntop/bin/ntop @/usr/local/ntop/etc/ntop/ntop.conf –m 192.168.1.0/24

Nagios

useradd nagios
passwd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
cd /home/test/
tar xzvf nagios-3.0b6.tar.gz
cd nagios-3.0b6
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios
service httpd restart
cd ..
tar xzvf nagios-plugins-1.4.12.tar.gz
cd nagios-plugins-1.4.12
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chkconfig --add nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, start Nagios.
service nagios start
vi /usr/local/nagios/etc/cgi.cfg

将默认的nagiosadmin修改为nagios
一开始会提示“HTTP WARNING: HTTP/1.1 403 Forbidden ”是因为nagios监控/var/www/html/下面的index.html文件,若没有就会提示错误,创建一个文件即可!
vi /var/www/html/index.html
hello !
wq
NdoUtility

rpm -ivh perl-DBD-MySQL-3.0007-1.fc6.i386.rpm
export PERL5LIB=/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/DBD
mysql -u root -p
create database nagios;
GRANT ALL ON nagios.* TO nagios@localhost IDENTIFIED BY "123456";
/q
cd /home/test
tar xzvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure --with-mysql-lib=/usr/lib
make
cd db
./installdb -u nagios -p 123456 -h localhost -d nagios
cd ..
cp src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
cp config/ndomod.cfg /usr/local/nagios/etc
cp src/ndo2db-3x /usr/local/nagios/bin/ndo2db
cp config/ndo2db.cfg /usr/local/nagios/etc
vi /usr/local/nagios/etc/ndo2db.cfg
db_user=nagios
db_pass=123456
wq

vi /usr/local/nagios/etc/nagios.cfg
修改如下:

broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
 
event_broker_options=-1
 
check_external_commands=1
 
command_check_interval=10s

启动ndo

/usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
service nagios restart

tail –f /var/log/messages | grep ndo 查看log

Nagvis

cd /home/test
tar xzvf nagvis-1.2.2.tar.gz
mv nagvis-1.2.2 /usr/local/nagios/share/nagvis
You should see the directorys etc, nagvis and wui on
ls -l /usr/local/nagios/share/nagvis
cd /usr/local/nagios/share/nagvis
cp etc/nagvis.ini.php-sample etc/nagvis.ini.php
vi etc/nagvis.ini.php

去掉注释
wq
check which unix user account is used to run your webserver (in my case it is apache).

grep -e '^User' /etc/httpd/conf/*
 
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/*

http:///nagvis/config.php

若安装nagvis-1.3需要安装以下rpm用作支持automap
graphviz的rpm包可以到官方网站去下载
http://www.graphviz.org/

rpm -ivh urw-fonts-2.3-6.1.1.noarch.rpm
rpm -ivh tk-8.4.13-3.fc6.i386.rpm
rpm -ivh graphviz-2.20.2-1.el5.i386.rpm
rpm -ivh graphviz-devel-2.20.2-1.el5.i386.rpm
rpm -ivh graphviz-doc-2.20.2-1.el5.i386.rpm
rpm -ivh graphviz-graphs-2.20.2-1.el5.i386.rpm
rpm -ivh graphviz-tcl-2.20.2-1.el5.i386.rpm
 类似资料: