山东汉子
分类: 系统运维
2010-07-12 19:25:23
Fedora 12 下 Cacti的架设
Prepared by Lear Zhang, 2010-07-12
声明:本文版权归作者所有,欢迎转载,转载请注明出处.保留所有权利.
欢迎浏览我的博客 http://zhangmtao.cublog.cn,文中所涉及的软件都在我的MSN空间有.联系Email & MSN:
安装环境与参数
系统使用Fedora12英文版本,所有下载的安装源文件保存在 /tmp/cacti 目录下, 系统安装路径为 /server/cacti ,如无说明,所有软件均为英文版本.
1. 安装Fedora 12
//!关闭 SELinux!!!,防火墙中打开http端口,否则外部无法访问!
2. 下载所有需要的组件
系统需要的软件清单如下.
所有软件解压缩后准备开始.
3. 安装
程序安装有一定的顺序,呵呵,咱们一步一步来.
3.1 安装mysql
#groupadd -g 200 mysql
#useradd -u 200 -g mysql -d /server/cacti/mysql -M mysql
#cd /tmp/cacti
#cd mysql-5.1.47
#./configure --prefix=/server/cacti/mysql --sysconfdir=/etc
#make
#make install
#cp support-files/my-medium.cnf /etc/my.cnf
//主配置文件.
# cd /server/cacti/mysql
#chown -R mysql .
#chgrp -R mysql .
//以上两行改变当前文件夹内所有文件的属主和属组.
#bin/mysql_install_db --user=mysql //使用账号来初始化数据库
#chown -R mysql:mysql /server/cacti/mysql/var/mysql
#bin/mysqld_safe --user=mysql &
#bin/mysqladmin -u root password ‘yournewpassword’ //设置新密码
#/server/cacti/mysql/bin/mysql –u root –p
//输入密码登陆mysql进行测试数据库
#vi /etc/rc.d/rc.local
//设置mysql 在Fedora启动时自动启动,在文件末尾填入如下行
cd /server/cacti/mysql
/server/cacti/mysql/bin/mysqld_safe --user=mysql &
#cd /tmp/cacti
3.2安装Apache
#cd httpd-2.2.15
#./configure --prefix=/server/cacti/apache --enable-so --enable-rewrite
#make
#make install
#cd /tmp/cacti
//让Apache 随着系统启动自动启动
#cp /server/cacti/apache/bin/apachectl /etc/rc.d/init.d/apache
#chmod +x /etc/rc.d/init.d/apache
#ln -s /etc/rc.d/init.d/apache /etc/rc3.d/S100apache
#ln -s /etc/rc.d/init.d/apache /etc/rc3.d/K100apache
#ln -s /etc/rc.d/init.d/apache /etc/rc5.d/S100apache
#ln -s /etc/rc.d/init.d/apache /etc/rc5.d/K100apache
3.3 安装PHP
3.3.1 首先安装zlib,freetype,libpng,jpeg 以便于让PHP 支持GD 库
1) 安装zlib
#cd zlib-1.2.5
#./configure --prefix=/server/cacti/zlib
#make
#make install
# cd /tmp/cacti
2) 安装freetype
#cd freetype-2.3.5
#./configure --prefix=/server/cacti/freetype
#make
#make install
#cd /tmp/cacti
3) 安装linpng
#cd libpng-1.4.3
#cd scripts/
#mv makefile.linux ../makefile
//注意,这里的makefile 不是用./configure生成,而是直接从scripts/里复制
#cd ..
#make
#make install
#cd /tmp/cacti
4) 安装jpeg
#cd jpeg-7
#mkdir /server/cacti/libjpeg
#mkdir /server/cacti /libjpeg/include
#mkdir /server/cacti /libjpeg/bin
#mkdir /server/cacti /libjpeg/lib
#mkdir /server/cacti /libjpeg/man
#mkdir /server/cacti /libjpeg/man/man1
//可以用mkdir -p /server/cacti/libjpeg/man/man1 创建多层目录
#./configure --prefix=/server/cacti/libjpeg --enable-shared --enable-static
#make
#make install
注意,这里configure带--enable-shared 参数是为了生成共享库
#cd /tmp/cacti
5) 检查libxml版本是否符合php5的要求
#rpm -qa |grep libxml
//版本符合要求,则不需要再安装,否则,需要卸载libxml包,安装更高版本的libxml.
//#rpm -e libxml*
//#cd libxml-2.7.7
//#./configure
//#make
//#make install
6) 安装fontconfig
#cd fontconfig-2.7.0
#./configure --prefix=/server/cacti/fontconfig --with-freetype-config=/server/cacti/freetype/bin/freetype-config
#make
#make install
#cd /tmp/cacti
7) 安装GD
#cd gd-2.0.35
#./configure --prefix=/server/cacti/libgd --with-png --with-freetype=/server/cacti/freetype --with-jpeg=/server/cacti/libjpeg
#make
#make install
#cd /tmp/cacti
8) 编辑 /etc/ld.so.conf
#vi /etc/ld.so.conf
添加如下几行到文件结尾
/server/cacti/zlib/lib
/server/cacti/freetype/lib
/server/cacti/libjpeg/lib
/server/cacti/libgd/lib
#ldconfig //装载相关动态扩展库
9) 安装PHP
#cd php-5.3.2
//configure 带如下参数^_^,太多了,晕.
#./configure 参数如下图所示.
#make
#make install
#ln -s /server/cacti/php/bin/* /usr/local/bin
#cd /tmp/cacti
3.4 配置 httpd.conf
#vi /server/cacti/apache/conf/httpd.conf
//添加ServerName hostname.example.com 或者本机的IP地址
“Servername hostname.example.com” //ServerName xxx.xxx.xxx.xxx
//查找AddType application/x-compress .Z 后面添加如下几行
“AddType application/x-gzip .gz .tgz”
“AddType application/x-httpd-php .php”
“AddType image/x-icon .ico”
//修改DirectoryIndex 行,添加index.php
“DirectoryIndex index.php index.html index.html.var”
3.5 配置测试页
#vi /server/cacti/apache/htdocs/index.php
添加如下行,做PHP测试页.
“ Phpinfo();
?>”
重新启动apache,打开浏览器,查看测试页.
显示如下页面.
3.6 安装RRDTool
RRDTool需要相应的库文件支持,需要安装如下库文件:
cgilib, libart_lgpl, intltool, pango, cario, rrdtool
1) 安装cgilib (0.5)
#cd cgilib-0.5
#vi cgi.c //修改cgi.c文件,删除 “#include(malloc.h);”行
#make
#make install
#mkdir -p /server/cacti/rrdtool/lb/include
#cp cgi.h /server/cacti/rrdtool/lb/include
#mkdir -p /server/cacti/rrdtool/lb/lib
#cp libcgi.a /server/cacti/rrdtool/lb/lib
#cd /tmp/cacti
2) 安装libart_lgpl
#cd libart_lgpl-2.3.17
#./configure --prefix=/server/cacti/rrdtool/lb
#make
#make install
#cd /tmp/cacti
3) 安装intltool
#cd intltool-0.40.6
#./configure
#make
#make install
#cd /tmp/cacti
4) 安装cario 和cairo-devel
#cd cario-1.8.10
#./configure --prefix=/server/cacti/cario
#make
#make install
#yum –y install cario-devel
5) 安装pango
#cd pango-1.28.1
#./configure --prefix=/server/cacti/pango
#make
#make install
#cd /tmp/cacti
6) 安装rrdtool
#cd rrdtool-1.2.23
//首先需要设置PKG_CONFIG_PATH,输入
#./configure --prefix=/server/cacti/rrdtool
#make
#make install
#cd /tmp/cacti
//完成后建立符号连接
#ln -s /server/cacti/rrdtool/bin/* /usr/local/bin/
#
//执行rrdtool 看是否安装正确
#cd /server/cacti/rrdtool/share/rrdtool/examples
#./stripes.pl //在当前目录下生成一个文件stripes.png,说明安装成功.
#cp stripes.png /server/cacti/apache/htdocs/
//在浏览器输入 ,看到如下图形,说明RRDTool安装成功:)
4. 安装net-snmp
#cd /tmp/cacti
#cd net-snmp-5.5
#./configure --prefix=/server/cacti/net-snmp --enable-developer
//有几个交互式的问答,要自己选择合适的配置.
#make
#make install
# ln -s /server/cactil/net-snmp/bin/* /usr/local/bin/
#cp EXAMPLE.conf /server/cacti/net-snmp/share/snmp/snmpd.conf
# /server/cacti/net-snmp/sbin/snmpd -c /server/cacti/net-snmp/share/snmp/snmpd.conf
#vi /etc/rc.local 在文件末尾添加
cd /server/cacti/net-snmp/sbin
snmpd -c /server/cacti/net-snmp/share/snmp/snmpd.conf
以上配置,是为了让snmpd随系统启动的时候自动运行.
测试是否可以运行.
#snmpwalk -v 1 -c public 127.0.0.1 SNMPv2-MIB::system
出现如下界面,就是正常运行啦.呵呵.
5. 安装Cacti
回到下载文件目录下,
#tar -xzvf cacti-0.8.7e.tar.gz
#mv cacti-0.8.7e /server/cacti/apache/htdocs/cacti
# vi /server/cacti/apache/htdocs/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
//添加cacti 用户
# useradd cacti
//将rra 目录的所有权给cacti 用户
# chown -R cacti /server/cacti/apache/htdocs/cacti/rra
//修改cacti 目录所属组
# chgrp -R cacti /server/cacti/apache/htdocs/cacti
//添加cron 任务
# crontab -e
*/5 * * * * /server/cacti/php/bin/php /server/cacti/apache/htdocs/cacti/poller.php > /dev/null 2>&1
保存退出.
6. 安装Cactid
CACTID 的安装需要以下支持(都安装好啦J):
net-snmp-devel (需要编译安装net-snmp 时添加--enable-developer 选项)
mysql
mysql-devel (mysql 源文件编译安装后默认支持)
openssl-devel (Redhat 默认安装)
# tar -zxvf cacti-cactid-0.8.6i.tar.gz
# cd cacti-cactid-0.8.6i
# ./configure --with-mysql=/server/cacti/mysql --with-snmp=/server/cacti/net-snmp
# make
//这时你将在此目录下看到多出了cactid、cactid.conf 两个文件
# mkdir /usr/local/cactid
# cp cactid cactid.conf /server/cacti/cactid
# vi /server/cacti/cactid/cactid.conf //修改cactid 配置文件
DB_Host 127.0.0.1
DB_Database cacti
DB_User cacti
DB_Pass cacti
保存退出
7. 数据库配置
#/server/cacti/mysql/bin/mysql -u root -p
Password:
Mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
Mysql> grant all on cacti.* to cacti@localhost identified by “cacti”;
Query OK, 1 row affected (0.00 sec)
Mysql>exit
# cd /server/cacti/apache/htdocs/cacti
# mysql -uroot -p cacti < cacti.sql
输入Password:
#ln -s /server/cacti/mysql/lib/mysql/libmysqlclient.so.15.0.0 /usr/lib/libmysqlclient.so.15
#ldconfig
这两句要加上,否则系统无法找到libmysqlclient.so.15库
#chmod 777 /server/cacti/apache/htdocs/cacti/log
#chmod 777 /server/cacti/apache/htdocs/cacti/rra
需要修改php.ini的参数,否则,系统会报错,
#vi .php.ini
date.timezone = utc
保存退出.在浏览器中打开
会出现如下窗口,则成功.否则,根据错误修改吧…
默认用户名 admin 默认密码 admin
第一次登录之后必须修改密码.
登陆之后,出现如下界面,就可以做其他的配置了,都是图形界面配置,呵呵.
添加新设备,配置监控参数,生成图形…
来个图示.