实验内容
Source为syslogtcp,监听端口为6868,主机名为localhost,搭配Channel的file类型,Sink的类型为hdfs。
系统环境
Linux Ubuntu 14.04
jdk-7u75-linux-x64
hadoop-2.6.0-cdh5.4.5
flume-ng-1.5.0-cdh5.4.5
zookeeper-3.4.5-cdh5.4.5
实验步骤
1、创建Flume配置文件,名为:syslogtcp_file_hdfs.conf,使用vim编辑该conf文件,
cd /apps/flume/conf
cp ./flume-conf.properties.template ./syslogtcp_file_hdfs.conf
vim syslogtcp_file_hdfs.conf
插入如下内容:
#定义各个组件
agent1.sources = src
agent1.channels = ch
agent1.sinks = des
#配置source
agent1.sources.src.type = syslogtcp
agent1.sources.src.port = 6868
agent1.sources.src.host = localhost
#配置channel
agent1.channels.ch.type = file
agent1.channels.ch.checkpointDir = /data/flume/ckdir
agent1.channels.ch.dataDirs = /data/flume/datadir
#配置sink
agent1.sinks.des.type = hdfs
agent1.sinks.des.hdfs.path = hdfs://localhost:9000/myflume/syslogtcp_file_hdfs/%Y%m%d/
agent1.sinks.des.hdfs.useLocalTimeStamp = true
#设置flume临时文件的前缀为 . 或 _ 在hive加载时,会忽略此文件。
agent1.sinks.des.hdfs.inUsePrefix=_
#设置flume写入文件的前缀是什么
agent1.sinks.des.hdfs.filePrefix = abc
agent1.sinks.des.hdfs.fileType = DataStream
agent1.sinks.des.hdfs.writeFormat = Text
#hdfs创建多久会新建一个文件,0为不基于时间判断,单位为秒
agent1.sinks.des.hdfs.rollInterval = 30
#hdfs写入的文件达到多大时,创建新文件 0为不基于空间大小,单位B
agent1.sinks.des.hdfs.rollSize = 100000
#hdfs有多少条消息记录时,创建文件,0为不基于条数判断
agent1.sinks.des.hdfs.rollCount = 10000
#hdfs空闲多久就新建一个文件,单位秒
agent1.sinks.des.hdfs.idleTimeout = 30
##下面是把上面设置的组件关联起来(把点用线连起来)
agent1.sources.src.channels = ch
agent1.sinks.des.channel = ch
2、启动flume:
flume-ng agent -c /conf -f /apps/flume/conf/syslogtcp_file_hdfs.conf -n agent1 -D flume.root.logger=DEBUG,console
3、在另一个窗口,向6868端口发送命令:
echo "hello can you hear me?" | nc localhost 6868
Flume-ng的输出如下:
查看hdfs中的结果如下: