flume-ng 使用spool source 传输文件到hdfs

 

Flume 1.4.0 User Guide 地址:http://archive.cloudera.com/cdh4/cdh/4/flume-ng-1.4.0-cdh4.6.0/FlumeUserGuide.html

本文档主要用来记录如何在日志服务器和hdfs服务器端利用flume-ng将已经写好的日志传输到hdfs。

一 安装与环境配置

   下载地址  http://archive.cloudera.com/cdh4/cdh/4/flume-ng-latest.tar.gz ,使用chd4版本。

   解压到服务器目录。

   配置JAVA_HOME和PATH (具体路径参考实际情况)

   declare -x JAVA_HOME="/usr/java/default"

   export PATH=$JAVA_HOME:$PATH

   export PATH=/home/dongxiao.yang/apache-flume-1.4.0-cdh4.6.0-bin/bin:$PATH 

 

二   程序参数配置

 flume-ng的程序参数主要通过修改各种配置文件实现。 (具体路径参考实际情况)

 1 flume-ng默认程序最大内存为20m,打开解压文件路径下的/home/dongxiao.yang/apache-flume-1.4.0-cdh4.6.0-bin/conf/flume-env.sh.template文件

修改如下一行

#JAVA_OPTS="-Xms100m -Xmx200m -Dcom.sun.management.jmxremote"

改为

JAVA_OPTS="-Xms64m -Xmx300m -Dcom.sun.management.jmxremote"

将flume-env.sh.template重命名为flume-env.sh使配置生效。

2 配置source channel sink。

服务器端的配置文件conf.properties

日志服务器端的配置文件conf.properties
#define agent1
agent1.sources = source1
agent1.channels = channel1
agent1.sinks = sink1
#Describe the source
agent1.sources.source1.type = spooldir
# source 读取源日志的路径
agent1.sources.source1.spoolDir = /home/dongxiao.yang/flumespool 
#agent1.sources.source1.fileHeader =true
 
#Describe the sink
#agent1.sinks.sink1.type = logger
agent1.sinks.sink1.type = avro
#avro sink 发送数据的地址和端口
agent1.sinks.sink1.hostname= 218.241.157.74
agent1.sinks.sink1.port = 10000
# avro 数据发送前会进行压缩,共有19个级别的压缩
agent1.sinks.sink1.compression-type = deflate
 
#Describe the channel
agent1.channels.channel1.type = file
#file channle checkpoint文件的路径
agent1.channels.channel1.checkpointDir = /home/dongxiao.yang/checkpoint
# file channel data文件的路径
agent1.channels.channel1.dataDirs = /home/dongxiao.yang/data
# file channel 每次传输事件的个数
agent1.channels.channel1.transactionCapacity = 10000
#file channel 最多储存事件的个数
agent1.channels.channel1.capacity= 10000000
 
 
#Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1
hdfs端的conf.properties
#define
agent1.sources = source1
agent1.channels = channel1
agent1.sinks = sink1
 
#Describe the source
agent1.sources.source1.type = avro
# avro source 监听的地址和端口
agent1.sources.source1.bind = 0.0.0.0
agent1.sources.source1.port = 10000
# avro source 读取的数据是压缩过的,类型必须与 前一个 avro sink相同
agent1.sources.source1.compression-type =deflate
 
#Describe the sink
agent1.sinks.sink1.type = hdfs
# 写入hdfs的路径
agent1.sinks.sink1.hdfs.path = /tmp/flume
# 文件前缀
agent1.sinks.sink1.hdfs.filePrefix = test
agent1.sinks.sink1.hdfs.rollCount = 0
agent1.sinks.sink1.hdfs.rollInterval=0
agent1.sinks.sink1.hdfs.rollSize=0
agent1.sinks.sink1.hdfs.batchSize=5000
#文件在完全没有流写入后60s关闭
agent1.sinks.sink1.hdfs.idleTimeout=60
#数据写入hdfs时进行压缩
agent1.sinks.sink1.hdfs.fileType = CompressedStream 
#数据写入hdfs时压缩的种类
agent1.sinks.sink1.hdfs.codeC = gzip
 
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 100000
agent1.channels.channel1.transactionCapacity = 5000
 
#Bind the source and sink to the channel
agent1.sources.source1.channels = channel1

 

 

三 启动程序

运行程序位于解压文件/bin目录下。运行前需要先为flume-ng赋予可执行权限:chmod 777 flume-ng。

在bin目录下运行命令 ,程序即可执行。


flume-ng agent --conf /home/dongxiao.yang/apache-flume-1.4.0-cdh4.6.0-bin/conf --conf-file /home/dongxiao.yang/apache-flume-1.4.0-cdh4.6.0-bin/conf/conf.properties

--name agent1 -Dflume.root.logger=INFO,DAILY -Duser.timezone=UTC+8

 

其中 --conf 对应的是配置文件目录 

     --conf-file 对应配置文件

     --name 对应配置文件内的angent的名字

     -D对应日志以及运行时区

 

posted @ 2014-06-03 14:11  sanmutongzi  阅读(1654)  评论(0编辑  收藏  举报