Flume配置案例(一)-基础篇

 官方文档(中文)

Flume 1.9用户手册中文版 — 可能是目前翻译最完整的版本了

官方文档(英文)

Flume 1.9.0 User Guide — Apache Flume

1、netcat- logger

安装telnet工具

sudo yum install telnet-server.x86_64 -y
sudo yum install telnet -y
sudo rpm -qa telnet-server

判断44444端口是否被占用

sudo netstat -tunlp | grep 44444

在/usr/local/soft/apache-flume-1.9.0-bin/conf/目录下创建flume-telnet-logger.properties文件,内容如下

# 指定agent的名字为a1
# 指定a1的sources为r1
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
# netcat用来监听指定端口号的数据
a1.sources.r1.type = netcat
# 监听localhost的44444端口
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# Describe the sink,日志方式 
a1.sinks.k1.type = logger

# 指定数据放到channel的内存中
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

执行

cd /usr/local/soft/apache-flume-1.9.0-bin/conf/
flume-ng agent -n a1 -c conf -f flume-telnet-logger.properties -Dflume.root.logger=DEBUG,console

另起一个控制台,使用telnet工具向本机的44444端口发送内容

telnet localhost 44444

2、spooldir-logger

创建文件flume-spooldir-logger.properties

#分别指定agent的sources,sinks, channels的名称 名称可以自定义
a1.sources = s1  
a1.sinks = k1  
a1.channels = c1  
   
#配置目录scource
a1.sources.s1.type =spooldir
a1.sources.s1.spoolDir =/usr/local/logs
a1.sources.s1.fileHeader= true  
a1.sources.s1.channels =c1  
   
#配置sink 
a1.sinks.k1.type = logger  
a1.sinks.k1.channel = c1  
   
#配置channel(内存做缓存)
a1.channels.c1.type = memory

启动

cd /usr/local/soft/apache-flume-1.9.0-bin/conf/
flume-ng agent -n a1 -c conf -f flume-spooldir-logger.properties -Dflume.root.logger=DEBUG,console

3、taildir-logger

taildir:可实时监控一批文件,并记录每个文件最新消费位置,agent进程重启后不会有重复消费的问题。

在/usr/local/soft/apache-flume-1.9.0-bin创建log文件夹,并在log中创建taildir_position.json文件

创建文件flume-taildir-logger.properties

#agent_name
a1.sources=r1
a1.sinks=k1
a1.channels=c1
​
#source的配置
# source类型
a1.sources.r1.type = TAILDIR
# 元数据位置
a1.sources.r1.positionFile = /usr/local/soft/apache-flume-1.9.0-bin/log/taildir_position.json
# 监控的目录
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1=/usr/local/data/.*log
a1.sources.r1.fileHeader = true
​
#sink的配置
a1.sinks.k1.type = logger
​
#channel的配置
a1.channels.c1.type = memory
a1.channels.c1.capacity = 10000
a1.channels.c1.transactionCapacity = 100
​
#用channel链接source和sink
a1.sources.r1.channels = c1
a1.sinks.k1.channel =c1

启动

cd /usr/local/soft/apache-flume-1.9.0-bin/conf/
flume-ng agent -n a1 -c conf -f flume-taildir-logger.properties -Dflume.root.logger=DEBUG,console

在/usr/local/data/路径下分别创建demo.log、demo1.log,然后添加内容,查看shell界面输出

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数智侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值