RHEL5.4下cacti及相关插件的编译安装推荐

一、概述

1. Cacti 是用php 语言实现的一个软件,它的主要功能是用snmp 服务获取数据,

然后用rrdtool 储存和更新数据,当用户需要查看数据的时候用rrdtool 生成图表

呈现给用户。因此,snmp 和rrdtool 是cacti 的关键。snmp 关系着数据的收集,

rrdtool 关系着数据存储和图表的生成。

2. Mysql 配合PHP 程序存储一些变量数据并对变量数据进行调用,如:主机名、主

机ip、snmp 团体名、端口号、模板信息等变量。

3. snmp 抓到数据不是存储在mysql 中,而是存在rrdtool 生成的rrd 文件中(在

cacti 根目录的rra 文件夹下)。rrdtool 对数据的更新和存储就是对rrd 文件的处

理,rrd 文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数

在创建时就已经定义。

二、Cacti的架构及工作流程

1. Cacti 的架构

2. Cacti 的工作流程

安装需求:(cacti相关包下载地址:http://www.cacti.net/downloads/)

RRDTool 1.2.x 或者更高

MySQL 4.1.x or 5.x 或者更高

PHP 4.3.6 或者更高(推荐5.3以下,否则会报很多错误) php-mysql php-snmp

Web服务 例如:Apache 或者 IIS

net-snmp

php编译配置时需要添加下列模块:(可用php m查看这些模块是否安装)

mysql

snmp

xml

session

sockets

gd (安装一些插件时需要)

LDAP (当用LDAP认证时需要,非必须)

安装过程步骤:

1.安装必需组件

yum install y fontconfig* autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel libart_lgpl* pango* libtool* ncurses ncurses-devel curl curl-devel openssl openssl-devel perl* net-snmp*

2. 安装mysql

查看系统中是否已经安装了MySQL,如果是卸载所有以mysql 开头的包。

yum remove y mysql*

tar -zxvf mysql-5.1.44.tar.gz -C /usr/local/src

useradd mysql

cd /usr/local/src/mysql-5.1.44

./configure –prefix=/usr/local/cacti/mysql –enable-local-infile –with-charset=gbk

–with-low-memory –with-mysqld-user=mysql –enable-thread-safe-client

make make install

cp /usr/local/src/mysql-5.1.44/support-files/my-medium.cnf /etc/my.cnf

chown -R mysql:mysql /usr/local/cacti/mysql/

/usr/local/cacti/mysql/bin/mysql_install_db –user=mysql

/usr/local/cacti/mysql/bin/mysqld_safe –user=mysql

echo /usr/local/cacti/mysql/lib/mysql /etc/ld.so.conf

cp /usr/local/src/mysql-5.1.44/support-files/mysql.server /etc/init.d/mysqld

ln -s /usr/local/cacti/mysql/bin/mysql /usr/local/bin/mysql

ldconfig -v | grep mysql

chmod 755 /etc/init.d/mysqld

chkconfig –add mysqld

chkconfig mysqld on

3.安装Apache

tar -zxvf httpd-2.2.15.tar.gz -C /usr/local/src

cd /usr/local/src/httpd-2.2.15

./configure –prefix=/usr/local/cacti/apache –enable-so –enable-rewrite –enable-ssl –with-ssl=/usr/bin/openssl –with-zlib –enable-mods-shared=all –enable-track-vars –with-mysql=/usr/local/cacti/mysql

make make install

/usr/local/cacti/apache/bin/apachectl start

ln -s /usr/local/cacti/apache/bin/apachectl /etc/init.d/httpd

vi /etc/init.d/httpd //添加如下两行

#description:http server

#chkconfig: 2345 83 17

chkconfig –add httpd

chkconfig httpd on

添加php支持

vi /usr/local/cacti/apache/conf/httpd.conf

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

IfModule dir_module

DirectoryIndex index.php index.html

/IfModule

4.安装php

tar -zxvf php-5.2.8tar.gz -C /usr/local/src

cd /usr/local/src/php-5.2.8

./configure –prefix=/usr/local/cacti/php –with-config-file-path=/usr/local/cacti/php

–with-apxs2=/usr/local/cacti/apache/bin/apxs –with-zlib –with-bz2 –with-freetype-dir –enable-mbstring –with-mysql=/usr/local/cacti/mysql –with-mysqli=/usr/local/cacti/mysql/bin/mysql_config –with-gd –with-libxml-dir –with-png-dir –with-jpeg-dir –enable-sockets –with-snmp

make make install

cp php.ini-dist /usr/local/cacti/php/php.ini

ln -s /usr/local/cacti/php/bin/php /usr/bin

vim /usr/local/cacti/apache/htdocs/index.php

?

phpinfo();

?

5.安装rrdtool

yum install y intltool //先更新intltool

tar -zxvf rrdtool-1.3.9.tar.gz

cd rrdtool-1.3.9

./configure –prefix=/usr/local/cacti/rrdtool

make make install

6.安装spine

tar -zxvf cacti-spine-0.8.7e.tar.gz

cd cacti-spine-0.8.7e

./configure –prefix=/usr/local/cacti/spine –with-mysql=/usr/local/cacti/mysql

make make install

cat /usr/local/cacti/spine/etc/spine.conf

DB_Host localhost

DB_Database cacti

DB_User cactiuser

DB_Pass cactiuser

DB_Port 3306

7.安装cacti并创建cacti数据库

tar -zxvf cacti-0.8.7e.tar.gz

mv cacti-0.8.7e /usr/local/cacti/apache/htdocs/cacti

chown R root:root /usr/local/cacti/apache/htdocs/cacti

cat /usr/local/cacti/apache/htdocs/cacti/include/config.php

$database_type = mysql

$database_default = cacti

$database_hostname = localhost

$database_username = cactiuser

$database_password = cactiuser

$database_port = 3306

cat /usr/local/cacti/apache/htdocs/cacti/include/global.php

$database_type = mysql

$database_default = cacti

$database_hostname = localhost

$database_username = cactiuser

$database_password = cactiuser

$database_port = 3306

useradd cactiuser

/usr/local/bin/mysql

mysql create database cacti;

mysql grant all privileges on cacti.* to cactiuser@localhost identified by cactiuser

mysql flush privileges;

mysql cacti /usr/local/cacti/apache/htdocs/cacti/cacti.sql //导入数据库

8.定时执行

crontab -e

*/5 * * * * php /usr/local/cacti/apache/htdocs/cacti/poller.php /dev/null 2 1

9.在浏览器中输入http://serverIP/cacti 安装配置cacti

设置完后用http://serverIP/cacti/登录,默认用户名和密码都是admin,第一次登录要求强制修改密码

安装后的Settings设置,需要注意net-snmp,roodtool的版本号.spine路径,poller type,如下:

以下是一些插件的安装,用于扩展功能

10.安装Plugin Architecture

unzip cacti-plugin-0.8.7e-PA-v2.5.zip

/usr/local/bin/mysql cacti pa.sql

cp cacti-plugin-0.8.7e-PA-v2.5.diff /usr/local/cacti/apache/htdocs/cacti/

cd /usr/local/cacti/apache/htdocs/cacti/

patch -p1 -N cacti-plugin-0.8.7e-PA-v2.5.diff

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

$config[‘url_path’]=’/’;改成

$config[‘url_path’]=’/cacti/’;

User Management– admin– 选中Plugin Management 保存

刷新页面,左侧configuratin的Settings下面会显示Plugin Managemnet

11.settings插件的安装

tar -zxvf settings-0.5.tgz

mv settings-0.5 /usr/local/cacti/apache/htdocs/cacti/plugins/settings

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

$plugins=array();找到这一项,添加

$plugins[] = ‘settings’;

$plugins[] = ‘weathermap’;

$plugins[] = ‘monitor’;

$plugins[] = ‘thold’;

$plugins[] = ‘ntop’;

$plugins[] = ‘syslog’;

$plugins[] = ‘discovery’;

点击左侧— Plugin Management– 在新打开的窗口中会显示刚安装的settings插件,如图:

必须Install再Enable才能使用

13.weathermap插件的安装

unzip php-weathermap-0.97.zip

mv weathermap/ /usr/local/cacti/apache/htdocs/cacti/plugins/weathermap

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

$plugins=array();找到这一项,添加

$plugins[]=’weathermap’;

cd /usr/local/cacti/apache/htdocs/cacti/plugins/weathermap

chown cactiuser output

cp editor-config.php-dist editor-config.php

ps -aux | grep httpd

chown daemon configs/

chmod u+w configs/

vi editor-config.php

$cacti_base = /usr/local/cacti/apache/htdocs/cacti

$cacti_url = http://192.168.0.161/cacti/

$mapdir= $cacti_base.’/plugins/weathermap/configs’;

$ignore_cacti = FALSE;

将editor.php中的ENABLED=false改为true,否则weathermap点击Editor时会报错

vim /usr/local/cacti/apache/htdocs/cacti/plugins/weathermap/editor.php

//$ENABLED=false; 将false改为true

$ENABLED=true;

14.monitor的安装

tar -zxvf monitor-latest.tgz

mv monitor-0.9/ /usr/local/cacti/apache/htdocs/cacti/plugins/monitor

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

$plugins=array();找到这一项,添加

$plugins[]=’monitor’;添加

15.thold的安装

tar -zxvf thold-latest.tgz

mv thold-0.41/ /usr/local/cacti/apache/htdocs/cacti/plugins/thold

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

$plugins=array();找到这一项,添加

$plugins[]=’thold’;添加

在Plugin Managment中,将刚安装的monitor,thold Install– Enable 就可以看到monitor thold的标签了

16. notp的安装

安装ntop之前要安装libpcap和rrdttool

tar -zxvf libpcap-1.1.1.tar.gz

cd libpcap-1.1.1

./configure

make make install

tar -zxvf ntop-3.3.tar.gz

cd ntop-3.3

./autogen.sh –with-rrd-home=/usr/local/cacti/rrdtool –disable-snmp

./configure –prefix=/usr/local/ntop –with-rrd-home=/usr/local/cacti/rrdtool –disable-snmp

make make install

cp packages/RedHat/ntop.conf.sample /etc/ntop.conf

配置ntop

groupadd ntop

useradd ntop -g ntop

mkdir /var/log/ntop

chown -R ntop.ntop /usr/local/share/ntop

chown -R ntop.ntop /var/log/ntop

mkdir /usr/local/var/ntop/rrd

chmod -R 777 /usr/local/var/ntop/rrd/

ln -s /usr/lib64/libpcap.so.0.9.4 /lib64/libpcap.so.1

ldconfig

/usr/local/ntop/bin/ntop -A

###########################################################################################

/usr/local/ntop/bin/ntop: error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory

ldd /usr/local/ntop/bin/ntop

libpcap.so.1 = not found

libpcap.so.1 = not found

find / -name libpcap.so*

# find / -name libpcap.so*

/usr/local/lib/libpcap.so.1.1.1

/usr/local/lib/libpcap.so.1

/usr/local/lib/libpcap.so

/usr/local/libpcap/lib/libpcap.so.1.1.1

/usr/local/libpcap/lib/libpcap.so.1

/usr/local/libpcap/lib/libpcap.so

/usr/lib64/libpcap.so.0.9.4

/usr/lib64/libpcap.so.0

/usr/lib64/libpcap.so.0.9

ln -s /usr/lib64/libpcap.so.0.9.4 /lib64/libpcap.so.1

ldconfig

###########################################################################################

/usr/local/ntop/bin/ntop -P /var/log/ntop -u nobody //启动服务(测试不成功)

/usr/local/ntop/bin/ntop -p /var/log/ntop //这样是成功的

设置开机自动启动:

echo /usr/local/ntop/bin/ntop -p /var/log/ntop 2 1 1 /dev/null /etc/rc.local

配置完成.

IP输入: http://192.168.0.200:3000 就OK 了.

tar -zxvf ntop-0.1.tar.gz

mv ntop /usr/local/cacti/apache/htdocs/cacti/plugins/ntop

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

$plugins=array();找到这一项,添加

$plugins[]=’ntop’;添加

User Management– admin– View NTop

17.syslog安装,可以做为日志服务器

tar -zxvf syslog-0.5.2.tar.gz

mv syslog /usr/local/cacti/ap

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

$plugins=array();找到这一项,添加

$plugins[]=’syslog’;添加

vim /usr/local/cacti/apache/htdocs/cacti/plugins/syslog/config.php

$syslogdb_type = ‘mysql’;

$syslogdb_default = ‘syslog’;

$syslogdb_hostname = ‘localhost

$syslogdb_username = ‘cactiuser’;

$syslogdb_password = ‘cactiuser’;

//建立syslog数据库及用syslog.sql建表等

/usr/local/bin/mysql

mysql create database syslog;

mysql quit;

/usr/local/bin/

mysql grant all privileges on syslog.* to cactiuser@localhost identified by cactiuser

mysql flush privileges;

mysql exit;

service syslog stop

安装rpm -ivh syslog

vi /etc/syslog-ng/syslog-ng.conf

# 在文件末尾添加如下内容

source net {

udp();

};

destionation d_mysql{

pipe( /tmp/mysql.pipe )

template( INSERT INTO

‘$FACILITY’, ‘$PRIORITY’, ‘$YEAR-$MONTH-$DAY’, ‘$HOUR:$MIN:$SEC’, ‘$MSG’ );\n ) template-escape(yes)

);

};

log { source(net); destination(d_mysql); }

log { source(s_sys); destination(d_mysql); }

shell配置

vim /sbin/syslogtomysql

#!/bin/bash

if [ ! -e /tmp/mysql.pipe];then

mkfifo /tmp/mysql.pipe

fi

while[-e /tmp/mysql.pipe]

do

mysql u cactiuser password=cactiuser syslog /tmp/mysql.pipe

done

chmod 755 /sbin/syslogtomysql

echo /sbin/syslogtomysql /etc/rc.local

/sbin/syslogtomysql

service syslog-ng restart

service mysqld restart

chkconfig syslog off

chkconfig –del syslog

chkconfig syslon-ng on

chkconfig –add syslog-n

点击syslog标签会有php的警告信息,经查找,是syslog.php中timespan_settings.php的路径不对,怀疑是版本问题导致

vim /usr/local/cacti/apache/htdocs/cacti/plugins/syslog/syslog.php

include($syslog_config[ graphtime ] ? ./lib/timespan_settings.php

plugins/syslog/html/syslog_timespan_settings.php //改为上面的路/*include($syslog_config[ graphtime ] ? ./include/html/inc_timespan_settings.

plugins/syslog/html/syslog_timespan_settings.php */

18.discovery的安装

tar -zxvf discovery-0.8.5.tar.gz

mv discovery /usr/local/cacti/apache/htdocs/cacti/plugins/discovery

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

$plugins=array();找到这一项,添加

$plugins[]=’discovery’;添加

全部安装完后效果图:

离开之后,我想你不要忘记一件事:不要忘记想念我。

RHEL5.4下cacti及相关插件的编译安装推荐

相关文章:

你感兴趣的文章:

标签云: