cacti

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

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,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
JavaScript 关系型数据库 MySQL
|
关系型数据库 PHP Ubuntu
|
关系型数据库 PHP Ubuntu
|
SQL 关系型数据库 PHP
|
Web App开发 监控 关系型数据库
|
Ubuntu 关系型数据库 PHP