免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2464 | 回复: 4
打印 上一主题 下一主题

安装Cacti的记录 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-05 01:54 |只看该作者 |倒序浏览
Cacti已经听说过很久,而且还领略过其风采,由于懒,未曾自己实际安装,这两天终于找了个时间,装了起来,感觉越用越好用,值得推荐.我就把我安装的过程,还有碰到的一些问题,记录在此,以作参考. 若有错漏,多多包涵. 在这个论坛学习了很多, 权当自己的一份作业吧.

安装的原则(自我感觉,欢迎拍砖):
1. 认真看清楚官方文档. 当然,官方文档很多,有时候抓到一个便以为是救生圈,所以我的建议是先多看,如果觉得差不多,就可以动手了.
2. 利用google. 我想这个就不用多说了.
3. 不断尝试. 我装了两次,第一次是因为没有耐性,php没法把gd编译进去(不知道这种说法对否),就放弃,重新在一个Redhat AS 3 上完整的又装了一次. 回头又把原来的系统再弄好.

1. 必需的软件
这里的安装包基本都是源代码,需要编译. 有兴趣的可以都用rpm包安装,我是装rpm给装怕了.
mysql (建议使用4.x, 试过用5.x,但是碰到在用的过程中,mysql出现问题,换了4.x,就好了,未深入研究什么原因) --> --> 下载
php --> 下载
Apache --> 下载
zlib --> 下载
libpng --> 下载
freetype --> 下载
GD --> 下载
Net-snmp --> 搜索和下载 (建议安装rpm包,省点事,包括下面三个net-snmp net-snmp-devel net-snmp-utils)
Libart --> 下载
RRDtool --> 下载
Cacti --> 下载

2. 安装过程
a. 安装顺序
mysql -> apache -> net-snmp -> zlib -> libpng -> freetype -> Libart -> GD -> php -> RRDtool -> Cacti
当然, 这个顺序也不是必然, 但是, 编译php之前一定要把GD装上, 而GD前面的库, 肯定也是在装GD之前装上咯,而且有些也是rrdtool必须的.

b. 安装步骤

mysql:

groupadd mysql
useradd -g mysql mysql
gunzip < mysql-VERSION.tar.gz | tar -xvf -
cd mysql-VERSION
./configure --prefix=/usr/local/mysql
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql
bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql var
chgrp -R mysql .
bin/mysqld_safe --user=mysql &

Apache:
./configure --prefix=/usr/local/apache --enable-shared=max --enable-cache --enable-speling --enable-rewrite --enable-so --with-mpm=worker --enable-ssl
make
make install

Net-snmp:
因为是rpm包, rpm -ivh Net-snmp* 就好了.

libpng libjpeg freetype Libart RRDtool GD:
这几个比较重要,而且Cacti有安装的指导,涉及一些环境变量的设置,所以放在一起说.

* 设置环境变量
BUILD_DIR=/tmp/rrdbuild
NSTALL_DIR=/usr/local/rrdtool-1.2.12

* zlib
cd $BUILD_DIR
wget http://people.ee.ethz.ch/oetiker ... s/zlib-1.2.2.tar.gz
tar zxf zlib-1.2.2.tar.gz
cd zlib-1.2.2
env CFLAGS="-O3 -fPIC" ./configure --prefix=$BUILD_DIR/lb
make
make install

* libpng
cd $BUILD_DIR
wget http://people.ee.ethz.ch/oetiker ... 1.2.8-config.tar.gz
tar zxvf libpng-1.2.8-config.tar.gz
cd libpng-1.2.8-config
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

* freetype
cd $BUILD_DIR
wget http://people.ee.ethz.ch/oetiker ... eetype-2.1.9.tar.gz
tar zxvf freetype-2.1.9.tar.gz
cd freetype-2.1.9
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

* libart_lgpl
cd $BUILD_DIR
wget http://people.ee.ethz.ch/oetiker ... _lgpl-2.3.17.tar.gz
tar zxvf 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

* 再次设置环境变量
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

* rrdtool
cd $BUILD_DIR/rrdtool-1.2.12
./configure --prefix=$INSTALL_DIR --disable-python --disable-tcl
make clean
make
make install

* GD
./configure --prefix=/usr/local/gd --with-freetype=/usr/local/freetype --
with-libpng=/usr/local/libpng
make
make install

PHP:
./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/gd --with-zlib --with-png=/usr/local/libpng --with-jpeg --with-freetype=/usr/local/freetype --enable-sockets
make
make install

Cacti:
cp cacti-0.8.6g.tar.gz /usr/local/apache/htdocs
cd /usr/local/apache/htdocs
tar zxvf cacti-0.8.6g.tar.gz
mv cacti-0.8.6g cacti
cd cacti
/usr/local/mysql/bin/mysqladmin -uroot create cacti
/usr/local/mysql/bin/mysql -uroot < cacti.sql
创建帐号:
/usr/local/mysql/bin/mysql -uroot
grant all privileges on cacti.* to cactiuser@localhost identified by 'cacti';
flush privileges;
chown –R cactiuser rra/ log/
vi ./include/config.php
$database_type = “mysql”;
$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “cactiuser”;
$database_password = “cacti”;
vi /etc/crontab
*/5 * * * * cactiuser /usr/local/php/bin/php /user/local/apache/htdocs/cacti/poller.php > /dev/null 2>&1

3. 测试

试执行
/usr/local/php/bin/php /user/local/apache/htdocs/cacti/poller.php
如果得到类似:
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
说明运行正常. 测试完, 把 /rra里面的rrd文件删除,原因是用root帐号执行的,可能引起权限的问题.

4. 碰到的问题
a. mysql的问题,前面已经提到.

b. 编译GD时候出现的错误:
gd_png.c:802: syntax error before '&' token
gd_png.c:802: warning: data definition has no type or storage class
gd_png.c:404: storage size of `open' isn't known
make[2]: *** [gd_png.lo] Error 1
make[2]: Leaving directory `/tmp/gd-2.0.26gif'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/tmp/gd-2.0.26gif'
make: *** [all] Error 2
[root@RHEL3 gd-2.0.26gif]#

解决方法:
修改gd_png.c #include "/usr/local/libpng/include/png.h"

可能漏了一些问题,我想起来再更新

5. 参考资料

http://linux.chinaunix.net/jh/4/594019.html
http://www.phpv.net/article.php/272
http://bbs.chinaunix.net/archiver/?tid-644567-page-1.html
http://bbs.chinaunix.net/archiver/?tid-686668.html
http://www.cacti.net/downloads/docs/html
rrdtool-version/doc/rrdbuild.txt

若有遗漏,敬请原谅.

[ 本帖最后由 jordi 于 2006-4-5 11:12 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-04-05 02:05 |只看该作者
贴两张图片, 很不一样

ScreenHunter_014.jpg (48.25 KB, 下载次数: 10)

ScreenHunter_014.jpg

ScreenHunter_013.jpg (36.52 KB, 下载次数: 14)

ScreenHunter_013.jpg

论坛徽章:
0
3 [报告]
发表于 2006-04-22 09:53 |只看该作者
写得好!!

论坛徽章:
0
4 [报告]
发表于 2006-06-15 22:47 |只看该作者
学习   支持
谢谢

论坛徽章:
0
5 [报告]
发表于 2006-06-16 08:44 |只看该作者
如果将rrdtool的源文件修改一下,就可以在图片上显示简体中文字了

http://www.linuxsky.net/html/200605/3067.html

修改cacti的源文件
site/include/top_header.php
添加
<META http-equiv="Content-Type" content="text/html; charset=gb2312">

site/include/top_graph_header.php
添加
<META http-equiv="Content-Type" content="text/html; charset=gb2312">

这样就可以很好的显示中文了

如果使用的是mysql 5的话

还需要修改mysql的配置文件,让服务器使用GB2312的编码,然后再生成cacti用到的数据库,并修改
site/lib/database.php
function db_connect_real($host,$user,$pass,$db_name,$db_type, $port = "3306", $retries = 20) {
        global $cnn_id;

        $i = 0;
        $cnn_id = NewADOConnection($db_type);

        $hostport = $host . ":" . $port;

        while ($i <= $retries) {
                if ($cnn_id->PConnect($hostport,$user,$pass,$db_name)) {
                        $cnn_id->Execute("SET NAMES 'GB2312'");
                        return(1);
                }

                $i++;

                usleep(400000);
        }

        cacti_log("ERROR: Cannot connect to MySQL server on '$host'. Please make sure you have specified a valid MySQL database name in 'include/config.php'
.");

        return(0);
}
这样就可以用中文来命名了。

[ 本帖最后由 springwind426 于 2006-6-16 09:01 编辑 ]

graph_image.php.png (44.6 KB, 下载次数: 12)

graph_image.php.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP