flume-1.9.0 与 hadoop-3.3.0 HDFS 对接部署
一、下载 apache-flume-1.9.0-bin.tar.gz 解压至 /home/hadoop-3.3.0/flume-1.9.0 目录;
二、创建相关目录
/home/hadoop-3.3.0/flumefile //用于接收tomcat日志文件
/home/hadoop-3.3.0/flume-1.9.0/channels1_logs_tmp
/home/hadoop-3.3.0/flume-1.9.0/channels1_logs_tmp_cp
三、创建并配置 /home/hadoop-3.3.0/flume-1.9.0/conf/flume.conf 文件:
# 指定Agent的组件名称 a1.sources = r1 a1.sinks = k1 a1.channels = c1 # 指定Flume source(要监听的路径) a1.sources.r1.type = spooldir a1.sources.r1.spoolDir = /home/hadoop-3.3.0/flumefile a1.sources.r1.fileHeader = false a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = timestamp # 指定Flume sink a1.sinks.k1.type = hdfs a1.sinks.k1.hdfs.path = hdfs://iZwz974yt1d*****:9000/logs a1.sinks.k1.hdfs.fileType = DataStream a1.sinks.k1.hdfs.writeFormat = TEXT a1.sinks.k1.hdfs.minBlockReplicas = 1 a1.sinks.k1.hdfs.rollInterval = 600 a1.sinks.k1.hdfs.rollSize = 0 a1.sinks.k1.hdfs.rollCount = 0 a1.sinks.k1.hdfs.idleTimeout = 0 a1.sinks.k1.hdfs.filePrefix=%Y-%m-%d # 指定Flume channel a1.channels.c1.type = file #a1.channels.c1.capacity = 1000 #a1.channels.c1.transactionCapacity = 100 a1.channels.c1.checkpointDir=/home/hadoop-3.3.0/flume-1.9.0/channels1_logs_tmp_cp a1.channels.c1.dataDirs=/home/hadoop-3.3.0/flume-1.9.0/channels1_logs_tmp # 绑定source和sink到channel上 a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
四、替换 guava 包:
将 /home/hadoop-3.3.0/flume-1.9.0/lib/guava-11.0.2.jar 替换为 /home/hadoop-3.3.0/share/hadoop/hdfs/lib/guava-27.0-jre.jar
否则将报以下错误:
2020-08-21 09:31:52,381 (SinkRunner-PollingRunner-DefaultSinkProcessor) [ERROR - org.apache.flume.sink.hdfs.HDFSEventSink.process(HDFSEventSink.java:459)] process failed java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V at org.apache.hadoop.conf.Configuration.set(Configuration.java:1380) at org.apache.hadoop.conf.Configuration.set(Configuration.java:1361) at org.apache.hadoop.conf.Configuration.setBoolean(Configuration.java:1703) at org.apache.flume.sink.hdfs.BucketWriter.open(BucketWriter.java:221) at org.apache.flume.sink.hdfs.BucketWriter.append(BucketWriter.java:572) at org.apache.flume.sink.hdfs.HDFSEventSink.process(HDFSEventSink.java:412) at org.apache.flume.sink.DefaultSinkProcessor.process(DefaultSinkProcessor.java:67) at org.apache.flume.SinkRunner$PollingRunner.run(SinkRunner.java:145) at java.lang.Thread.run(Thread.java:748) Exception in thread "SinkRunner-PollingRunner-DefaultSinkProcessor" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V at org.apache.hadoop.conf.Configuration.set(Configuration.java:1380) at org.apache.hadoop.conf.Configuration.set(Configuration.java:1361) at org.apache.hadoop.conf.Configuration.setBoolean(Configuration.java:1703) at org.apache.flume.sink.hdfs.BucketWriter.open(BucketWriter.java:221) at org.apache.flume.sink.hdfs.BucketWriter.append(BucketWriter.java:572) at org.apache.flume.sink.hdfs.HDFSEventSink.process(HDFSEventSink.java:412) at org.apache.flume.sink.DefaultSinkProcessor.process(DefaultSinkProcessor.java:67) at org.apache.flume.SinkRunner$PollingRunner.run(SinkRunner.java:145) at java.lang.Thread.run(Thread.java:748) 2020-08-21 09:32:22,059 (Log-BackgroundWorker-c1) [INFO - org.apache.flume.channel.file.EventQueueBackingStoreFile.beginCheckpoint(EventQueueBackingStoreFile.java:230)] Start checkpoint for /home/hadoop-3.3.0/flume-1.9.0/channels1_logs_tmp_cp/checkpoint, elements to sync = 1
五、启动flume:
cd /home/hadoop-3.3.0/flume-1.9.0
nohup bin/flume-ng agent --conf conf --conf-file conf/flume.conf --name a1 -Dflume.root.logger=INFO,console &
六、确认是否启动成功: ps -ef|grep flume
李小家