flume监听数据并上传到HDFS上

一准备数据

在/opt下创建datas文件夹,  /opt/datas是自定义指定的监听目录,启动flume之前是空文件夹。

启动成功后把之前准备好的两个测试文件复制到监听目录下。

[root@master tmp]# cp a1test /opt/datas
[root@master tmp]# cp tmp.txt /opt/datas
[root@master tmp]# cat a1test
慈母手中线,游子身上衣。
临行密密缝,意恐迟迟归。
谁言寸草心,报得三春晖。
[root@master tmp]# cat tmp.txt
我想吃饭
我想吃饭
[root@master tmp]# 

二启动Hadoop集群

进入/root/bigdata/hadoop2.7.3/sbin目录下

启动命令:start-all.sh

 三设置flume配置文件

进入flume的conf文件下创建agent01.conf文件 并进行编辑

# 配置拦截器
定义三大组件的名称
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1

# 配置source组件
agent1.sources.source1.type = spooldir
agent1.sources.source1.spoolDir = /opt/datas
agent1.sources.source1.fileHeader = false

# 配置拦
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过Flume的Spooling Directory Source来实现这个功能。Spooling Directory Source会监控一个指定的目录,当有新的文件被写入时,就会将文件内容作为事件传递给Flume的Channel。然后再通过Flume的Interceptor将文件中的逗号修改为竖杠,并存储到HDFS中。 具体的配置如下: 1. 在Flume的配置文件中添加一个Spooling Directory Source: ``` # define the Spooling Directory Source agent.sources = spoolDir agent.sources.spoolDir.type = spooldir agent.sources.spoolDir.spoolDir = /path/to/spool/directory agent.sources.spoolDir.fileHeader = true agent.sources.spoolDir.fileSuffix = .COMPLETED ``` 2. 添加一个Interceptor来修改文件内容 ``` # define the Interceptor to modify the file content agent.sources.spoolDir.interceptors = interceptor1 agent.sources.spoolDir.interceptors.interceptor1.type = regex_replace agent.sources.spoolDir.interceptors.interceptor1.regex = , agent.sources.spoolDir.interceptors.interceptor1.replaceString = | ``` 3. 添加一个HDFS Sink ``` # define the HDFS Sink agent.sinks = hdfsSink agent.sinks.hdfsSink.type = hdfs agent.sinks.hdfsSink.hdfs.path = /path/to/hdfs/directory agent.sinks.hdfsSink.hdfs.fileType = DataStream agent.sinks.hdfsSink.hdfs.rollInterval = 0 ``` 最后将Spooling Directory Source和HDFS Sink连接起来: ``` # connect the Source and Sink agent.sources.spoolDir.channels = memoryChannel agent.sinks.hdfsSink.channel = memoryChannel ``` 这样配置后,Flume就会监听指定的目录,当有新文件写入时,将文件内容作为事件传递给内存Channel。Interceptor会修改文件内容,然后将修改后的事件存储到HDFS中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值