余老师带你学习大数据框架全栈第十二章Flume第十节企业开发案例之复制

复制

企业开发案例1

实验目的:使用 Flume-1 监控文件变动,Flume-1 将变动内容传递给 Flume-2,Flume-2 负责存储到 HDFS。同时 Flume-1 将变动内容传递给 Flume-3,Flume-3 负责输出到 Local FileSystem。
实验分析
在这里插入图片描述

实验步骤
一、实验前准备
1.新建FlumeSqoopC1,C2,C3
在这里插入图片描述
进入C1,
一、进行三台机器认证
切换到root用户。
命令:sudo /bin/bash
在这里插入图片描述
进入hadoop目录下并查看有哪些文件夹。
命令:cd /hadoop/
在这里插入图片描述
运行initHost.sh脚本,进行三台机器的认证:./initHosts.sh
确保我们的三台机器是running状态。
命令:./initHosts.sh
在这里插入图片描述
二、启动集群
1切换到hadoop用户,(密码Yhf_1018 )命令:su – hadoop
在这里插入图片描述

2切换到hadoop根目录下
命令:cd /hadoop/
在这里插入图片描述
3启动startAll.sh
命令:./startAll.sh
在这里插入图片描述
这个脚本里包含这三台机器所有的启动命令
进入c2,
1.切换到/hadoop/目录下,新建datas文件夹
命令:cd /hadoop/
mkdir datas
在这里插入图片描述
再新建test文件夹
命令:mkdir test
在这里插入图片描述
在test目录下新建hive.log
命令:touch hive.log
在这里插入图片描述
向文件中追加内容:
命令:echo hello >> hive.log
echo ssss >> hive.log

2.切换到datas目录下,创建 flume3 文件夹
命令:cd datas
mkdir flume3
在这里插入图片描述

3.切换到/hadoop/Flume/apache-flume-1.9.0-bin目录下,新建job文件夹
命令:cd /hadoop/Flume/apache-flume-1.9.0-bin
mkdir job
在这里插入图片描述
二、实验
1.切换到job里
命令:cd job
2.创建编辑 flume-file-flume.conf配置文件
配置 1 个接收日志文件的 source 和两个 channel、两个 sink,分别输送给flume-flume-hdfs 和 flume-flume-dir。
命令:vi flume-file-flume.conf
输入a或i进行编辑,在文件中添加以下内容。

# 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 /hadoop/test/hive.log
a1.sources.r1.shell = /bin/bash -c
# Describe the sink
# sink 端的 avro 是一个数据发送者
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = app-12
a1.sinks.k1.port = 4141

a1.sinks.k2.type = avro
a1.sinks.k2.hostname = app-12
a1.sinks.k2.port = 4142
# Describe the channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.channels.c2.type = memory
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1 c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2

在这里插入图片描述
点击Ecs退出编辑,:wq保存退出

3.创建编辑flume-flume-hdfs.conf 配置文件
配置上级 Flume 输出的 Source,输出是到 HDFS 的 Sink。
命令:vi flume-flume-hdfs.conf
输入a或i进行编辑,在文件中添加以下内容。

# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1
# Describe/configure the source
# source 端的 avro 是一个数据接收服务
a2.sources.r1.type = avro
a2.sources.r1.bind =app-12
a2.sources.r1.port = 4141

# Describe the sink
a2.sinks.k1.type = hdfs
a2.sinks.k1.hdfs.path = hdfs://dmcluster/bbb/%Y%m%d/%H
#上传文件的前缀
a2.sinks.k1.hdfs.filePrefix =bbb- 
#是否按照时间滚动文件夹
a2.sinks.k1.hdfs.round = true
#多少时间单位创建一个新的文件夹
a2.sinks.k1.hdfs.roundValue = 1
#重新定义时间单位
a2.sinks.k1.hdfs.roundUnit = hour
#是否使用本地时间戳
a2.sinks.k1.hdfs.useLocalTimeStamp = true
#积攒多少个 Event 才 flush 到 HDFS 一次
a2.sinks.k1.hdfs.batchSize = 100
#设置文件类型,可支持压缩
a2.sinks.k1.hdfs.fileType = DataStream
#多久生成一个新的文件
a2.sinks.k1.hdfs.rollInterval = 600
#设置每个文件的滚动大小大概是 128M
a2.sinks.k1.hdfs.rollSize = 134217700
#文件的滚动与 Event 数量无关
a2.sinks.k1.hdfs.rollCount = 0

# Describe the channel
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 1000
# Bind the source and sink to the channel
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1

点击Ecs退出编辑,:wq保存退出

4.创建编辑flume-flume-dir.conf 配置文件
配置上级 Flume 输出的 Source,输出是到本地目录的 Sink。
命令:vi flume-flume-dir.conf
输入a或i进行编辑,在文件中添加以下内容。

# Name the components on this agent
a3.sources = r1
a3.sinks = k1
a3.channels = c2
# Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.bind =app-12
a3.sources.r1.port = 4142
# Describe the sink
a3.sinks.k1.type = file_roll
a3.sinks.k1.sink.directory = /hadoop/datas/flume3
# Describe the channel
a3.channels.c2.type = memory
a3.channels.c2.capacity = 1000
a3.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a3.sources.r1.channels = c2
a3.sinks.k1.channel = c2

在这里插入图片描述

5.执行配置文件
重新开2个命令终端,在hadoop用户下切换到/hadoop/Flume/apache-flume-1.9.0-bin目录下,分别启动对应的 flume 进程:flume-flume-dir,flume-flume-hdfs,flume-file-flume。
命令:cd /hadoop/Flume/apache-flume-1.9.0-bin

flume-ng agent --name a3 --conf-file job/flume-flume-dir.conf

flume-ng agent --name a2 --conf-file job/flume-flume-hdfs.conf

flume-ng agent --name a1 --conf-file job/flume-file-flume.conf

6.检查 HDFS 上数据
命令:hdfs dfs -ls /
在这里插入图片描述

hdfs dfs -ls /bbb
在这里插入图片描述
一直想下查看,直到找到bbb-.文件 查看:
在这里插入图片描述

在这里插入图片描述

7.检查/hadoop/datas/flume3 目录中数据
命令:cd /hadoop/datas/flume3

ll
在这里插入图片描述
详细学习内容可观看Spark快速大数据处理扫一扫~~~或者引擎搜索Spark余海峰
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45810046/article/details/113742671