作业二

来源:互联网 发布:js radiobutton 编辑:程序博客网 时间:2024/05/18 02:19

Cacti是一套基于PHP、MySQL、SNMP及RRDTool开发的网络流量监测图形分析工具。它通过snmpget来获取数据,使用 RRDtool绘画图形,它的界面非常漂亮,能让你根本无需明白rrdtool的参数能轻易的绘出漂亮的图形。而且你完全可以不需要了解RRDtool复杂的参数。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结 构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,让你添加自己的snmp_query和script。

cacti 的工作原理,如下图


  • 1,snmp协议收集远程服务器的数据

  • 2,将snmp收集的数据内容保存到rrd数据库中

  • 3,若用户查看某台设备上的流量或其它状态信息

  • 4,在mysql数据库中查找该设备对应的rra数据库文件的名称

  • 5,通过rrdtool命令进行绘图即可

cacti要在LNMP,或者LAMP的环境现使用,所以先得安装LAMP或LNMP环境。

除了LNMP外 还得安装下面两个程序

安装net-snmp

 
yum install -y net-snmp net-snmp-utils

修改配置文件,

vim /etc/snmp/snmpd.conf
修改前,
view systemview included .1.3.6.1.2.1.1
修改后,
view systemview included .1.3.6.1.2.1

测试

service snmpd start
snmpnetstat -v 2c -c public -Ca -Cp tcp localhost
Active Internet (tcp) Connections (including servers)
Proto Local Address     Remote Address     (state)
tcp  *.ssh         *.*          LISTEN
tcp  *.mysql        *.*          LISTEN
tcp  localhost.smtp     *.*          LISTEN
tcp  localhost.smux     *.*          LISTEN
tcp  localhost.x11-ssh-   *.*          LISTEN
tcp  192.168.18.201.ssh   192.168.18.138.61353 ESTABLISHED

安装RRDTool

yum install -y rrdtool

测试

rrdtool -v
RRDtool 1.3.8 Copyright 1997-2009 by Tobias Oetiker <tobi@oetiker.ch>
        Compiled Aug 21 2010 10:57:18
Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv, dump, restore,
    last, lastupdate, first, info, fetch, tune,
    resize, xport
RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)
For more information read the RRD manpages
接下来安装Cacti,可在官网下载 ’wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz ‘

因为Cacti是一个PHP程序,是基于Apache或者Nginx的网页 ,所以要先为它配置虚拟主机

vim /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
  DocumentRoot /web/vhosts/cacti
  ServerName cacti.test.com
  ErrorLog logs/cacti.test.com-error_log
  CustomLog logs/cacti.test.com-access_log common
  <Directory "/web/vhosts/cacti">
    Options Indexes FollowSymLinks
    DirectoryIndex index.php index.html index.htm
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
建立Cacti文档目录

 mkdir -pv /web/vhosts/cacti

并将下载的压缩包解压的这个目录下面

配置cacti的数据库

mysqladmin create cactidb
mysql cactidb < cacti.sql
给cacti访问数据库的授权用户

mysql -e "GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'"
mysqladmin flush-privileges
mysql -ucactiuser -pcactiuser
修改cacti的配置文件

vim /web/vhosts/cacti/include/config.php

$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;
$url_path ="/"
接下来我们要创建一个cacti用户并修改相应目录权限

useradd cactiuser
chown -R cactiuser:cactiuser log/ rra/
重启并初始化httpd与cacti即可

我们可通过访问本机IP来访问cacti主页面

将cacti的页面初始化(主要为检查配置,登录)完成后我们在左上角会出现红颜色的“console”控制台标签,另一个是蓝色的“graphs”图像标签

graphs为查看图像的选项

console大致分为七个大项和多个项目,下面我们来罗列一下

(1).Create 创建

  • New Graphs 添加新图形

(2).Management 管理

  • Graph Management 图形管理。可以在此删除、复制图像,Cacti会自动创建图像。不过如果我们有特殊的需要,比如将几张图上的数据合并在一张图像上的话也可以在此手工新建图像;

  • Graph Trees 图形树。在graphs界面里,图像或devices是树状结构显示的,可以在此设置树的结构;

  • Data Sources 数据源。记要用来管理rrd文件的,一般无需修改,Cacti会自己创建rrd文件;

  • Devices 设备管理。这是我们最经常需要修改的地方,可以在此创建新的设备或修改其名称等信息。

(3).Collection Methods 数据收集方法一般我们无需对这两项进行修改。(非常重要在下面的内容中进行详解

  • Data Queries 数据查询,

  • Data Input Methods 数据输入方法

(4).Templates 模板,这些模板可以导出、导入也可以自己编写,一般无需修改。

  • Graph Templates 图形模板

  • Host Templates 主机模板

  • Data Templates 数据模板

(5).Import/Export 导入/导出,对上述模板的导入、导出。我们可以在Cacti的官方网站上找到这些模板,不过需要注意模板对于的Cacti的版本。

  • Import Templates 导入模板

  • Export Templates 导出模板

(6).Configuration 配置

  • Settings 系统设置,Cacti的主要配置菜单;可以在此重新设置对应的程序的路径、版本等信息。也可以设置图像的输出方式(允许ftp)、显示效果、登陆方式(允许使用LDAP)等。

  • Plugin Management 插件管理

(7).Utilities 工具

  • System Utilities 系统工具,显示Cacti系统的一些cache和log信息,如果log文件太大建议直接到后台查看;

  • User Management 用户管理,可以在此添加、删除用户,并对每个用户设置详细的权限;

  • Logout User 用户退出


原创粉丝点击