1、推荐参考博客地址:http://blog.csdn.net/xiao_jun_0820/article/category/2399621
放在flume根目录conf文件夹下的代理配置文件写法:
a1.sources = r1
a1.sinks = k1
a1.channels = c1
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path=hdfs://localhost:9000/user/hadoop/flume
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.writeFormat=Text
a1.sinks.k1.hdfs.rollInterval=0
a1.sinks.k1.hdfs.rollSize=10240
a1.sinks.k1.hdfs.rollCount=0
a1.sinks.k1.hdfs.idleTimeout=60
# 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
先进到hadoop的根目录下启动HDFS (命令./sbin/start-dfs.sh)
然后开启终端启动上面的代理文件,开启另一个终端测试端口连接。
可以参考本博此文:http://my.oschina.net/u/2478308/blog/731838
写入成功后会在终端中显示例如FlumeData.1470365774656.tmp的文件,该文件会根据设置的时间去除.tmp后缀。
事项:
1、HDFS的写入路径为 hdfs://namenodepath:namenodeport/自定义用户目录/自定义数据存储目录。对应目录需要提前创建,代理启动写入时不会自己创建目录。
2、需要切换到有hdfs写入权限的用户。
3、dfs.fileType=DataStream hdfs.writeFormat=Text 使生成的文件可以读取。
4、flume写入hdfs后可以通过例如./bin/hdfs dfs -cat flume/FlumeData.1470365774656,查看hdfs中的文件内容。
5、可以连接http://localhost:50070中Utilities查看相关目录下的写入HDFS的文件。