cacti的配置

监控软件: cacti , nagios , ntop 这几个其他文章有介绍:
使用yum安装需要的软件包:
# yum install php php-mysql php-snmp mysql mysql-server net-snmp net-snmp-libs net-snmp-utils php-pdo perl-DBD-MySQL
在主监控机上安装rrdtool: 下载地址: http://pkgs.repoforge.org/rrdtool/
        需要安装rrdtool rrdtoo-devel rrdtool-php    
下载好这些软件使用:
           #yum localinstall *.rpm –nogpgcheck
     这里也可以使用yum安装网上安装(个人认为比较方便)
     
     
     
     
  1. 1、编辑/etc/yum.repo.d/Centos.Base.repo文件,把下面内容加入最后:  
  2. [dag]  
  3. name=Dag RPM Repository for Red Hat Enterprise Linux  
  4. baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag  
  5. gpgcheck=1  
  6. gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt  
  7. enabled=1  
  8.  
  9. 2、# yum clean all 
  10. # yum install rrdtool rrdtool-devel rrdtool-php 
配置/etc/snmp/snmp.conf文件:
     
     
     
     
  1.  com2secnotConfigUser default publicdefault该用来127.0.0.1    
  2.  access notConfigGroup "" any noauth exact systemview none none将systemview该为all    
  3. #view all included .1 80的‘#’去掉  
  4. #service snmpd restart 
 
   安装cacti 下载cacti-0.8.7e.tar.gz

        #tar xvf cacti-0.8.7e.tar.gz

        #mv cacti-o.8.73.tar.gz /var/www/html/cacti

        #useradd cacti

        #chown –R cacti /var/www/html/cacti

        #chmod  -R 775 /var/www/html/cacti

在数据库中配置cacti的访问权限:

     
     
     
     
  1. mysql> create database cacti;  
  2. mysql> grant all privileges on cacti.* to cacti@localhost identified by 'cacti' with grant option;  
  3. mysql> grant all privileges on cacti.* to [email protected] identified by 'cacti' with grant option;  
  4. mysql> use cacti;  
  5. mysql> source /var/www/html/cacti/cacti.sql;配置/var/www/html/cacti/include/config.php ,将username,password该一下       
  6. #service httpd restart    
 
         #setenforce 0 如果不关闭会出现很多问题,如访问不了,没有权限等
 游览器中输入以下内容: http://192.168.0.1/cacti 会出现安装界面,ip是该服务器的ip地址,直接单击next,一路下去直到输入账户admin密码admin ,这是默认账户密码,之后会重新改密码,自己随便设置个就行了。单击graphs,你可以看本机的监控图,注意一定要有耐心,总会出现的,这个成图很慢。

创建个计划任务:crontab –u cacti –e 加入下列内容:

  */5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

确保:/var/www/html/cacti/rra存在,如果没有看到图可以手动执行一下这个计划中的命令

   php /var/www/html/cacti/poller.php > /dev/null 2>&1
 

使用 Cacti 监控 Linux 主机
#在被监控的linux主机上安装net-snmp
                  yum install net-snmpvi
编辑 /etc/snmp/snmpd.conf文件:
将下边这行中的defaultcom2secnotConfigUser default public
   #改为192.168.0.3cacti)服务器的地址)com2secnotConfigUser 192.168.0.3 public
#将下边这行中的systemviewaccess notConfigGroup "" any noauth exact systemview none none
    #改为allaccess notConfigGroup "" any noauth exact all none none
#将下边这行的注释“#”号去掉#view all included .1 80service snmpd restart
9)如果出现问题请注意一下snmp协议的版本,都用version 1是一种解决方法如果都用version 1,需要把所有监控机和被监控机的snmpd.conf改一下
#vi /etc/snmp/snmpd.conf#将下边这行view systemview included .1.3.6.1.2.1.1
#改为view systemview included .1.3.6.1.2.1 在游览器输入服务端的http://ip/cacti 选择console--devices---add填入一下内容,这是要监控的客户端:

     
     
     
     
  1. # service mysqld restart 

 

选择default trees-----单击default trees---add 填入一下内容即可,然后选择graphs可以看着监控的主机的图

cacti 常用插件安装
      要安装别的插件前,先要安装cacti的一个patch--Plugin Architecture,才能支持插件 PA 2.8 = cacti 0.8.7g  
 
  
  
  
  
  1. # tar xvf cacti-plugin-0.8.7g-PA-v2.8.tar.gz  
  2. # cp -R cacti-plugin-arch/* /var/www/html/cacti/cd /var/www/html/cacti/  
  3. #mysql -ucacti -pcacti cacti <pa.sqlpatch -p1 -N <cacti-plugin-0.8.7g-PA-v2.8.diff 
编辑vi include/config.php 修改为$url_path = “/cacti/”;
  安装常用插件 Monitor,Settings,thold  
  
  
  
  
  1. # tar zxvf monitor-latest.tgz  
  2. # tar zxvf settings-latest.tgz  
  3. # tar zxvf thold-latest.tgz  
  4. # mv monitor-0.9/ /var/www/html/cacti/plugins/monitor# mv settings-0.6/ /var/www/html/cacti/plugins/settings  
  5. # mv thold-0.41/ /var/www/html/cacti/plugins/thold登陆安装启用对应的插件即可。   
     这里以monitor为例:选择user Management --- admin –plugin management(打上钩),也将monitor打上钩

常见故障排除 安装完毕在浏览器上无法看到数据的png图片。看apachelog  
    如果出现:     ========================   
  
  
  
  
  1. [Thu Feb 09 15:12:24 2006] [error] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico     
  2. ERROR: opening '/var/www/html/cacti/rra/localhost_mem_buffers_3.rrd': Permission denied  
 PS: 解决办法:关闭selinux,即可解决问题。
  PS :以上无法获取数据图大多和poller.phpcmd.php权限有关。
   当cacti 有图没有数据时,而且状态为nan的错误
PS :这个很可能是snmp的问题,执行以下命令,没有得到如图的结果。就说明snmp不支持64MIB库。重新编译安装snmp
 
  
  
  
  
  1. # snmpwalk -c public -v 2c 127.0.0.1  
  2.    IF-MIB::ifHCInOctetsIF-MIB::ifHCInOctets.1 = Counter64: 7437357IF-MIB::ifHCInOctets.2 =   Counter64: 353773IF-MIB::ifHCInOctets.3 = Counter64: 0 
         PS :被监控主机无法获得snmp信息,还有可能是对方主机snmp版本和当前主机的snmp版本不一致导致的。
PS rrdtools版本要一致,特别是在升级cacti时候。版本不一致,可能rra数据格式不同。就无法处理。
        排错思路:
1 、查看log下的日志文件。一般那里会有提示
2 、测试SNMP是不是工作正常 snmpwalk -v 2c -c public hostIP   if正常的话会出现一些数据。不正常会出现一些错误,也会有对应的错误提示。
3 、自动运行poller.php没有。有没有加入cacti的的用户。。有没有给cacti用户写入rra/ log/的权限。。
4 crontab –u cactiuser –e cactiuser加上自动运行poller.php的任务:
             */ 5     *       *       *       *       root    /usr/local/bin/php /usr/local/share/cacti/poller.php /dev/null 2>&1         5 分钟刷新一次数据。你也可以根据需要还设置。 5 。把cacti目录里的cmd.phppoller.php文件加下运行的权限。

脚本下载以及设置  
下载mysql-cacti-templates模板,用来检测mysql的状态:
  
  
  
  
  1. wget http://mysql-cacti-templates.googlecode.com/files/mysql-cacti-templates-1.1.2.tar.gz  
  2. tar -xzvf mysql-cacti-templates-1.1.2.tar.gz  
  3. cd mysql-cacti-templates-1.1.2  
  4. cp ss_get_mysql_stats.php /var/www/html/cacti/scripts 
在游览器中导入该模板文件:cacti_host_template_x_db_server_ht_0.8.6i.xml
修改ss_get_mysql_stats.php 文件
  
  
  
  
  1. $mysql_user = 'cacti';  
  2.       $mysql_pass = 'cacti';  
  3.       $cache_dir  = "var/www/html/cacti/cache/";  
  4. #mkdir /var/www/html/cacti/cacti/cache/  
  5. #chmod 777 -R /var/www/html/cacti/cache/  
       默认在获取的数据/tmp/下,会有cacti不能读取的情况。所以放在cacti目录来。  
二,创建监控Mysql需要的账户以及权限 配置MySQL服务器,让cacti所在机器能够访问MySQL服务器的状态信息,必须拥有”process”权限。如果要监控InnoDB状态,还必须有”SUPER”权限。
  
  
  
  
  1. mysql> grant process,super on *.* to 'cacti'@'%' identified by 'cacti';  
  2. mysql> grant all privileges on cacti.*  to cacti@"%" identified by "cacti"
  选择import templates cacti_host_template_x_db_server_ht_0.8.6i.xml导入之后,选择
devices-----mylinux( 或者localhost反正是监控的机器),可以看到如图中的 带有mysql的信息,选中所需就可以监控mysql

网卡流量的监控:

  
  
  
  
  1. 编辑:/etc/snmpd/snmpd.conf文件:  
  2. view systemview included .1.3.6.1.2.1.1  
  3.  
  4. view systemview included .1.3.6.1.2.1.25.1.1  
  5.  
  6. view systemview included .1.3.6.1.2.1.2  
  7.  说明:如果要监控流量的话,需要在监控端把标红的(第三行)内容加入snmpd.conf文件中 

之后,在host-templates设置如下图,Interface-Traffic(流量)、其他的是主机监控(测试过)

最后在devices中添加主机,在Graph Trees中设置,等个N分钟就会出现如下内容:

关于绘图:cmd.php是最低是5分钟采集一次数据的,效率比较低(没有测试);而spine最低可以降到每1分钟采集数据而且配置主机到显示图等的时间并不长:

 1、下载cacti-spine: 版本要好Cacti版本一致,
       下载地址: http://www.cacti.net/downloads/spine/patches/
 2、配置前要安装:net-snmp-devel、net-snmp-libs、net-snmp、net-snmp-utils,如果是编译安装的话在配置的时候使用--with-snmp=dir(net-snmp的路径)
 3、配置安装:
 
  
  
  
  
  1. #tar xvf cacti-spine-0.8.7e.tar.gz  
  2.  
  3. #cd cacti-spine-0.8.7e  
  4.  
  5. #./configure --prefix=/usr/local/spine --with-snmp=/usr --with-mysql=/usr/local/mysql/  
  6.  
  7. #make   
  8.  
  9. #make install  
  10. # ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock  
  11. 编辑spine.conf文件,将数据库名等信息填写对;测试是否能用:/usr/local/spine/bin/spine  
  12. 如果出现:SPINE: Poller[0] FATAL: Unable to read configuration file! (Spine init),数目你的spine.conf文件有问题,重新编译安装; 如果一直出现该问题是因为版本太低,把/usr/local/spine/etc/spine.conf 复制到/etc/spine.conf ,再次测试即可:看到有starting字符,就是成功 

可能出现的问题:我出现过这么个问题:Cannot find SNMP header files under yes 对这个问题一致很纳闷,net-snmp-devel也安装了,最后发现必须使用--with-snmp=/usr,如果不加路径的话,会一直出现该问题的。

4、配置spine,在cacti中settin,找到path路径把spine的路径填写对,在pooler选择spine。
5、最后,在可能出现的问题:我出现过这么个问题:Cannot find SNMP header files under yes 对这个问题一致很纳闷,net-snmp-devel也安装了,最后发现必须使用--with-snmp=/usr,如果不加路径的话,会一直出现该问题的。
4、配置spine,在cacti中settin,找到path路径把spine的路径填写对,在pooler选择spine。
5、最后,在 System Utilities找到Rebuild Poller Cache,重置一下就行了。
,重置一下就行了。

你可能感兴趣的:(文章,软件包,网卡流量,监控软件)