开发者社区> 技术小阿哥> 正文

cacti

简介:
+关注继续查看

Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具

Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,功能非常强大完善。界面友好。

CACTI

CACTI

软件 Cacti 的发展是基于让 RRDTool 使用者更方便使用该软件,除了基本的 Snmp 流量跟系统资讯监控外,Cacti 也可外挂 Scripts 及加上 Templates 来作出各式各样的监控图。

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),它能够存储的数据笔数在创建时就已经定义。


实验环境

centos 5.5


实验软件

cacti-0.8.8a.tar.gz

cacti-spine-0.8.8a.tar.gz

rrdtool-1.3.8.tar.gz


软件安装

yum install httpd* mysql* php php-mysql* mod_ssl mod_mod_auth_mysql mod_auth_mysql mod_perl php-gd php-xml xml php-mbstring php-ldap php-pear php-xmlrpc -y

yum install mysql-connector-odbc mysql-devel libdbi-dbd-mysql -y

yum install net-snmp* pango-devel* cairo-devel* intltool -y

yum install zlib libpng freetype libart_lgpl libart_lgpl-devel libxml* pango*  -y


service httpd restart

service mysqld restart

service snmpd restart

chkconfig --level 35 httpd on  

chkconfig --level 35 snmpd on  

chkconfig --level 35 mysqld on

setenforce 0  


vim /etc/httpd/conf/httpd.conf

#ServerName www.example.com:80  找到

ServerName           *:80  改为

 

#AddType application/x-tar .tgz 找到

#AddType application/x-tar .tgz


AddType application/x-tar .tgz  改为

AddType application/x-httpd-php .php


http://服务器ip 

wKiom1nfiyHArQIJAAFuDfVq42Q089.jpg-wh_50


touch /var/www/html/test.php

vim /var/www/html/test.php 

<?php

phpinfo();

?>


http://服务器ip/test.php


wKiom1nfi6ORP8U6AAFFA2PazDg957.jpg-wh_50


netstat -tuplna | grep httpd

tcp        0      0 :::80                       :::*                        LISTEN      16796/httpd         

tcp        0      0 :::443                      :::*                        LISTEN      16796/httpd   

      

netstat -tuplna | grep mysqld

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17003/mysqld


ps -aux | grep httpd

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root     16796  0.0  1.3 313176 13284 ?        Ss   22:58   0:00 /usr/sbin/httpd

apache   16798  0.0  0.6 313176  6924 ?        S    22:58   0:00 /usr/sbin/httpd

apache   16799  0.0  0.6 313176  6924 ?        S    22:58   0:00 /usr/sbin/httpd


ps -aux | grep mysqld

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root     16901  0.0  0.1 108188  1596 pts/3    S    22:58   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql

mysql    17003  0.0  3.1 367516 32380 pts/3    Sl   22:58   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

root     27873  0.0  0.0 103324   888 pts/5    S+   23:19   0:00 grep mysqld



mysqladmin -uroot password 数据库密码

mysql -uroot -p数据库密码

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> create database cacti;  创建数据库

mysql> grant all privileges on  cacti.*to  cacti@localhost identified by 'cacti'; 授权用户保留root最高权限

mysql> select host,user from mysql.user; 查看用户以及权限

+-----------+-------+

| host      | user  |

+-----------+-------+

| 127.0.0.1 | root  |

| centos6   |       |

| centos6   | root  |

| localhost |       |

localhost | cacti |

| localhost | root  |

+-----------+-------+

6 rows in set (0.00 sec)

mysql> flush privileges; 刷新权限


mysql -ucacti -pcacti   查看授权用户是否可以登入数据库

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| cacti              |

| test               |

+--------------------+

3 rows in set (0.00 sec)


tar zxvf cacti-0.8.8a.tar.gz 

mv cacti-0.8.8a /var/www/html/cacti


tar zxvf rrdtool-1.3.8.tar.gz 

cd rrdtool-1.3.8

./configure --prefix=/usr/local/rrdtool

make && make install


tar zxvf cacti-spine-0.8.8a.tar.gz 

cd cacti-spine-0.8.8a

./configure  --prefix=/usr/local/spine

make && make install


mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql 导入sql文件

mysql -ucacti -pcacti 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases; 

+--------------------+

| Database           |

+--------------------+

| information_schema |

| cacti              |

| test               |

+--------------------+

3 rows in set (0.00 sec)


mysql> use cacti; 

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;

+---------------------------+

| Tables_in_cacti           |

+---------------------------+

| cdef                      |

| cdef_items                |

| colors                    |

| data_input                |

| data_input_data           |

| data_input_fields         |

| data_local                |

| data_template             |

| data_template_data        |

| data_template_data_rra    |

| data_template_rrd         |

| graph_local               |

| graph_template_input      |

| graph_template_input_defs |

| graph_templates           |

| graph_templates_gprint    |

| graph_templates_graph     |

| graph_templates_item      |

| graph_tree                |

| graph_tree_items          |

| host                      |

| host_graph                |

| host_snmp_cache           |

| host_snmp_query           |

| host_template             |

| host_template_graph       |

| host_template_snmp_query  |

| plugin_config             |

| plugin_db_changes         |

| plugin_hooks              |

| plugin_realms             |

| poller                    |

| poller_command            |

| poller_item               |

| poller_output             |

| poller_reindex            |

| poller_time               |

| rra                       |

| rra_cf                    |

| settings                  |

| settings_graphs           |

| settings_tree             |

| snmp_query                |

| snmp_query_graph          |

| snmp_query_graph_rrd      |

| snmp_query_graph_rrd_sv   |

| snmp_query_graph_sv       |

| user_auth                 |

| user_auth_perms           |

| user_auth_realm           |

| user_log                  |

| version                   |

+---------------------------+

52 rows in set (0.00 sec)

mysql> 


vim /var/www/html/cacti/include/config.php 

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cacti";  授权用户

$database_password = "cacti";  授权用户密码

$database_port = "3306";

$database_ssl = false;


vim /var/www/html/cacti/include/global.php 

/* Default database settings*/

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cacti"; 授权用户

$database_password = "cacti"; 授权用户密码

$database_port = "3306";

$database_ssl = false;


vim /etc/crontab                       

*/5 * * * * root php /var/www/html/cacti/poller.php


cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf

vim /etc/spine.conf

DB_Host       localhost

DB_Database    cacti 

DB_User       cacti 授权用户

DB_Pass       cacti 授权用户密码

DB_Port       3306

DB_PreG       0


http://服务器ip/cacti


163959950.png


164114646.png


164349166.png

find /usr/local/ -name rrdtool

/usr/local/rrdtool-1.3.8/bin/rrdtool 复制路径刷新即可


164527663.png

默认用户名  admin  admin


164644348.png

修改密码 给为 新的密码


164809181.png

cacti搭建完毕

cacti搭建完成,为了能更好使用需要修改snmp配置文件

vim  /etc/snmp/snmpd.conf

找到

com2sec notConfigUser  default       public

更改为

com2sec notConfigUser  all           public  

找到

access  notConfigGroup ""      any       noauth    exact  systemview none none

更改为

access  notConfigGroup ""      any       noauth    exact  all none none

找到

#view all    included  .1                               80

更改为

view all    included  .1                               80

找到

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc

改为

view mib2   included  .iso.org.dod.internet.mgmt.mib-2  fc


/etc/rc.d/init.d/crond restart

Stopping crond: [  OK  ]

Starting crond: [  OK  ]


vim /etc/php.ini

找到 ;date.timezone =

改为 date.timezone = Asia/shanghai



测试rrdtool,是否生成图片的命令

php /var/www/html/cacti/poller.php

05/23/2013 10:39:23 PM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval!  The Poller Interval is '60' seconds, with a maximum of a '300' second Cron, but 262 seconds have passed since the last poll!

OK u:0.00 s:0.01 r:7.62

OK u:0.00 s:0.01 r:7.62

OK u:0.00 s:0.01 r:10.25

05/23/2013 10:39:34 PM - SYSTEM STATS: Time:10.9177 Method:spine Processes:1 Threads:1 Hosts:17 HostsPerProcess:17 DataSources:20 RRDsProcessed:10

OK u:0.00 s:0.01 r:10.82

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.84

OK u:0.00 s:0.01 r:10.84

看到这个提示,证明rrdtool已经获得了数据


检查snmp获得数据是否正常可以使用

snmpwalk -v 2c -c public 127.0.0.1 if

IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifIndex.3 = INTEGER: 3
IF-MIB::ifIndex.4 = INTEGER: 4
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifDescr.3 = STRING: eth1
IF-MIB::ifDescr.4 = STRING: sit0
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.3 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.4 = INTEGER: tunnel(131)
IF-MIB::ifMtu.1 = INTEGER: 16436
IF-MIB::ifMtu.2 = INTEGER: 1500
IF-MIB::ifMtu.3 = INTEGER: 1500
IF-MIB::ifMtu.4 = INTEGER: 1480
IF-MIB::ifSpeed.1 = Gauge32: 10000000
IF-MIB::ifSpeed.2 = Gauge32: 1000000000
IF-MIB::ifSpeed.3 = Gauge32: 1000000000
IF-MIB::ifSpeed.4 = Gauge32: 0
IF-MIB::ifPhysAddress.1 = STRING: 
IF-MIB::ifPhysAddress.2 = STRING: 0:50:56:b2:dd:6a
IF-MIB::ifPhysAddress.3 = STRING: 0:50:56:b2:4a:bf
IF-MIB::ifPhysAddress.4 = STRING: 
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
IF-MIB::ifAdminStatus.2 = INTEGER: up(1)
IF-MIB::ifAdminStatus.3 = INTEGER: down(2)
IF-MIB::ifAdminStatus.4 = INTEGER: down(2)
IF-MIB::ifOperStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: up(1)
IF-MIB::ifOperStatus.3 = INTEGER: down(2)
IF-MIB::ifOperStatus.4 = INTEGER: down(2)
IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.2 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.3 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.4 = Timeticks: (0) 0:00:00.00
IF-MIB::ifInOctets.1 = Counter32: 456696
IF-MIB::ifInOctets.2 = Counter32: 13011691
IF-MIB::ifInOctets.3 = Counter32: 0
IF-MIB::ifInOctets.4 = Counter32: 0
IF-MIB::ifInUcastPkts.1 = Counter32: 3736
IF-MIB::ifInUcastPkts.2 = Counter32: 82264
IF-MIB::ifInUcastPkts.3 = Counter32: 0
IF-MIB::ifInUcastPkts.4 = Counter32: 0
IF-MIB::ifInNUcastPkts.1 = Counter32: 0
IF-MIB::ifInNUcastPkts.2 = Counter32: 0
IF-MIB::ifInNUcastPkts.3 = Counter32: 0
IF-MIB::ifInNUcastPkts.4 = Counter32: 0
IF-MIB::ifInDiscards.1 = Counter32: 0
IF-MIB::ifInDiscards.2 = Counter32: 0
IF-MIB::ifInDiscards.3 = Counter32: 0
IF-MIB::ifInDiscards.4 = Counter32: 0
IF-MIB::ifInErrors.1 = Counter32: 0
IF-MIB::ifInErrors.2 = Counter32: 119
IF-MIB::ifInErrors.3 = Counter32: 0
IF-MIB::ifInErrors.4 = Counter32: 0
IF-MIB::ifInUnknownProtos.1 = Counter32: 0
IF-MIB::ifInUnknownProtos.2 = Counter32: 0
IF-MIB::ifInUnknownProtos.3 = Counter32: 0
IF-MIB::ifInUnknownProtos.4 = Counter32: 0
IF-MIB::ifOutOctets.1 = Counter32: 456696
IF-MIB::ifOutOctets.2 = Counter32: 38508110
IF-MIB::ifOutOctets.3 = Counter32: 0
IF-MIB::ifOutOctets.4 = Counter32: 0
IF-MIB::ifOutUcastPkts.1 = Counter32: 3736
IF-MIB::ifOutUcastPkts.2 = Counter32: 70719
IF-MIB::ifOutUcastPkts.3 = Counter32: 0
IF-MIB::ifOutUcastPkts.4 = Counter32: 0
IF-MIB::ifOutNUcastPkts.1 = Counter32: 0
IF-MIB::ifOutNUcastPkts.2 = Counter32: 0
IF-MIB::ifOutNUcastPkts.3 = Counter32: 0
IF-MIB::ifOutNUcastPkts.4 = Counter32: 0
IF-MIB::ifOutDiscards.1 = Counter32: 0
IF-MIB::ifOutDiscards.2 = Counter32: 0
IF-MIB::ifOutDiscards.3 = Counter32: 0
IF-MIB::ifOutDiscards.4 = Counter32: 0
IF-MIB::ifOutErrors.1 = Counter32: 0
IF-MIB::ifOutErrors.2 = Counter32: 0
IF-MIB::ifOutErrors.3 = Counter32: 0
IF-MIB::ifOutErrors.4 = Counter32: 0
IF-MIB::ifOutQLen.1 = Gauge32: 0
IF-MIB::ifOutQLen.2 = Gauge32: 0
IF-MIB::ifOutQLen.3 = Gauge32: 0
IF-MIB::ifOutQLen.4 = Gauge32: 0
IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.2 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.3 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.4 = OID: SNMPv2-SMI::zeroDotZero

如果出现这一些,证明snmp可以正常抓取数据



120148262.png



如果出现这个,证明cacti正常工作



配置客户端,客户端以windows xp为例

1 控制面板-添加删除程序-添加删除windows组件-管理与监视工具-snmp有两个选项,全部勾线安装

2 cmd-services.msc

3 找到snmp服务

101956333.png

右键-属性

101956361.png




101956383.png

团体名字默认为public(可以更改),但是要和服务器端名字相同

接收来自snmp包的ip地址为服务器端ip地址,点击应用-确定

重启客户端snmp服务

102339334.png

右键-重启服务


102505945.png

这样windows xp客户端配置就完成了


介绍如何,配置客户端,客户端以linux(centos) 为例

yum -y install net-snmp

vim  /etc/snmp/snmpd.conf

找到

com2sec notConfigUser  default       public

更改为

com2sec notConfigUser  cacti服务端ip          public  

找到

access  notConfigGroup ""      any       noauth    exact  systemview none none

更改为

access  notConfigGroup ""      any       noauth    exact  all none none

找到

#view all    included  .1                               80

更改为

view all    included  .1                               80

找到

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc

改为

view mib2   included  .iso.org.dod.internet.mgmt.mib-2  fc


/etc/rc.d/init.d/crond restart

Stopping crond: [  OK  ]

Starting crond: [  OK  ]

如果监控Linux客户端出现snmp检测不到网卡,处理方法是,添加主机选择 ccd/netSNMPHost 这个模版




本文转自 mailfile 51CTO博客,原文链接:http://blog.51cto.com/mailfile/1199311,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
阿里云服务器ECS登录用户名是什么?系统不同默认账号也不同
阿里云服务器Windows系统默认用户名administrator,Linux镜像服务器用户名root
15287 0
如何设置阿里云服务器安全组?阿里云安全组规则详细解说
阿里云安全组设置详细图文教程(收藏起来) 阿里云服务器安全组设置规则分享,阿里云服务器安全组如何放行端口设置教程。阿里云会要求客户设置安全组,如果不设置,阿里云会指定默认的安全组。那么,这个安全组是什么呢?顾名思义,就是为了服务器安全设置的。安全组其实就是一个虚拟的防火墙,可以让用户从端口、IP的维度来筛选对应服务器的访问者,从而形成一个云上的安全域。
18580 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
27723 0
阿里云服务器安全组设置内网互通的方法
虽然0.0.0.0/0使用非常方便,但是发现很多同学使用它来做内网互通,这是有安全风险的,实例有可能会在经典网络被内网IP访问到。下面介绍一下四种安全的内网互联设置方法。 购买前请先:领取阿里云幸运券,有很多优惠,可到下文中领取。
21933 0
使用OpenApi弹性释放和设置云服务器ECS释放
云服务器ECS的一个重要特性就是按需创建资源。您可以在业务高峰期按需弹性的自定义规则进行资源创建,在完成业务计算的时候释放资源。本篇将提供几个Tips帮助您更加容易和自动化的完成云服务器的释放和弹性设置。
20879 0
阿里云ECS云服务器初始化设置教程方法
阿里云ECS云服务器初始化是指将云服务器系统恢复到最初状态的过程,阿里云的服务器初始化是通过更换系统盘来实现的,是免费的,阿里云百科网分享服务器初始化教程: 服务器初始化教程方法 本文的服务器初始化是指将ECS云服务器系统恢复到最初状态,服务器中的数据也会被清空,所以初始化之前一定要先备份好。
16589 0
13690
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
JS零基础入门教程(上册)
立即下载
性能优化方法论
立即下载
手把手学习日志服务SLS,云启实验室实战指南
立即下载