天天看点

rrdtool + cacti 的 配置安装经验(RedHat Enterprise Linux 4.0版)

参考自  无废话 apache+mysql+php+snmp+rrdtool+cacti 配置

原贴位置:http://bbs.chinaunix.net/viewthread....ilter%3Ddigest

我在原贴基础上进行了修改,因为适合我自己的情况,和原贴已经有很大不同,只是给遇到相似问题的朋友一点提示,不见得具有普遍性

向原作者表示感谢

我的环境描述:

     RHEL 4.0 / gcc 3.2.3 /

 安装的软件包:

  X Window System

  GNOME Desktop Environment

  Editors

  Graphical Internet

  Text-based Internet

  Server Configuration Tools

  Development Tools

  Administration Tools

  System Tools

本机IP 10.3.7.7

---安装 mysql

直接使用RHEL4自身携带的 mysql 进程,即可满足条件

可能需要额外安装mysql服务端,安装包:

 mysql-server-4.1.7-4.RHEL4.1.i386.rpm

 mysql-bench-4.1.7-4.RHEL4.1.i386.rpm

执行:

[[email protected] usr]# groupadd mysql

[[email protected] usr]# useradd -g mysql mysql

[[email protected] mysql]# /usr/bin/mysql_install_db --user=mysql

[[email protected] mysql]# ./bin/mysqld --user=mysql

[[email protected] mysql]# /usr/bin/mysqladmin -u root password mysql

[[email protected] mysql]# cd /etc/rc3.d/

[[email protected] rc3.d]# ln -s /etc/init.d/mysqld S85mysql

[[email protected] rc3.d]# ln -s /etc/init.d/mysqld K85mysql

Mysql 安装结束

---安装apache

apache 本身系统是自带的,只是为了获取最新版本外加试验,我也按照帖子重新安装了

[[email protected] usr]# tar -zxvf  httpd-2.0.55.tar.gz

[[email protected] usr]# cd httpd-2.0.55

[[email protected] httpd-2.0.54]# ./configure --prefix=/www --enable-so

[[email protected] httpd-2.0.54]# make && make install

[[email protected] httpd-2.0.54]# cp /www/bin/apachectl /etc/init.d/httpd

[[email protected] httpd-2.0.54]# cd /etc/rc3.d

[[email protected] rc3.d]# ln -s /etc/init.d/httpd S85httpd

[[email protected] rc3.d]# ln -s /etc/init.d/httpd K85httpd

[[email protected] rc3.d]# /www/bin/apachectl start

[/code]

Apache 安装完毕

---安装PHP

同样,PHP也可以使用系统自带的,处于使用最新php版本的原因,进行了新的安装

[code]

[[email protected] usr]# tar -zxvf php-4.3.10.tar.gz

[[email protected] usr]# cd php-4.3.10

[[email protected] php-4.3.10]# ./configure --prefix=/www/php /

> --with-apxs2=/www/bin/apxs /

> --with-config-file-path=/www/php /

> --enable-sockets /

> --with-mysql=/usr/local/mysql /

> --with-zlib /

> --with-libxml /

> --with-gd

[[email protected] php-4.3.10]# make && make install

# 没有使用 [[email protected] php-4.3.10]# cp php.ini-dist /www/php/php.ini

[[email protected] php-4.3.10]# vi /www/conf/httpd.conf

            加入内容:

     AddType application/x-tar .tgz

                   AddType application/x-httpd-php .php

                   AddType image/x-icon .ico

           DirectoryIndex属性调整为:

                   DirectoryIndex index.php index.html index.html.var

        保存退出 :wq

[[email protected] php-4.3.10]# /www/bin/apachectl restart

[/code]

---补充:由于with-gd选项可能需要图形支持,如果出现编译错误,则需要安装如下rpm包:

 libjpeg-devel-6b-33.i386.rpm

 libart_lgpl-devel-2.3.16-3.i386.rpm

 libattr-devel-2.4.16-3.i386.rpm

 libpng10-1.0.16-1.i386.rpm

 libpng10-devel-1.0.16-1.i386.rpm

 libpng-devel-1.2.7-1.i386.rpm

Php安装完毕

---设置mysql,建立cacti数据库和数据库帐户

[code]

[[email protected] php-4.3.10]# /usr/local/mysql/bin/mysql -u root -pmysql

    mysql> create database cactidb;

  mysql> grant all on cactidb.* to root;

  mysql> grant all on cactidb.* to [email protected];

  mysql> grant all on cactidb.* to cactiuser;

  mysql> grant all on cactidb.* to [email protected];

  mysql> set password for [email protected]=password('cactipw');

注:以上语句输出 Query OK, 0 rows affected (0.01 sec) 表示成功

  mysql> exit

Mysql设置完毕

---检测apache + php + mysql

[root @tsai usr]# cd /www/htdocs

[root @tsai htdocs]# touch test.php

[root @tsai htdocs]# vi test.php

            <?

            phpinfo( );

            ?>

 保存退出 :wq

[root @tsai htdocs]# touch mydqltest.html

[root @tsai htdocs]# vi mysqltest.html

      <html>

         <body>

            <?

               $link=mysql_connect('localhost','root');

                mysql_select_db('mysql');

               $str="select * from user;";

               $result=mysql_query($str,$link);

               $show=mysql_num_rows($result);

               mysql_close($link);

               for ($i=0;$i < $show;$i++)

                   {

                 $arr[$i]=mysql_fetch_array($result);

                   };

            ?>

 <table align=center border=1>

          <tr align=center>

             <td>Host</td>

             <td>User</td>

             <td>Password</td>

          </tr>

 <?for ($i=0;$i<$show;$i++){?>

          <tr>

            <td><?echo $arr[$i][Host]?></td>

            <td><?echo $arr[$i][User]?></td>

            <td><?echo $arr[$i][Password]?></td>

         </tr>

             <?};?>

          </body>

       </html>

 保存退出 :wq

[/code]

重启mysql + apache 服务

[root @Bleach htdocs]# /etc/init.d/mysqld restart

[root @Bleach htdocs]# /etc/init.d/httpd restart

进入浏览器检查

http://10.3.7.7/test.php 和 http://10.3.7.7/mysqltest.html

---安装rrdtool

[code]

[[email protected] usr]# tar zxvf rrdtool.tar.gz

[[email protected] usr]# cd rrdtool-1.2.12

[[email protected] rrdtool-1.0.50]# ./configure

[[email protected] rrdtool-1.0.50]# make && make install

[/code]

补充说明:

 rrdtool需要tcl开发库的支持,否则会出现编译错误,请安装

  tcl-devel-8.4.7-2.i386.rpm

  tcl-html-8.4.7-2.i386.rpm

  tclx-devel-8.3.5-4.i386.rpm

  tclx-doc-8.3.5-4.i386.rpm

 另外编译过程中可能出现错误: cc1: invalid option `tune=pentium4'

 修改:进入 /rrdtool-1.2.12/bindings/perl-shared,编辑Makefile

      删除 OPTIMIZE = -O2 -g -pipe -m32 -march=i386 -mtune=pentium4 中的 -mtune=pentium4

      ---这个可能和gcc版本有关

Rrdtool安装完毕

安装net-snmp、snmpwalk和snmpget命令

[code]

[[email protected] usr]# rpm -qa | grep net-snmp

 net-snmp-5.1.2-11

 net-snmp-utils-5.1.2-11

 net-snmp-libs-5.1.2-11

 net-snmp-perl-5.1.2-11

 net-snmp-devel-5.1.2-11

[[email protected] usr]# vi /etc/snmp/snmpd.conf

更改 1、com2sec notConfigUser  default       public

       改为:com2sec notConfigUser   127.0.0.1       public

       2、access  notConfigGroup ""      any       noauth    exact  systemview  none none

       改为:access  notConfigGroup ""      any       noauth    exact  all  none  none

       3、#view all    included  .1         80

       将前面的 # 注释 去掉。

保存退出 :wq

[[email protected] usr]# service snmpd restart

[/code]

注:如果你机器内没有snmpwalk和snmpge命令,请安装:

 net-snmp-devel-5.1.2-11.i386.rpm

 net-snmp-perl-5.1.2-11.i386.rpm

 net-snmp-utils-5.1.2-11.i386.rpm

[code]

安装/ 配置cacti

[code]

[[email protected] usr]# useradd cactiuser -g users

[[email protected] usr]# passwd cactiuser (pwd:cactipw)

[[email protected] usr]# cp cacti-0.8.6h.tar.gz /www/htdocs/

[[email protected] usr]# cd /www/htdocs/

[[email protected] htdocs]# tar zxvf cacti-0.8.6h.tar.gz

[[email protected] htdocs]# mv cacti-0.8.6h cacti

[[email protected] htdocs]# cd cacti

[[email protected] cacti]# /usr/local/mysql/bin/mysql -u root -pmysql cactidb < cacti.sql

[[email protected] cacti]# chown -R cactiuser rra/

[[email protected] cacti]# chown -R cactiuser log/

[[email protected] cacti]# cd scripts

[[email protected] scripts]# chown cactiuser:users *

[[email protected] scripts]# vi /www/htdocs/cacti/include/config.php

 $database_type = “mysql”;

 $database_default = “cactidb”;

 $database_hostname = “localhost”;

 $database_username = “cactiuser”;

 $database_password = “cactipw”;

 更改用户、密码 等项 与上面给出的对应 保存退出

[[email protected] scripts]# crontab -u cactiuser -e 

加入

*/5 * * * * /www/php/bin/php /www/htdocs/cacti/poller.php > /dev/null 2>&1

保存退出:wq

[/code]

全部设置完毕。

打开浏览器 http://10.3.7.7/cacti 进入cacti的初始设置页面

第一次默认登陆账号:admin 密码 admin

登陆后在新改个密码就OK

需要说明的还有路径

[code]

 snmpwalk Binary Path : /usr/bin/snmpwalk

 snmpget Binary Path: /usr/bin/snmpget

 snmpbulkwalk Binary Path: /usr/bin/snmpbulkwalk

 snmpgetnext Binary Path: /usr/bin/snmpgetnext

 RRDTool Binary Path: /usr/local/rrdtool-1.2.12/bin/rrdtool

 PHP Binary Path: /www/php/bin/php

 Cacti Log File Path: /www/htdocs/cacti/log/cacti.log

 Cactid Poller File Path: /www/htdocs/cacti/poller.php

 如果你是按上述步骤做的 那上面的路径不会错。

[/code]

注:此时graphs还不能显示图形,需要将服务重新启动一下

[code]

[[email protected] scripts]# /etc/init.d/snmpd restart

[[email protected] scripts]# /etc/init.d/mysqld restart

[[email protected] scripts]# /etc/init.d/httpd restart

[/code]

 现在打开或刷新 http://10.3.7.7/cacti 选 graphs 选项应该能出图形

 如还没有显示图形,则检查 cacti/rra cacti/log 的权限是否符合,查看rra/目录下是否有生成的数据文件

 可以尝试使用 php poller.php 执行查看是否rra目录下有生成的文件

 如果依然没有产生图形,则进入web,选择【Console】-》【Graph Management】任意选择右侧项目,在页面又上角选择【Turn On Graph Debug Mode.】

     可以查看打印信息进行问题定位。