做网站公司 备案seo信息优化
一 ,多输出
1 ,要求 :
- 数据来源 : 文件监控
- 数据去向 : hdfs + 本地
- 分配机制 : 复制 ( 两个目的地的数据完全一致 )
2 ,架构图 :
3 ,思路 :
- flume1 :接收文件变化
- flume2 :建数据下沉到 hdfs
- flume3 :将数据下沉到 本地
4 ,配置文件 :vim flume1.conf
- 目的 : 配置 1 个接收日志文件的 source 和 2 个 channel、两个 sink
- avro : 语言无关的数据序列化和 RPC 框架。
- RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。
- avro : 简单地说,就是一种传输数据格式,让数据更快的传递。
- 配置 :
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf
vim flume1.conf
# 名字
a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1 c2
# 选择器:复制
a1.sources.r1.selector.type = replicating# 1 ,源:linux 脚本
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /tmp/root/hive.log
a1.sources.r1.shell = /bin/bash -c# 2 ,下沉:avro ( 为了传递数据,选择这种类型 ),选择将数据发送到哪里
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = node01
a1.sinks.k1.port = 4141a1.sinks.k2.type = avro
a1.sinks.k2.hostname = node01
a1.sinks.k2.port = 4142# 3 ,管道 ( 内存缓存数据,1000 个缓存,每个事物发送 100 条数据 )
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100a1.channels.c2.type = memory
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100# 关联管道与源,管道与出口
a1.sources.r1.channels = c1 c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2
5 ,配置文件 :vim flume2.conf ( 下沉到 hdfs )
- 目的 : 配置上级 flume 输出的 source,输出是到 hdfs的 sink。
- 代码 : vim flume2.conf
# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1# Describe/configure the source
a2.sources.r1.type = avro
a2.sources.r1.bind = node01
a2.sources.r1.port = 4141# Describe the sink
a2.sinks.k1.type = hdfs
a2.sinks.k1.hdfs.path = hdfs://node01:8020/flume2/%Y%m%d/%H
#上传文件的前缀
a2.sinks.k1.hdfs.filePrefix = flume2-
#是否按照时间滚动文件夹
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
#最小冗余数
a2.sinks.k1.hdfs.minBlockReplicas = 1# Describe the channel
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100# Bind the source and sink to the channel
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1
6 ,配置文件 :vim flume3.conf ( 下沉到本地 )
vim flume3.conf
# 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 = node01
a3.sources.r1.port = 4142# 下沉到文件
a3.sinks.k1.type = file_roll
a3.sinks.k1.sink.directory = /root/flumesink# 管道
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
7 ,启动 :先启动下沉,再启动源
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin
bin/flume-ng agent --conf conf/ --name a2 --conf-file /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/flume2.conf
bin/flume-ng agent --conf conf/ --name a3 --conf-file /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/flume3.conf
bin/flume-ng agent --conf conf/ --name a1 --conf-file /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/flume1.conf
8 ,测试 :
- 改变那个文件的内容 :
cd /tmp/root
echo 1111 >> hive.log
echo 2222 >> hive.log - 观察结果 :
1 ,hdfs :
2 ,本地文件夹 :
二 ,负载均衡 :
1 ,负载均衡 : 简介
- 目的 : 减轻任务的压力。
- 做法 : 把一个工作让很多人一起做。
- 应用场景 : 任务量太大的时候。
2 ,目的 :
- flume1 : 接收网络端口数据。
- flume2 : 打印到控制台。
- flume3 : 打印到控制台。
3 ,架构模型 :
4 ,注意 :
我们把数据打印到控制台,方便监控数据变化,就不把数据发送到 hdfs 了。
5 ,高可用配置 :
6 ,负载均衡配置 :
7 ,负载均衡的策略 :
- 目的 : 我干活的时候,你休息,你干活的时候,我休息。
- 策略 : 轮询 ,随机 。
8 ,vim flume1.conf :监听网络端口,发数据到 avro
# 名字
a1.sources = r1
a1.channels = c1
a1.sinkgroups = g1
a1.sinks = k1 k2# 监听端口,本机的 44444
a1.sources.r1.type = netcat
a1.sources.r1.bind = node01
a1.sources.r1.port = 44444# 负载均衡,失败后退,负载方式(轮询),10 秒没好,就回退
a1.sinkgroups.g1.processor.type = load_balance
a1.sinkgroups.g1.processor.backoff = true
a1.sinkgroups.g1.processor.selector = round_robin
a1.sinkgroups.g1.processor.selector.maxTimeOut=10000# 下沉
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = node01
a1.sinks.k1.port = 4141a1.sinks.k2.type = avro
a1.sinks.k2.hostname = node01
a1.sinks.k2.port = 4142# 管道
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100# 连接
a1.sources.r1.channels = c1
a1.sinkgroups.g1.sinks = k1 k2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c1
9 ,vim flume2.conf : 从 avro 收数据,发到控制台
# 名字
a2.sources = r1
a2.sinks = k1
a2.channels = c1# 从 avro 接收数据
a2.sources.r1.type = avro
a2.sources.r1.bind = node01
a2.sources.r1.port = 4141# 下沉到 :控制台
a2.sinks.k1.type = logger# Describe the channel
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100# Bind the source and sink to the channel
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1
10 ,vim flume3.conf : 从 avro 接收数据,发到控制台
# 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 = node01
a3.sources.r1.port = 4142# Describe the sink
a3.sinks.k1.type = logger# 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
11 ,执行 : ( 开三个控制台窗口 )
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin
bin/flume-ng agent --conf conf/ --name a3 --conf-file /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/fzjh/flume3.conf -Dflume.root.logger=INFO,console
bin/flume-ng agent --conf conf/ --name a2 --conf-file /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/fzjh/flume2.conf -Dflume.root.logger=INFO,console
bin/flume-ng agent --conf conf/ --name a1 --conf-file /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/fzjh/flume1.conf
12 ,测试 :
- 在 node02 上,使用网络连接工具 : telnet node01 44444
- 在 node02 上,给 node01 发消息 : 发很多次
13 ,结果 :
在 flume1 上看到一些数据,在flume2 上,也看到一些数据。