Flume>采集案例(2)

1、采集目录到HDFS

需求分析
结构示意图:
在这里插入图片描述
采集需求:某服务器的某特定目录下,会不断产生新的文件,每当有新文件出现,就需要把文件采集到HDFS中去
根据需求,首先定义以下3大要素

  • 数据源组件,即source ——监控文件目录 : spooldir
    spooldir特性:
    1、监视一个目录,只要目录中出现新文件,就会采集文件中的内容
    2、采集完成的文件,会被agent自动添加一个后缀:COMPLETED
    3、所监视的目录中不允许重复出现相同文件名的文件
  • 下沉组件,即sink——HDFS文件系统 : hdfs sink
  • 通道组件,即channel——可用file channel 也可以用内存channel
    flume配置文件开发
    配置文件编写:
cd  /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf

mkdir -p /export/servers/dirfile

vim spooldir.conf
# Name the components on this agent
a1.sources=r1
a1.channels=c1
a1.sinks=k1
# Describe/configure the source
##注意:不能往监控目中重复丢同名文件
a1.sources.r1.type=spooldir
a1.sources.r1.spoolDir=/export/dir
a1.sources.r1.fileHeader = true
# Describe the sink
a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path=hdfs://node01:8020/spooldir/
# Describe the channel
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

bin/flume-ng agent -c ./conf -f ./conf/spooldir.conf -n a1 -Dflume.root.logger=INFO,console

上传文件到指定目录
将不同的文件上传到下面目录里面去,注意文件不能重名

cd /export/dir

具体代码

[root@node01 apache-flume-1.8.0-bin]# mkdir -p /export/install/dirfile
[root@node01 apache-flume-1.8.0-bin]# vi tmpconf/b1.conf
# Name the components on this agent
a1.sources=r1
a1.channels=c1
a1.sinks=k1
# Describe/configure the source
##注意:不能往监控目中重复丢同名文件
a1.sources.r1.type=spooldir
a1.sources.r1.spoolDir=/export/install/dirfile
a1.sources.r1.fileHeader = true
# Describe the sink
a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path=hdfs://node01:8020/spooldir/
# Describe the channel
a1.channels.c1.type=memory
a1.channels.c1.capacity=1000
a1.channels.c1.transactionCapacity
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flume是Apache下的一个分布式、可靠且高可用的海量日志采集、聚合和传输的系统。它可以将多个数据源的数据采集到Hadoop系统中进行处理和分析。 一个简单的Flume采集方案案例如下: 1. 配置Flume Agent 在Flume的conf目录中,新建一个配置文件flume.conf,并添加以下内容: ``` # Name the components on this agent agent.sources = source1 agent.sinks = sink1 agent.channels = channel1 # Describe/configure the source agent.sources.source1.type = netcat agent.sources.source1.bind = localhost agent.sources.source1.port = 44444 # Describe the sink agent.sinks.sink1.type = logger # Use a channel which buffers events in memory agent.channels.channel1.type = memory agent.channels.channel1.capacity = 1000 agent.channels.channel1.transactionCapacity = 100 # Bind the source and sink to the channel agent.sources.source1.channels = channel1 agent.sinks.sink1.channel = channel1 ``` 2. 启动Flume Agent 在Flume的bin目录中,执行以下命令启动Flume Agent: ``` ./flume-ng agent --conf-file ../conf/flume.conf --name agent -Dflume.root.logger=INFO,console ``` 3. 发送数据 在终端中,执行以下命令向Flume Agent发送数据: ``` nc localhost 44444 ``` 4. 查看结果 在终端中,可以看到Flume Agent接收到了数据,并将数据输出到日志中。 以上就是一个简单的Flume采集方案案例。通过配置Flume Agent,可以方便地采集多个数据源的数据,并将数据传输到Hadoop系统中进行处理和分析。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值