Flume的安装与使用

Apache Flume是一个分布式、可靠的数据采集系统,用于从不同数据源收集日志并转移到中央存储。本文介绍了Flume的安装、配置、Source、Channel、Sink等组件的详细使用,包括Netcat、Exec、Kafka、HDFS等,并展示了如何基于Nginx访问日志进行数据分析的作业案例。
摘要由CSDN通过智能技术生成

Apache Flume

一、概述

大数据需要解决的三个问题:采集、存储、计算

另外一个比较主流的大数据处理的技能栈ElasticSerach Stack: ElasticSearch(存储)、Kibana(计算结果的可视化展示)、Logstash(数据采集和简单处理)

**Apache Flume是一个分布式、可靠的、高可用的数据采集、聚合系统,将海量的日志数据从不同的数据源移动到一个中央的存储系统中。**用一句话总结:Flume不生产数据,它只是数据的搬运工
在这里插入图片描述

二、环境搭建

安装

[root@HadoopNode00 home]# mkdir flume
[root@HadoopNode00 home]# tar -zxf /root/apache-flume-1.7.0-bin.tar.gz -C /home/flume/
[root@HadoopNode00 home]# cd flume/
[root@HadoopNode00 flume]# ll apache-flume-1.7.0-bin/
total 148
drwxr-xr-x.  2 root root  4096 Sep 27 07:30 bin
-rw-r--r--.  1 root root 77387 Oct 11  2016 CHANGELOG
drwxr-xr-x.  2 root root  4096 Sep 27 07:30 conf
-rw-r--r--.  1 root root  6172 Sep 26  2016 DEVNOTES
-rw-r--r--.  1 root root  2873 Sep 26  2016 doap_Flume.rdf
drwxr-xr-x. 10 root root  4096 Oct 13  2016 docs
drwxr-xr-x.  2 root root  4096 Sep 27 07:30 lib
-rw-r--r--.  1 root root 27625 Oct 13  2016 LICENSE
-rw-r--r--.  1 root root   249 Sep 26  2016 NOTICE
-rw-r--r--.  1 root root  2520 Sep 26  2016 README.md
-rw-r--r--.  1 root root  1585 Oct 11  2016 RELEASE-NOTES
drwxr-xr-x.  2 root root  4096 Sep 27 07:30 tools

语法详解

在这里插入图片描述

# example.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

Simple Example

收集网络端口产生的访问数据,并且输出到服务的控制台窗口

准备配置文件
[root@HadoopNode00 flume]# cd apache-flume-1.7.0-bin/
[root@HadoopNode00 apache-flume-1.7.0-bin]# vi conf/simple.properties
[root@HadoopNode00 apache-flume-1.7.0-bin]# vi conf/simple.properties
# example.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = HadoopNode00
a1.sources.r1.port = 44444

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
启动Flume Agent服务实例
[root@HadoopNode00 apache-flume-1.7.0-bin]# bin/flume-ng agent --conf conf --conf-file conf/simple.properties --name a1 -Dflume.root.logger=INFO,console
测试
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>telnet HadoopNode00 44444
'telnet' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

在这里插入图片描述

三、Flume的Compent详细使用

Source

主要作用:读取/接受外部数据源参数的实时数据

Netcat
Exec

执行一个Unix操作系统的操作指令,将指令产生的结果作为source数据来源

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -f /home/flume/apache-flume-1.7.0-bin/Hello.log
测试追加数据
[root@HadoopNode00 apache-flume-1.7.0-bin]# echo Hello Hadoop2 >> Hello.log
Spooling Directory

收集某一个文件夹/目录中的文本文件数据集

注意:

  • 数据文件一旦采集完成,会自动重命名为*.completed
  • spooldir source不会采集后缀为*.completed的数据文件,只会采集非后缀的数据文件
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /home/flume/apache-flume-1.7.0-bin/data
Avro

类似于Netcat,收集某一个网络端口的访问数据,通常应用构建Flume集群
在这里插入图片描述

# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.bind = HadoopNode00
a1.sources.r1.port = 55555

通过专用客户端测试
[root@HadoopNode00 apache-flume-1.7.0-bin]# bin/flume-ng avro-client --host HadoopNode00 --port 55555 --filename README.md

Kafka

读取接受kafka消息队列中的数据,作为source的数据来源

tier1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
tier1.sources.source1.channels = channel1
# kafka集群的地址列表
tier1.sources.source1.kafka.bootstrap.servers = localhost:9092 
# kafka订阅的主题名
tier1.sources.source1.kafka.topics.regex = ^topic[0-9]$
# the default kafka.consumer.group.id=flume is used

Channel

事件(Event)队列的数据结构,负责采集数据的临时存储

Memory

临时存放到内存中

JDBC(不重要)

Events存储到一个持久化的数据库(Derby),目前不支持其它数据库产品

a1.channels = c1
a1.channels.c1.type = jdbc

Kafka

Events存储到Kafka集群,kafka是一个高可用和数据冗余备份功能的消息队列系统

a1.channels.channel1.type = org.apache.flume.channel.kafka.KafkaChannel
a1.channels.channel1.kafka.bootstrap.servers = kafka-1:9092,kafka-2:9092,kafka-3:9092
a1.channels.channel1.kafka.topic = channel1
a1.channels.channel1.kafka.consumer.group.id = flume-consumer

<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值