Chinaunix首页 | 论坛 | 博客
  • 博客访问: 54536
  • 博文数量: 4
  • 博客积分: 2955
  • 博客等级: 少校
  • 技术积分: 38
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-21 14:48
文章分类

全部博文(4)

文章存档

2010年(2)

2009年(2)

最近访客

分类: LINUX

2009-11-10 10:08:40

cacti流量监控服务器搭建手册
 
1、安装环境及软件需求:
 centos-5.2 
 mysql-5.0.67 
 apache-2.2.9 
 php-5.2.6 
 eaccelerator-0.9.5.3 
 net-snmp-5.4.2       
 rrdtool-1.3.4  
 cacti-0.87b  
 cacti-spine-0.87a  
 cacti-plugin-arch-2.1 
 php-weathermap-0.95b 
 
2、 基本安装:
 2.1 centos安装
   具体安装参考其他资料,只选取开发工具包,其他不选。
   安装完后更新源为国内速度比较快的电信服务器
    vi  /etc/yum.repos.d/CentOS-Base.repo
    :1,$s/mirror.centos.org/mirror.be10.com/g
    :wq
   安装插件: yum -y install yum-fastestmirror
   更新系统所有已安装的包:yum update
   后面编译过程需要的一些包也直接yum安装:比如 gd,pango,zlib等
   
 2.2 mysql 数据库的安装
   可参考解压出来的目录下 INSTALL-BINARY 文件:
   shell> groupadd mysql
   shell> useradd -g mysql mysql
   shell> tar zxvf mysql.tar.gz
   shell> cd mysql
   shell> ./configure  --prefix=/usr/local/mysql
   shell> make && make install
   shell> cp support-files/my-medium.cnf  /etc/my.cnf
   shell> cd /usr/local/mysql
   shell> chown -R mysql .
   shell> chgrp -R mysql .
   shell> scripts/mysql_install_db --user=mysql
   shell> chown -R root .
   shell> chown -R mysql data
   shell> bin/mysqld_safe --user=mysql &
   
   让mysql开机自动运行:
   法1: echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >>/etc/rc.local
   法2: cp support-files/mysql.server /etc/init.d/mysql
      chmod +x /etc/init.d/mysql
      chkconfig --add mysql
      chkconfig --level 35 mysql on
      service mysql start
    或者分别进入rc3.d和rc5.d目录手动建立连接文件:
      cd /etc/rc3.d and rc5.d
      ln -s ../init.d/mysql S86mysql
      ln -s ../init.d/mysql K86mysql
(Note: the number in filename doesn't conflict with other scripts)
   
   把mysql库文件导入系统库路径:
   echo "/usr/local/mysql/lib" >/etc/ld.so.conf.d/mysql.lib.conf
   shell> ldconfig
      
 2.3 apache的安装:
   ./configure --prefix=/www --enable-so
   make && make install
   
   编译过程有错的话,就是缺少一些开发库,yum搜索安装即可
   修改配置文件 /www/conf/httpd.conf ,找到User 和Group改为:
     User apache
     Group apache
   在系统中增加帐号: useradd -s /bin/nologin -d /dev/null apache  
   
   开机自动运行: echo "/www/bin/apachectl -k start" >> /etc/rc.local
   
 2.4 PHP的安装:
   ./configure --prefix=/www/php \
         --with-apxs2=/www/bin/apxs \
         --with-config-file-path=/www/php \
         --enable-sockets \
         --with-mysql=/usr/local/mysql \
         --with-zlib-dir=/usr/include \
         --with-gd
   make && make install
   cp php.ini-dist /www/php/php.ini
   
   在apache配置文件中增加以下内容来支持php:
   vi /www/conf/httpd.conf
   找到,在DirectoryIndex 后面增加 index.php
   找到,在下面增加以下内容:
      ###############for php and cacti###################
      AddType application/x-tar .tgz
      AddType application/x-httpd-php .php
      AddType image/x-icon .ico
      #######################over########################
   
   库文件处理:
    echo "/www/php/lib" >/etc/ld.so.conf.d/php.lib.conf
    ldconfig
    
 2.5  php加速--eaccelerator的安装:
    
    ./configure --prefix=/www/eaccelerator \
           --enable-eaccelerator=shared \
           --with-php-config=/www/php/bin/php-config
    make && make install
   
   编辑PHP配置文件(/www/php/php.ini)增加以下内容:
   
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;     ;
     ;  2008/10/14 zhyong         ;
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
     zend_extension="/www/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
     eaccelerator.shm_size="16"
     eaccelerator.cache_dir="/tmp/eaccelerator"
     eaccelerator.enable="1"
     eaccelerator.optimizer="1"
     eaccelerator.check_mtime="1"
     eaccelerator.debug="0"
     eaccelerator.filter=""
     eaccelerator.shm_max="0"
     eaccelerator.shm_ttl="0"
     eaccelerator.shm_prune_period="0"
     eaccelerator.shm_only="0"
     eaccelerator.compress="1"
     eaccelerator.compress_level="9"
   以上可参考eaccelerator解压后目录内的README文件
   建立eaccelerator的暂存数据目录:
    mkdir /tmp/eaccelerator
    chmod 0777 /tmp/accelerator
    
 2.6 rrdtool和net-snmp的安装:
 
   直接参照解压目录的README和INSTALL文件进行安装
   ./configure
   make && make install
   
   rrdtool库文件:
     echo "/usr/local/rrdtool-1.3.4/lib" >/etc/ld.so.conf.d/rrdtool.lib.conf
     ldconfig
   
 2.7 mysql数据库的一些设置:
   
    主要是一些数据库权限的设置
    useradd cactiuser
    /usr/local/mysql/bin/mysql -u root -p
    mysql> set password for );    
    mysql> create database cacti;                                  
       mysql> grant all on cacti.* to root;                           
       mysql> grant all on cacti.* to ;                 
       mysql> grant all on cacti.* to cactiuser;                      
       mysql> grant all on cacti.* to ;            
       mysql> set password for );
       mysql> flush privileges;               
       mysql> exit   
      
  2.8 cacti的安装:
    
    tar -zxvf cacti-0.8.7b.tar.gz
    mv cacti-0.8.7b /www/htdocs/cacti
    cd /www/htdocs/cacti
    导入cacti数据库
    /usr/local/mysql/bin/mysql -u root -pcactipw cacti    
    chown -R cactiuser /www/htdocs/cacti
    
    修改 /www/htdocs/cacti/include/config.php 和global.php文件
    
    $database_type = “mysql”;
    $database_default = “cacti”;
    $database_hostname = “localhost”;
    $database_username = “cactiuser”;
    $database_password = “cactipw”;
 
   crontab –u cactiuser –e
   */5 * * * * /www/php/bin/php /www/htdocs/cacti/poller.php > /dev/null 2>&1
   
 2.9  cacti-spine 的安装:
 
   ./configure --with-mysql=/usr/local/mysql/include
   make && make install
   
   默认安装在目录/usr/local/spine
   修改配置文件:  vi /usr/local/spine/etc/spine.conf
        DB_Host         localhost
        DB_Database     cacti   
        DB_User         cactiuser
        DB_Pass         cactipw 
        DB_Port         3306  
    
  2.10 收尾
   
    可执行文件加入路径:
    echo "export PATH=$PATH:/usr/local/mysql/bin:/www/bin:/www/php/bin:/usr/local/rrdtool-1.3.4/bin" >>/etc/profile
    source /etc/profile
    
    启动服务:
     service mysql start  或者 /usr/local/mysql/bin/mysqld_safe --user=mysql &
     /www/bin/apachectl -k start
     
   查看服务是否启动:
       netstat -tunlp |grep :80
       netstat -tunlp |grep :3306
      
   清除防火墙设置: iptables -F    
    现在就可以通过 访问cacti页面啦
    要通过直接访问,需要在DNS服务器上设置域名指向,然后修改apache配置文件
     vi /www/conf/httpd.conf
     修改 DocumentRoot = "/www/htdocs/cacti"
    
     apache错误日志: /www/logs/err_log
    
     初次打开要求设置admin密码,然后是snmpwalk等路径设置
        /usr/local/bin/snmpwalk
        /usr/local/bin/snmpget
        /usr/local/bin/snmpbulkwalk
        /usr/local/bin/snmpgetnext
        /usr/local/rrdtool-1.3.4/bin/rrdtool
        /www/php/bin/php
        /www/htdocs/cacti/log/cacti.log
        /usr/local/spine/bin/spine
      
     进入页面后的基本设置:
     console ->setting ->General
       SNMP Utility Version -->
       RRDTool Utility Version -->
       SNMP Version -->
       SNMP Community -->
       
     console ->setting ->Visual
       Maximum Field Length -->30
      此项与流量图上的提示文字有关,Length太小会造成部分GigabitEthernet1/0/1显示不全
      
    console ->setting ->Poller
      Poller Type --> spine
 
  2.11 常见问题:
    
    2.11.1 对于Traffic 大于800Mbits/s的无法显示问题.
     在创建graph前修改 Data Templates -> Interface Traffic ->
      1: traffic_in -> Maximum Value Use Per-Data Source Value 默认是100000000 后面再添 几个0就OK了,
      2: traffic_out也要修改,
     最好在使用new graph创建新的graph之前修改,否则之后修改会有一定的麻烦,甚至无法正常工作。
   
   2.11.2 不能连接数据库
     查看以下文件中关于数据库的配置
      /www/htdocs/cacti/include/global.php  config.php
       /usr/local/spine/etc/spine.conf
     查看/tmp/mysql.sock文件是否存在,没有的话重启mysql服务可以自动建立
      service mysql restart
      或 killall -9 mysql ; mysqld_safe --user=mysql &
      
   2.11.3 打开页面遇到"Access Deniess" 或者admin帐号异常
     直接进数据库修改:(默认密码为md5加密)
      mysql -u root -pcactipw
      mysql> use cacti;
      mysql> update user_auth set password=md5('newpasswd') where username='admin';
      mysql> \q
        
   2.11.4 在页面上添加了device,但在Graph下没有图像:
      主要是在crontab计划任务里面是每隔5分钟进行一次poller,所以需要5分钟后才能绘出图像,
      图形位于/www/htdocs/cacti/rra/目录下的 *.rrd文件
      
      也可以手工运行:
      测试被控对象是否开启了SNMP服务,public为团体名:
        snmpwalk -v 2c -c public 10.10.0.1 
      测试PHP是否可以采集到数据
       /www/php/bin/php /www/htdocs/cacti/poller.php
 
3.插件weathermap的安装
   
  3.1 cacti-plugin-arch 安装
   
   tar -zxvf cacti-plugin-arch.tar.gz
   cd cacti-plugin-arch
   
   直接用处理好的页面替换原来cacti目录下文件:
   cp -rf files-0.8.7b/* /www/htdocs/cacti/
   
   导入数据库:
    mysql -u root -pcactipw cacti < pa.sql
   
   最后重新修改/www/htdocs/cacti/include/global.php文件中关于数据库的设置
    $database_type = "mysql";
    $database_default = "cacti";
    $database_hostname = "localhost";
    $database_username = "cactiuser";
    $database_password = "cactipw";
    $database_port = "3306";
   
   权限设置:
      chown -R cactiuser /www/htdocs/cacti
     
  3.2 weathermap 的安装
   
   unzip php-weathermap-0.95b.zip
   mv weathermap /www/htdocs/cacti/plugins/
   chown -R cactiuser /www/htdocs/plugins/
   
   激活weathermap插件:
   修改cacti目录下的include/global.php的配置文件,在配置中查找
   /* Default session name - Session name must contain alpha characters */行,
   在此行$plugins = array();下面加入:
     $plugins[] = 'weathermap';
   注意:上面weathermap的名字必须与cacti/plugins/目录下插件目录的名字相同。
   
   cd /www/htdocs/cacti/plugins/weathermap
   cp editor-config.php-dist editor-config.php
   chmod -R 777 configs
   vi editor-config.php
   修改$cacti_base,$cacti_url,$mapdir这三个参数为实际路径。
   
   最后进入页面修改:
   console -> User Management ->admin -> Realm Permissions
   勾选 Plugin -> Weathermap: Configure/Manage
     Plugin -> Weathermap: View
   保存退出。
   
   其他更多插件到 
                
阅读(3386) | 评论(0) | 转发(0) |
0

上一篇:LVS+Keepalived实现高可用集群

下一篇:没有了

给主人留下些什么吧!~~