flume使用实例

1、监听端口a1.sources.r1.type = netcat

配置文件nc-flume-console.conf

Name the components on this agent a1 表示jvm进程名

a1.sources = r1

a1.sinks = k1

a1.channels = c1

Describe/configure the source

a1.sources.r1.type = netcat

a1.sources.r1.bind = node1

a1.sources.r1.port = 44444

Describe the sink

a1.sinks.k1.type = logger

Use a channel which buffers events in memory

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000 #1000个event

a1.channels.c1.transactionCapacity = 100

Bind the source and sink to the channel

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

flume-ng agent -n a1 -c conf/ -f /export/server/flume/job/nc-flume-console.conf

参数-n 表示jvm进程名 -c表示本次启动读取的配置文件conf目录下的文件 -f 表示具体执行的文件

另开窗口输入内容后控制台会自动返回OK

2、实时监控单个追加文件

配置文件 flume-exec-logger.conf

#Agent_name

a1.sources = r1

a1.sinks = k1

a1.channels = c1

#Sources

a1.sources.r1.type = exec

a1.sources.r1.command = tail -F /export/server/hive/logs/hive.log

#Channel

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000

a1.channels.c1.transactionCapacity = 100

#sinks

a1.sinks.k1.type = logger

#组合

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

启动flume监听

flume-ng agent -c conf/ -f job/flume-exec-logger.conf -n a1

手动追加数据到hive.log文件 并查看监控窗口

echo INFO [main] spark.HiveSparkClientFactory >> logs/hive.log

动态添加数据到hive.log

连接hive 观察flume监控变化

beeline -u jdbc:hive2://node1:10000 -n ljr

show databases;

由此可见当我们操作hive的时候 hive.log 就更新,由于我们监控了hive.log文件所以当有新数据追加到hive.log的时候 就会监听到 并打印到控制台

3、实时监控单个追加文件,并将数据输出到hdfs

配置文件 flume-hivelogs-hdfs.con

Name the components on this agent

a2.sources = r2

a2.sinks = k2

a2.channels = c2

Describe/configure the source

a2.sources.r2.type = exec

a2.sources.r2.command = tail -F /export/server/hive/logs/hive.log

Describe the sink

a2.sinks.k2.type = hdfs

a2.sinks.k2.hdfs.path = hdfs://node1:8020/flume/%Y%m%d/%H

#上传文件的前缀

a2.sinks.k2.hdfs.filePrefix = logs-

#是否按照时间滚动文件夹

a2.sinks.k2.hdfs.round = true

#多少时间单位创建一个新的文件夹

a2.sinks.k2.hdfs.roundValue = 1

#重新定义时间单位

a2.sinks.k2.hdfs.roundUnit = hour

#是否使用本地时间戳

a2.sinks.k2.hdfs.useLocalTimeStamp = true

#积攒多少个 Event 才 flush 到 HDFS 一次

a2.sinks.k2.hdfs.batchSize = 100

#设置文件类型,可支持压缩

a2.sinks.k2.hdfs.fileType = DataStream

#多久生成一个新的文件

a2.sinks.k2.hdfs.rollInterval = 60

#设置每个文件的滚动大小

a2.sinks.k2.hdfs.rollSize = 134217700

#文件的滚动与 Event 数量无关

a2.sinks.k2.hdfs.rollCount = 0

Use a channel which buffers events in memory

a2.channels.c2.type = memory

a2.channels.c2.capacity = 1000

a2.channels.c2.transactionCapacity = 100

Bind the source and sink to the channel

a2.sources.r2.channels = c2

a2.sinks.k2.channel = c2

启动flume监听,操作hive

flume-ng agent -n a2 -c conf/ -f flume-hivelogs-hdfs.con

查看hdfs,有新文件产生

使用 Flume 监听整个目录(a3.sources.r3.type = TAILDIR)

的实时追加文件,并上传至 HDFS

实现步骤:

【1】创建被监控目录

我这里监控data目录 此目录需要提前创建

mkdir data

cd data

touch file1.txt

touch file2.txt

touch log2.txt

toch log1.txt

【2】创建文件 flume-taildir-hdfs.conf

a3.sources = r3

a3.sinks = k3

a3.channels = c3

Describe/configure the source

a3.sources.r3.type = TAILDIR

#记录最后监控文件的断点的文件,此文件位置可不改

a3.sources.r3.positionFile = /export/server/flume/data /tail_dir.json

a3.sources.r3.filegroups = f1 f2

a3.sources.r3.filegroups.f1 = /export/server/flume/data/.*file.*

a3.sources.r3.filegroups.f2 =/export/server/flume/data/.*log.*

Describe the sink

a3.sinks.k3.type = hdfs

hdfs://node1:8020 可省略

a3.sinks.k3.hdfs.path = hdfs://node1:8020/flume/upload2/%Y%m%d/%H

#上传文件的前缀

a3.sinks.k3.hdfs.filePrefix = upload-

#是否按照时间滚动文件夹

a3.sinks.k3.hdfs.round = true

#多少时间单位创建一个新的文件夹

a3.sinks.k3.hdfs.roundValue = 1

#重新定义时间单位

a3.sinks.k3.hdfs.roundUnit = hour

#是否使用本地时间戳

a3.sinks.k3.hdfs.useLocalTimeStamp = true

#积攒多少个 Event 才 flush 到 HDFS 一次

a3.sinks.k3.hdfs.batchSize = 100

#设置文件类型,可支持压缩

a3.sinks.k3.hdfs.fileType = DataStream

#多久生成一个新的文件,单位是秒

a3.sinks.k3.hdfs.rollInterval = 3600

#设置每个文件的滚动大小大概是 128M,单位是byte

a3.sinks.k3.hdfs.rollSize = 134217700

#文件的滚动与 Event 数量无关

a3.sinks.k3.hdfs.rollCount = 0

Use a channel which buffers events in memory

a3.channels.c3.type = memory

a3.channels.c3.capacity = 1000

a3.channels.c3.transactionCapacity = 100

Bind the source and sink to the channel

a3.sources.r3.channels = c3

a3.sinks.k3.channel = c3

【3】启动flume监控

bin/flume-ng agent -c conf -f datas/flume-taildir-hdfs.conf -n a3

【4】向文件中追加内容

相关推荐
猎板PCB 邹亮3 小时前
国内高频混压PCB厂家有哪些?
大数据·人工智能·pcb工艺
Microsoft Word5 小时前
Flink
大数据·flink
理***所5 小时前
湖北理元理律师事务所债务优化方案:让还款与生活平衡的艺术
大数据
TTBIGDATA10 小时前
Step9—Ambari Web UI 初始化安装 (Ambari3.0.0)
大数据·hadoop·python·ambari·bigtop·ttbigdata·janettr
冰橙子id10 小时前
基于ubuntu安装hadoop
大数据·hadoop·ubuntu
爱吃糖的靓仔11 小时前
ElasticSearch查询指定时间内出现的次数/2秒内出现的次数
大数据·elasticsearch·jenkins
鸿乃江边鸟11 小时前
Starrocks 物化视图的实现以及在刷新期间能否读数据
java·大数据·starrocks·sql
线条112 小时前
【Hive 运维实战】一键管理 Hive 服务:Metastore 与 HiveServer2 控制脚本开发与实践
hive·hadoop·自动化
Python数据分析与机器学习12 小时前
【python实战】二手房房价数据分析与预测
大数据·开发语言·python·数据挖掘·数据分析·scikit-learn·ipython
wuli玉shell13 小时前
spark shuffle的分区支持动态调整,而hive不支持
大数据·hive·spark