cacti

http://aaronw.me/static/90.html

cacti是一套PHP程序,它运用snmpget采集数据,使用rrdtool绘图。使用Cacti能统计网络设备的流量

、CPU、系统负载等参数,也可以自定义监测的指标。

所有的软件都放在/opt目录下

1、安装apache
[root@script opt]# # tar vxzf  httpd-2.0.54.tar.gz
[root@script opt]# cd httpd-2.0.54
[root@script httpd-2.0.54]# ./configure –prefix=/usr/local/apache –enable-so
[root@script httpd-2.0.54]# make && make install
[root@script httpd-2.0.54]# /usr/local/apache/bin/apachectl start
[root@script httpd-2.0.54]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@script httpd-2.0.54]# chmod a+x /etc/init.d/httpd
[root@script httpd-2.0.54]# vi /etc/init.d/httpd
      在第三行加入如下两行:
      # chkconfig: 345 85 15
      # description: Starts and stops the Apache HTTP Server.
      保存退出:wq
[root@script httpd-2.0.54]# chkconfig –add httpd


2、安装mysql
[root@script opt]# tar vxzf mysql-4.0.18.tar.gz
[root@script opt]# cd mysql-4.0.18
[root@script mysql-4.0.18]# ./configure –prefix=/usr/local/mysql
[root@script mysql-4.0.18]# make && makeinstall
[root@script mysql-4.0.18]# ./scripts/mysql_install_db
[root@script mysql-4.0.18]# /usr/local/mysql/bin/mysqld_safe –user=root &
[root@script mysql-4.0.18]# /usr/local/mysql/bin/mysqladmin -u root password 888888
[root@script mysql-4.0.18]# cp /usr/local/mysql/share/mysql/mysql.server

/etc/rc.d/init.d/mysqld
[root@script mysql-4.0.18]# chkconfig –add mysqld

3、安装php
[root@script opt]# tar vxzf php-4.4.2.tar.gz
[root@script opt]# cd php-4.4.2
[root@script php-4.4.2]# ./configure –prefix=/usr/local/php \
–with-apxs2=/usr/local/apache/bin/apxs \
–with-config-file-path=/usr/local/php \
–with-mysql=/usr/local/mysql \
–with-zlib-dir=/usr/include \
–enable-sockets \
–with-gd
    最后可能会提示缺少libxml,就需要下载回来安装,很简单 ./configure 然后 make && make

install
[root@script php-4.4.2]# make && make install
[root@script php-4.4.2]# cp php.ini-dist /usr/local/php/php.ini
[root@script php-4.4.2]# vi /usr/local/apache/conf/httpd.conf
    按 I 键添加
    AddType application/x-tar .tgz
    AddType application/x-httpd-php .php
    AddType image/x-icon .ico
    DirectoryIndex index.php index.html index.html.var
    保存退出 :wq
[root@script php-4.4.2]# /usr/local/apache/bin/apachectl restart

4、设置mysql
[root@script opt]# /usr/local/mysql/bin/mysql -uroot -p888888
    mysql> create database cacti;
    mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY ‘cactipwd’;
    mysql> flush privileges;
注:以上语句输出 Query OK, 0 rows affected (0.01 sec) 表示成功
  mysql> exit

5、检查apache+php+mysql
[root@script opt]# cd /usr/local/apache/htdocs
[root@script htdocs]# touch test.php
[root@script htdocs]# vi test.php
    <?
      phpinfo( );
    ?>
保存退出 :wq
[root@script htdocs]# touch mysqltest.php
[root@script htdocs]# vi mysqltest.php
      <html>
         <body>
            <?
               $link=mysql_connect(‘localhost’,'root’,’888888′);
                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

重启mysql + apache 服务
[root@script htdocs]# service mysql restart
[root@script htdocs]# service httpd restart
进入浏览器检查
http://localhost/test.phphttp://localhost/mysqltest.php

6、安装rrtool
与mrtg相比,rrdtool自带了gd库,所以不用先安装gd库。(不过由于rrdtool自带的gd库不支持中文,

所以rrdtool画出�淼耐家膊荒苡兄形模�否则会出现乱码)。
注意:rrdtool1.2的版本由于已经不再自带外部的lib库(如cgilib,zlib等),所以需要从

http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/pub/libs/下载这些库�戆沧啊=ㄒ榛故鞘褂�

1.0的版本,比较方便。

[root@script opt]# tar vxzf rrdtool-1.0.50.tar.gz
[root@script local]# cd rrdtool-1.0.50
[root@script rrdtool-1.0.50]# ./configure –prefix=/usr/local/rrdtool
[root@script rrdtool-1.0.50]# make && make install
7、安装net-snmp、snmpwalk和snmpget命令
[root@script opt]# rpm -qa | grep net-snmp
    net-snmp-5.0.9-2.30E.15
    net-snmp-devel-5.0.9-2.30E.15
    net-snmp-libs-5.0.9-2.30E.15
    net-snmp-utils-5.0.9-2.30E.15
[root@script opt]# vi /etc/snmp/snmpd.conf
       更改 com2sec notConfigUser  default       public
       改为 com2sec notConfigUser  127.0.0.1     public
       更改 access  notConfigGroup “”      any       noauth    exact  systemview  none 

none
       改为 access  notConfigGroup “”      any       noauth    exact  all         none 

none
       将 #view all    included  .1         80 前面的 # 注释去掉
保存退出 :wq
[root@script opt]# service snmpd restart
注:如果你机器内没有snmpwalk和snmpge命令,请到安装盘里查找 net-snmp-utils 包,执行 rpm -

ivh net-snmp-utils-5.0.9-2.30E.15.i386.rpm 之后这两个命令就在系统里了。其他包也都在安装盘

里 确保安装这四个包就OK

8、安装配置cacti
[root@script opt]# cp cacti-0.8.6g.tar.gz /usr/local/apache/htdocs/
[root@script opt]# cd /usr/local/apache/htdocs/
[root@script htdocs]# tar vxzf cacti-0.8.6g.tar.gz
[root@script htdocs]# mv cacti-0.8.6g cacti
[root@script htdocs]# cd cacti
[root@script cd cacti]# /usr/local/mysql/bin/mysql -uroot -p888888 cacti < cacti.sql
[root@script cd cacti]# cd scripts
[root@script cd scripts]# vi /usr/local/apache/htdocs/cacti/include/config.php
    $database_type = “mysql”;
    $database_default = “cacti”;
    $database_hostname = “localhost”;
    $database_username = “cactiuser”;
    $database_password = “cactipwd”;
更改用户、密码 等项 与上面给出的对应 保存退出
[root@script cd scripts]# vi /etc/crontab
加入
*/5 * * * * root /usr/local/php/bin/php /usr/local/apache/htdocs/cacti/poller.php >

/dev/null 2>&1
保存退出:wq

9、最后说明
全部设置完后打开浏览器 http://localhost/cacti 进入cacti的初始设置页面,第一次默认登陆账号

:admin 密码 cactipwd ,登陆后再新改个密码,再用admin和密码登陆就OK
需要说明的还有路径
snmpwalk Binary Path : /usr/bin/snmpwalk
snmpget Binary Path: /usr/bin/snmpget
RRDTool Binary Path: /usr/local/rrdtool/bin/rrdtool
PHP Binary Path: /usr/local/php/bin/php
Cacti Log File Path: /usr/local/apache/htdocs/cacti/log/cacti.log
Cactid Poller File Path: /usr/local/apache/htdocs/cacti/poller.php
最好确认一下路径是否正确

注:此时graphs还不能显示图形,需要将服务重新启动一下
[root@script /]# service snmpd restart
[root@script /]# /usr/local/mysql/bin/mysqld_safe –user=root &
[root@script /]# /usr/local/apache/bin/apachectl start
OK ,现在打开或刷新 http://192.168.1.99/cacti 选 graphs 选项一定能出图形

你可能感兴趣的:(linux,职场,cacti,休闲)