cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。
Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量
snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。关于RRDTool的知识请参阅RRDTool教学
- 安装环境 centos6 64bit
- 1搭建所需环境
- [root@localhost ~]# rpm -qa | grep zlib
- zlib-1.2.3-27.el6.x86_64
- zlib-devel-1.2.3-27.el6.x86_64
- [root@localhost ~]# rpm -qa | grep libpng
- libpng-static-1.2.46-1.el6_1.x86_64
- libpng-1.2.46-1.el6_1.x86_64
- libpng-devel-1.2.46-1.el6_1.x86_64
- [root@localhost ~]# rpm -qa | grep freetype
- freetype-demos-2.3.11-6.el6_1.8.x86_64
- freetype-devel-2.3.11-6.el6_1.8.x86_64
- freetype-2.3.11-6.el6_1.8.x86_64
- [root@localhost ~]# rpm -qa | grep jpeg
- libjpeg-6b-46.el6.x86_64
- [root@localhost ~]# rpm -qa | grep php
- php-mysql-5.3.3-3.el6_1.3.x86_64
- php-cli-5.3.3-3.el6_1.3.x86_64
- php-snmp-5.3.3-3.el6_1.3.x86_64
- php-gd-5.3.3-3.el6_1.3.x86_64
- php-common-5.3.3-3.el6_1.3.x86_64
- php-pdo-5.3.3-3.el6_1.3.x86_64
- php-5.3.3-3.el6_1.3.x86_64
- [root@localhost ~]# rpm -qa | grep perl
- perl-libs-5.10.1-119.el6_1.1.x86_64
- perl-DBI-1.609-4.el6.x86_64
- perl-Pod-Escapes-1.04-119.el6_1.1.x86_64
- perl-devel-5.10.1-119.el6_1.1.x86_64
- perl-Module-Pluggable-3.90-119.el6_1.1.x86_64
- perl-5.10.1-119.el6_1.1.x86_64
- perl-ExtUtils-MakeMaker-6.55-119.el6_1.1.x86_64
- perl-Pod-Simple-3.13-119.el6_1.1.x86_64
- net-snmp-perl-5.5-37.el6_2.1.x86_64
- perl-DBD-MySQL-4.013-3.el6.x86_64
- yum install tcl*
- [root@localhost ~]# rpm -qa | grep mysql
- php-mysql-5.3.3-3.el6_1.3.x86_64
- mysql-connector-odbc-5.1.5r1144-7.el6.x86_64
- mysql-connector-java-5.1.12-2.el6.x86_64
- mysql-libs-5.1.52-1.el6_0.1.x86_64
- mysql-server-5.1.52-1.el6_0.1.x86_64
- mysql-bench-5.1.52-1.el6_0.1.x86_64
- mysql-5.1.52-1.el6_0.1.x86_64
- mysql-devel-5.1.52-1.el6_0.1.x86_64
- mysql-embedded-5.1.52-1.el6_0.1.x86_64
- [root@localhost ~]# rpm -qa | grep net-snmp
- net-snmp-utils-5.5-37.el6_2.1.x86_64
- net-snmp-libs-5.5-37.el6_2.1.x86_64
- net-snmp-5.5-37.el6_2.1.x86_64
- net-snmp-perl-5.5-37.el6_2.1.x86_64
- net-snmp-devel-5.5-37.el6_2.1.x86_64
- 2安装rrdtool
- tar zxvf rrdtool-1.2.27.tar.gz
- cd rrdtool-1.2.27
- ./configure --prefix=/usr/local (关于这个指定路径的问题 一说是必须指定路径)
- make
- make install
- 3安装cacti
- tar zxvf cacti-0.8.7i.tar.gz
- mv cacti-0.8.7i /var/www/html/cacti
- 4 mysql>create database cacti default character set utf8;
- mysql>grant all privileges on cacti.* to cacti@localhost identified by '123456';
- mysql>flush privileges;
- 5vim /var/www/html/cacti/include/config.php
- $database_type = "mysql";
- $database_default = "cacti";
- $database_hostname = "localhost";
- $database_username = "cacti";
- $database_password = "123456";
- 5关闭selinux或者 setenforce 0
- 6 useradd cacti
- chown -R cacti.cacti /var/www/html/cacti
- chmod 777 -R /var/www/html/cacti
- 7 /etc/init.d/httpd start
- /etc/init.d/mysqld start
- /etc/init.d/iptables stop
- 8输入http://ip/cacti/ 进行安装以及路径的选择
- 问题1 CACTI不能显示图像,rra下没有文件!权限,PATH,snmpwalk没问题
- 把 Data Source Debug 的命令在cacti服务器端执行一次,就可以了
- 问题2 cacti图像不连续的解决方法
- 1 [root@localhost rra]# /usr/local/bin/rrdtool fetch localhost_mem_swap_4.rrd AVERAGE 用此命令检查 如果是nan说明没有采集到数据
- 1324534200: -nan
- 1324534500: -nan
- 1324534800: -nan
- 1324535100: -nan
- 1324535400: -nan
- 1324535700: -nan
- 1324536000: -nan
- 1324536300: -nan
- 1324536600: -nan
- 1324536900: -nan
- 2这个一般是网络问题或者是snmp有问题 解决办法就是
- 进入cacti管理界面执行 管理--图像管理---随便点击一个图片---然后打开图像调试模式--保存 然后就好了
- 问题3 cacti监控远程主机的配置
- 一 被监控端操作
- 1被监控端vim /etc/snmp/snmpd.conf的配置如下(确保配置文件有如下内容)
- com2sec notConfigUser 127.0.0.1 public
- com2sec notConfigUser 192.168.1.130(被监控的IP) public
- group notConfigGroup v1 notConfigUser
- group notConfigGroup v2c notConfigUser
- view systemview included .1.3.6.1.2.1.1
- view systemview included .1.3.6.1.2.1.2
- view systemview included .1.3.6.1.2.1.25.1.1
- view all included .1
- access notConfigGroup "" any noauth exact all none none
- com2sec notConfigUser default public
- com2sec *.*.*.0 192.168.1.130/24 public
- group MyRWGroup any local
- group MyROGroup any mynetwork
- group notConfigUser any zoom
- view all included .1 80
- view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
- access MyROGroup "" any noauth 0 all none none
- access MyRWGroup "" any noauth 0 all all all
- syslocation Unknown (edit /etc/snmp/snmpd.conf)
- syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
- dontLogTCPWrappersConnects yes
- 2重启snmp服务
- /etc/init.d/snmpd restart
- 3iptables关闭
- /etc/init.d/iptables stop
- 二 cacti监控端
- 1 snmpwalk -v 1 192.168.1.130 -c public 执行检测看到如下结果 表明配置成功
- HOST-RESOURCES-MIB::hrSWInstalledDate.858 = STRING: 2011-12-22,1:22:25.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.859 = STRING: 2011-12-22,1:18:49.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.860 = STRING: 2011-12-22,1:20:12.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.861 = STRING: 2011-12-22,1:22:25.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.862 = STRING: 2011-12-22,1:18:57.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.863 = STRING: 2011-12-22,1:20:24.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.864 = STRING: 2011-12-22,1:22:25.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.865 = STRING: 2011-12-22,1:19:3.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.866 = STRING: 2011-12-22,1:20:29.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.867 = STRING: 2011-12-22,1:22:26.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.868 = STRING: 2011-12-22,1:19:4.0,-8:0
- HOST-RESOURCES-MIB::hrSWInstalledDate.869 = STRING: 2011-12-22,1:20:30.0,-8:0
- DISMAN-EVENT-MIB::mteEventNotificationObjects."_snmpd".'_linkDown' = STRING: _linkUpDown
- DISMAN-EVENT-MIB::mteEventNotificationObjects."_snmpd".'_linkUp' = STRING: _linkUpDown
- DISMAN-EVENT-MIB::mteEventNotificationObjects."_snmpd".'_mteTriggerFailure' = STRING: _triggerFail
- DISMAN-EVENT-MIB::mteEventNotificationObjects."_snmpd".'_mteTriggerFalling' = STRING: _triggerFire
- DISMAN-EVENT-MIB::mteEventNotificationObjects."_snmpd".'_mteTriggerFired' = STRING: _triggerFire
- DISMAN-EVENT-MIB::mteEventNotificationObjects."_snmpd".'_mteTriggerRising' = STRING: _triggerFire
- NOTIFICATION-LOG-MIB::nlmConfigGlobalEntryLimit.0 = Gauge32: 1000
- NOTIFICATION-LOG-MIB::nlmConfigGlobalAgeOut.0 = Gauge32: 1440 minutes
- NOTIFICATION-LOG-MIB::nlmStatsGlobalNotificationsLogged.0 = Counter32: 0 notifications
- NOTIFICATION-LOG-MIB::nlmStatsGlobalNotificationsBumped.0 = Counter32: 0 notifications
- 2cacti控制端监控查看
- 问题4 监控设备处于unknow状态
- acti新添加的主机能手动获取snmp信息,但cacti里面一直是unknown,本机没有问题,就是新增加的主机出不了图。
- 故障排除:
- 操作流程:
- 1 进入控制台-系统工具-重建绘图器缓存
- 2 在cacti服务器上运行
- /usr/bin/php /var/www/html/poller.php
- 数分钟后,假如还是不行,重复上述操作一次,即可!
转载于:https://blog.51cto.com/liveforlinux/801200