一、编译
首先下载flume1.7源码,导入eclipse
1.Maven依赖报错Missing artifact jdk.tools:jdk.tools:jar:1.7
添加依赖
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
2.eclipse校验提示错误
原因:AvroFlumeEvent类是编译生成的,eclipse依赖找不到正常,没影响
3.运行
mvn install -Dmaven.test.skip=true -Dtar
编译成功后会在flume-ng-dist/target下生成tar包
4.仓库不全的话有些包下不到需手动添加,也可以直接注释不需要的插件依赖
手动添加方法:
首先,到 http://mvnrepository.com/ 这个网,在搜索栏中输入你要搜索的 JAR 包关键字
运行 mvn install:install-file -Dfile=E:\xxx\xxx.jar -DgroupId=xxx
-DartifactId=xxx -Dversion=xxx -Dpackaging=jar
二、启动
1.flume-ng-node根目录下创建test.properties
# example.conf: A single-node Flume configuration
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
a1.sources.r1.channels = c1
# Describe the sink
a1.sinks.k1.type = logger
a1.sinks.k1.channel = c1
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
2.创建src/main/resources资源文件夹,复制根目录conf下log4j文件放进去,修改日志级别
3.设置Application运行参数 -n a1 -f test.properties
4.启动Application
使用telnet命令就可以测试了
5.启动可能报错没有相关类
原因:flume-ng-node默认依赖可能不包括该插件
比如kafka sink需在pom.xml增加依赖
<dependency>
<groupId>org.apache.flume.flume-ng-sinks</groupId>
<artifactId>flume-ng-kafka-sink</artifactId>
</dependency>