准备工作:
- 三台已经安装好的虚拟机(weekend110、weekend01、weekend02)
- 三台虚拟机上都已安装 JDK1.8 和 Flume1.7.0
- 虚拟机weekend110上已安装 Hadoop2.7 和 Hive
需求:
使用在机器weekend110上部署的Flume-a1准实时监控日志文件 /tmp/hadoop/hive.log 的变动,Flume-a1将变动的内容传递给在weekend01上部署的Flume-a2,Flume-a2负责存储到HDFS。同时Flume-a1将变动内容传递给在weekend02上部署的Flume-a3,Flume-a3再负责输出到Local FileSystem的指定目录flume3下。
实现:
-
分别在三台机器上的 /home/hadoop/app/flume-1.7.0-bin/ 下创建一个job目录,用来专门存放要配置的conf配置文件。另外单独在机器weekend02的 /home/hadoop/datas/ 下创建自定义的输出目录flume3
-
分别在三台机器的 /home/hadoop/app/flume-1.7.0-bin/job 目录下配置各自的conf文件,如下:
在weekend110上,配置1个接收日志文件的source和两个channel、两个sink ,配置文件 flume-file-flume.conf 的内容如下:
# Name the components on this agent
a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1 c2
# 将数据流复制给所有channel
a1.sources.r1.selector.type = replicating
# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /tmp/hadoop/hive.log
a1.sources.r1.shell = /bin/bash -c
# Describe the sink
# sink端的avro是一个数据发送者
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = weekend01
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = weekend02
a1.sinks.k2.port = 4142
# Describe the channel
a1.