一、第一层Flume(f1)
(1)Flume组件:Agent(Source + Channel + Sink)
(2)一个事务为event(Header + Body),body为存储数据,header是Flume自动加入的数据。
① 选用配置:taildir source -> etl interceptor -> kafka channel
taildir source实现断点续传,监控多目录
kafka channel可省去kafka sink
② 作用:采用了etl interceptor进行初步的数据清洗,去除不符合Json格式的数据。
第一层flume采集到kafka中数据是一个主题一个分区,主题名applog。
1、flume_to_kafka.conf
#taildir source -> etl interceptor -> kafka channel
#1、定义source、channel、agent名称
a1.sources = r1
a1.channels = c1
#2、描述source
a1.sources.r1.type = TAILDIR
#指定监控的组名
a1.sources.r1.filegroups = f1
#指定f1组监控的路径
a1.sources.r1.filegroups.f1 = /opt/module/applog/log/app.*
#指定断点续传的文件
a1.sources.r1.positionFile = /opt/module/flume/position.json
#指定每个批次采集多少数据[batchSize<=事务的大小]
a1.sources.r1.batchSize = 100
#2.1、指定自定义拦截器
#定义拦截器的名称
a1.sources.r1.interceptors = i1
#定义拦截器的全类名
a1.sources.r1.interceptors.i1.type = com.atguigu.interceptor.ETLInterceptor$Builder
#3、描述channel
a1.channels.c1.type = org.apache.flume.channel.kafka.KafkaChannel
#指定kafka集群
a1.channels.c1.kafka.bootstrap.servers = hadoop102:9092,hadoop103:9092
#指定数据写到kafka哪个topic
a1.channels.c1.kafka.topic = applog
#是否以Event对象的形式写入kafka
a1.channels.c1.parseAsFlumeEvent = false
#4、关联source->channel
a1.sources.r1.channels = c1
2、pom.xml文件
导入两个依赖和两个插件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atguigu</groupId>
<artifactId>data0821</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-ng-core</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
<!-- 解析Json格式 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependen