Cacti教程(一)概述及安装
Cacti教程(一)概述及安装
1.概述
cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。
Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量。
snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。关于RRDTool的知识请参阅RRDTool教学。
2.Cacti的架构及工作流程
2.1 Cacti的架构
2011-1-17 15:18 上传下载附件 (14.6 KB)
2.2 Cacti的工作流程
2011-1-17 15:18 上传下载附件 (18.34 KB)
3. 安装条件
ØApache
Øhp
ØMySQL
ØRRDTool
ØNet-SNMP
4.安装过程
系统环境:Ubuntu Server 9.04 64位
Apache与MySQL的安装此处省略
4.1 PHP安装
•在zlib的configure时,不要指定—prefix,如果指定了prefix在下面类安装时,会提示找不到zlib;
•libpng的安装时,要根据操作系统修改参数,如果操作系统为32位,则采用脚本中的参数,如果为64位,则需要在cp scripts/makefile.std makefile执行完成以后,修改makefile中CFLAGS的值,在后面加上-fPIC参数,否则会出现“usr/local/lib/libpng.a: could not read symbols: Bad value”的错误;
•在安装PHP之前,由于开启了Mysql模块,所以一定要安装Mysql,而且Cacti的数据也需要Mysql数据库进行存储;
•HP的configure时,一定要加上--enable-sockets 选项,否则无法运行,PHP安装完成以后,它的配置文件为/usr/local/php/etc/php.ini。
•安装完成以后,在/usr/local/apache/htdocs下建立test.php,测试运行
- <?php
- phpinfo();
- ?>
- 复制代码安装脚本如下:
- #!/bin/sh
- cd /usr/local/src/php
- #1.zlib install
- #http://www.zlib.net/ zlib-1.2.5.tar.gz
- url:http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download
- cd /usr/local/src/php
- tar zxvf zlib-1.2.5.tar.gz
- cd zlib-1.2.5
- #./configure --prefix=/usr/local/zlib zlib not installed
- ./configure
- make
- make install
- #/usr/local/lib
- #2.libxml install libxml2-2.7.2.tar.gz
- #download url:http://xmlsoft.org/sources/
- cd /usr/local/src/php
- tar zxvf libxml2-2.7.2.tar.gz
- cd libxml2-2.7.2
- ./configure --prefix=/usr/local/libxml
- make
- make install
- #3.jpeg6 install jpegsrc.v6b.tar.gz
- #download url:http://www.ijg.org/files/
- mkdir /usr/local/libjpeg
- mkdir /usr/local/libjpeg/bin
- mkdir /usr/local/libjpeg/lib
- mkdir /usr/local/libjpeg/include
- mkdir /usr/local/libjpeg/man
- mkdir /usr/local/libjpeg/man/man1
- cd /usr/local/src/php
- tar zxvf jpegsrc.v6b.tar.gz
- cd jpeg-6b
- cp /usr/local/src/php/libtool libtool
- ./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
- make
- make install
- #4.libpng install libpng-1.5.0beta34.tar.gz
- #download url:http://sourceforge.net/projects/libpng/files/
- cd /usr/local/src/php
- tar zxvf libpng-1.5.0beta34.tar.gz
- cd libpng-1.5.0beta34
- cp scripts/makefile.std makefile
- #如果服务器是64版本,需要修改makefile的 CFLAGS参数,加入 -fPIC
- make
- make install
- #/usr/local/lib /usr/local/bin
- #5.freetype install freetype-2.4.0.tar.gz
- #download url:http://sourceforge.net/projects/freetype/files/
- cd /usr/local/src/php
- tar zxvf freetype-2.4.0.tar.gz
- cd freetype-2.4.0
- ./configure --prefix=/usr/local/freetype
- make
- make install
- #6 GD2 install gd-2.0.35.tar.gz
- #download url:http://www.libgd.org/
- #/usr/local/lib/libpng.a: could not read symbols: Bad value
- #http://blog.c1gstudio.com/archives/152
- cd /usr/local/src/php
- tar zxvf gd-2.0.35.tar.gz
- cd gd-2.0.35
- ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/libjpeg --with-png=/usr/local/lib --with-zlib=/usr/local/lib --with-freetype=/usr/local/freetype
- make
- make install
- #7. php install
- cd /usr/local/src/php
- tar zxvf php-5.3.2.tar.gz
- #mv php*.tar.gz backup
- cd php-5.3.2
- #we should install mysql first
- #open the funcation:--enable-sockets DTžÄdatetimezone
- ./configure --prefix=/usr/local/php --with-libxml-dir=/usr/local/libxml --with-gd=/usr/local/gd --with-jpeg-dir=/usr/local/libjpeg --with-zlib-dir=/usr/local/lib --with-png-dir=/usr/local/lib --with-freetype-dir=/usr/local/freetype --enable-mbstring --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc
- #if error install :apt-get install flex
- make
- make install
- cp php.ini-development /usr/local/php/etc/php.ini
- sed -i '/<FilesMatch/s/^/<FilesMatch \\.php$>\
- SetHandler application\/x-httpd-php \
- <\/FilesMatch>\
- <FilesMatch "\.ph(p[2-6]?|tml)$">\
- SetHandler application\/x-httpd-php\
- <\/FilesMatch>\
- <FilesMatch "\.phps$">\
- SetHandler application\/x-httpd-php-source\
- <\/FilesMatch>\
- \ /' /usr/local/apache/conf/httpd.conf
- sed -i '/DirectoryIndex/s/$/ index.php/' /usr/local/apache/conf/httpd.conf
- service apache stop
- service apache start
复制代码复制代码4.2 RRDTool安装
执行脚本如下
- #!/bin/sh
- export BUILD_DIR=/usr/local/src/rrdtool
- export INSTALL_DIR=/usr/local/rrdtool
- #mkdir -p $BUILD_DIR
- cd $BUILD_DIR
- export PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig
- export PATH=$INSTALL_DIR/bin:$PATH
- export LDFLAGS="-Wl,--rpath -Wl,${INSTALL_DIR}/lib"
- #pkg-config
- cd $BUILD_DIR
- gunzip -c pkg-config-0.23.tar.gz | tar xf -
- cd pkg-config-0.23
- ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
- make
- make install
- #zlib
- cd $BUILD_DIR
- gunzip -c zlib-1.2.5.tar.gz | tar xf -
- cd zlib-1.2.5
- ./configure --prefix=$INSTALL_DIR --shared
- make
- make install
- cd $BUILD_DIR
- #wget http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.18.tar.gz
- gunzip -c libpng-1.2.18.tar.gz | tar xf -
- cd libpng-1.2.18
- env CFLAGS="-O3 -fPIC" ./configure --prefix=$INSTALL_DIR
- make
- make install
- #freetype
- cd $BUILD_DIR
- #wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.3.5.tar.gz
- gunzip -c freetype-2.3.5.tar.gz | tar xf -
- cd freetype-2.3.5
- ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
- make
- make install
- #libxml2
- cd $BUILD_DIR
- gunzip -c libxml2-2.6.32.tar.gz | tar xf -
- cd libxml2-2.6.32
- ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
- make
- make install
- #fontconfig
- cd $BUILD_DIR
- gunzip -c fontconfig-2.4.2.tar.gz | tar xf -
- cd fontconfig-2.4.2
- ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC" --with-freetype-config=$INSTALL_DIR/bin/freetype-config
- make
- make install
- #pixman
- cd $BUILD_DIR
- #wget http://oss.oetiker.ch/rrdtool/pub/libs/pixman-0.10.0.tar.gz
- gunzip -c pixman-0.10.0.tar.gz | tar xf -
- cd pixman-0.10.0
- ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
- make
- make install
- #cairo
- cd $BUILD_DIR
- #wget http://oss.oetiker.ch/rrdtool/pub/libs/cairo-1.6.4.tar.gz
- gunzip -c cairo-1.6.4.tar.gz | tar xf -
- cd cairo-1.6.4
- ./configure --prefix=$INSTALL_DIR \
- --enable-xlib=no \
- --enable-xlib-render=no \
- --enable-win32=no \
- CFLAGS="-O3 -fPIC"
- make
- make install
- #Glib
- cd $BUILD_DIR
- #wget http://oss.oetiker.ch/rrdtool/pub/libs/glib-2.15.4.tar.gz
- gunzip -c glib-2.15.4.tar.gz | tar xf -
- cd glib-2.15.4
- apt-get -y install gettext
- #must have gettext support in C library :apt-get install gettext
- ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
- make
- make install
- #pango
- cd $BUILD_DIR
- #wget http://oss.oetiker.ch/rrdtool/pub/libs/pango-1.21.1.tar.bz2
- bunzip2 -c pango-1.21.1.tar.bz2 | tar xf -
- cd pango-1.21.1
- ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC" --without-x
- make
- make install
- #rrdtool
- cd $BUILD_DIR
- gunzip -c rrdtool-1.3.9.tar.gz | tar xf -
- cd rrdtool-1.3.9
- ./configure --prefix=$INSTALL_DIR --disable-tcl --disable-python
- make
- make install
复制代码复制代码4.3 Net-Snmp和Cacti安装
在安装过程中,错误主要出现在net-snmp安装时,如果提示“grep: /usr/lib/libbeecrypt.la: No such file or director”,则缺少libbecrypt类,通过apt-get -y install libbeecrypt7解决;如果提示“usr/bin/ld: cannot find -lperl”,说明共享库中没有perl,通过“ln -s /usr/lib/libperl.so.5.10 /usr/lib/libperl.so”命令解决。
安装完成以后,输入http://ip/cacti 测试,如果不能正常测试,则使用http://ip/cacti/index.php 进行测试;在配置界面中输入相应rrdtool和net-snmp的安装位置进行登录界面,初始的登录用户名和密码都是admin,初次登录修改密码,修改为******
执行脚本如下:
- #!/bin/sh
- #net-snmp installation net-snmp-5.5.tar.gz http://www.net-snmp.org/
- cd /usr/local/src/cacti
- #error:/usr/lib/libbeecrypt.la' is not a valid libtool archive
- #short of libbeecrypt
- apt-get -y install libbeecrypt7
- tar zxvf net-snmp-5.5.tar.gz
- cd net-snmp-5.5
- #apt-get install libiconv-hook-dev
- ./configure --prefix=/usr/local/net-snmp --enable-mfd-rewrites --with-default-snmp-version="2" --with-sys-contact="admin" --with-sys-location="China" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp"
- ln -s /usr/lib/libperl.so.5.10 /usr/lib/libperl.so
- make
- make install
- ln -s /usr/local/net-snmp/bin/* /usr/local/bin/
- cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf
- #vim snmp.conf
- /usr/local/net-snmp/sbin/snmpd
- #vim /etc/rc.local /usr/local/net-snmp/sbin/snmpd
- #cd $BUILD_DIR
- cd /usr/local/src/cacti
- tar xvfz cacti-0.8.7g.tar.gz
- mv cacti-0.8.7g /usr/local/apache/htdocs/cacti
- sed -i 's/$database_default = "cacti"/$database_default = "cactidb"/g' /usr/local/apache/htdocs/cacti/include/config.php
- sed -i 's/$database_password = "cactiuser"/$database_password = "cactipwd"/g' /usr/local/apache/htdocs/cacti/include/config.php
- groupadd cacti
- useradd -g cacti cactiuser
- chown -R cactiuser /usr/local/apache/htdocs/cacti/rra/
- chown -R cactiuser /usr/local/apache/htdocs/cacti/log/
- #cacti-spine settings cacti-spine-0.8.7g.tar.gz spine默认安装在/usr/local/spine
- cd /usr/local/src/cacti
- apt-get -y install autoconf automake libtool
- tar zxvf cacti-spine-0.8.7g.tar.gz
- cd cacti-spine-0.8.7g
- ./configure --with-snmp=/usr/local/net-snmp --with-mysql=/usr/local/mysql
- make
- make install
- chgrp -R cacti /usr/local/apache/htdocs/cacti/
- #MySql Configuration
- /usr/local/mysql/bin/mysql -uroot -proot <<EOF
- create database cactidb;
- grant all on cactidb.* to cactiuser@localhost identified by "cactipwd";
- use cactidb;
- source /usr/local/apache/htdocs/cacti/cacti.sql
- EOF
- #vim /usr/local/php/etc/php.ini date.timezone = Asia/Shanghai
- sed -i '/Date/s/$/\
- date.timezone = Asia\/Shanghai/' /usr/local/php/etc/php.ini
- service apache stop
- service apache start
复制代码复制代码
Cacti安装完成
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论