flume搭建

jdk配置
/etc/profile 修改环境变量

export JAVA_HOME=/usr/java/jdk1.8.0_77
export HADOOP_HOME=/lj/hadoop-2.2.0
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin

source /etc/profile

解压
tar -zxvf apache-flume-1.5.0-bin.tar.gz -C 路径

/lj/apache-flume-1.5.0-bin/conf
重命名 mv flume-env.sh.template flume-env.sh
flume-env.sh下配置
JAVA_HOME=/usr/java/jdk1.8.0_77

需要hadoop包,使用scp将
/lj/hadoop-2.2.0/share/hadoop/common/hadoop-common-2.2.0.jar
/lj/hadoop-2.2.0/share/hadoop/common/lib/commons-configuration-1.6.jar、hadoop-auth-2.2.0.jar、htrace-core-3.0.4.jar
/letv/data/hadoop-2.6.0/share/hadoop/hdfs/hadoop-hdfs-2.6.0.jar
拷贝到/lj/apache-flume-1.5.0-bin/lib下

将/lj/hadoop-2.2.0/etc/hadoop/{core-site.xml,hdfs-site.xml} 拷贝到/lj/apache-flume-1.5.0-bin/conf下

vim /etc/hosts

10.185.28.92 THadoop1
10.185.28.94 THadoop2
10.185.28.95 THadoop3
10.185.28.23 THadoop4
10.185.28.58 THadoop5
10.185.28.16 THadoop6
10.185.28.26 THadoop7
10.185.28.50 THadoop8

然后创建要监听的目录mkdir /root/logs

启动
bin/flume-ng agent -n a4 -c conf -f conf/a4.conf -Dflume.root.logger=INFO,console

bin/flume-ng agent -n a2 -f /home/hadoop/a2.conf -c conf -Dflume.root.logger=INFO,console

-D指定运行时要打印在控制台的日志级别
INFO,Debug,warning

接下来将文件放入指定目录

配置文件a4

#定义agent名, source、channel、sink的名称
a4.sources = r1
a4.channels = c1
a4.sinks = k1

#具体定义source
a4.sources.r1.type = spooldir
a4.sources.r1.spoolDir = /home/hadoop/logs

#具体定义channel
a4.channels.c1.type = memory
#容量 条
a4.channels.c1.capacity = 10000
#事务容量
a4.channels.c1.transactionCapacity = 100

#定义拦截器,为消息添加时间戳
#可以拦截无效数据
a4.sources.r1.interceptors = i1
a4.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder


#具体定义sink
a4.sinks.k1.type = hdfs
#上层抽象,nameService,路由
#%Y%m%d 从拦截器得到时间
a4.sinks.k1.hdfs.path = hdfs://ns1/flume/%Y%m%d
#前缀,随便起名字,名字是event-.时间戳
a4.sinks.k1.hdfs.filePrefix = events-
#纯文本
a4.sinks.k1.hdfs.fileType = DataStream
#不按照条数生成文件
a4.sinks.k1.hdfs.rollCount = 0
#两个条件满足其中一个就可以
#HDFS上的文件达到128M时生成一个文件
a4.sinks.k1.hdfs.rollSize = 134217728
#HDFS上的文件达到60秒生成一个文件
a4.sinks.k1.hdfs.rollInterval = 60

#组装source、channel、sink
a4.sources.r1.channels = c1
a4.sinks.k1.channel = c1

配置文件a2


#定义agent名, source、channel、sink的名称
a2.sources = r1
a2.channels = c1
a2.sinks = k1

#具体定义source
a2.sources.r1.type = exec
#tail -F 监视文件的增长
a2.sources.r1.command = tail -F /home/hadoop/a.log

#具体定义channel
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100

#具体定义sink
#logger是打印在控制台上
a2.sinks.k1.type = logger

#组装source、channel、sink
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1

你可能感兴趣的:(Flume)