僞分佈式系列 - 第六篇 - flume-1.9.0-環境搭建

目標

  • flume下載安裝
  • 此處以實時監聽文件上傳到hdfs爲場景實現

架構

在這裏插入圖片描述

  • flume的官方給的如上的圖,這是個基本的單位agent 有source,channel,sink組成,agent可以隨意組合,可以形成一個複雜的架構關係,實現各種方式的採集,高可用.

環境準備

下載flume

# flume 配置
export FLUME_HOME=/opt/bigdata/flume/default
export PATH=${FLUME_HOME}/bin:$PATH

flume配置

進入配置目錄

  • /opt/bigdata/flume/default/conf 這個目錄沒有限制,啓動agent時候隨意指定

配置

  • 配置配置文件file-to-hdfs.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
## exec表示flume回去調用給的命令,然後從給的命令的結果中去拿數據
a1.sources.r1.type = exec
## 使用tail這個命令來讀數據
a1.sources.r1.command = tail -F /opt/bigdata/flume/default/conf/data.txt
a1.sources.r1.channels = c1

# Describe the sink
## 表示下沉到hdfs,類型決定了下面的參數
a1.sinks.k1.type = hdfs
## sinks.k1只能連接一個channel,source可以配置多個
a1.sinks.k1.channel = c1
## 下面的配置告訴用hdfs去寫文件的時候寫到什麼位置,下面的表示不是寫死的,而是可以動態的變化的。表示輸出的目錄名稱是可變的
a1.sinks.k1.hdfs.path = /data/flume/logs/%y-%m-%d/%H%M/
##表示最後的文件的前綴
a1.sinks.k1.hdfs.filePrefix = logs-
## 表示到了需要觸發的時間時,是否要更新文件夾,true:表示要
a1.sinks.k1.hdfs.round = true
## 表示每隔1分鐘改變一次
a1.sinks.k1.hdfs.roundValue = 1
## 切換文件的時候的時間單位是分鐘
a1.sinks.k1.hdfs.roundUnit = minute
## 表示只要過了3秒鐘,就切換生成一個新的文件
a1.sinks.k1.hdfs.rollInterval = 3
## 如果記錄的文件大於20字節時切換一次
a1.sinks.k1.hdfs.rollSize = 20
## 當寫了5個事件時觸發
a1.sinks.k1.hdfs.rollCount = 5
## 收到了多少條消息往dfs中追加內容
a1.sinks.k1.hdfs.batchSize = 10
## 使用本地時間戳
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#生成的文件類型,默認是Sequencefile,可用DataStream:爲普通文本
a1.sinks.k1.hdfs.fileType = DataStream

# Use a channel which buffers events in memory
##使用內存的方式,內存緩存的數據,重啓會丟失,file 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

啓動測試

  • 啓動命令,log在flume家目錄下的logs目錄裏
$FLUME_HOME/bin/flume-ng agent -c conf -f conf/file-to-hdfs.conf -n a1

[root@ecs-6531-0002 default]# bin/flume-ng agent -c conf -f conf/file-to-hdfs.conf -n a1
Info: Including Hadoop libraries found via (/opt/bigdata/hadoop/default/bin/hadoop) for HDFS access
Info: Including Hive libraries found via (/opt/bigdata/hive/default) for Hive access
+ exec /usr/local/java_1.8.0_121/bin/java -Xmx20m -cp '/opt/bigdata/flume/default/conf:/opt/bigdata/flume/default/lib/*:/opt/bigdata/hadoop/default/etc/hadoop:/opt/bigdata/hadoop/default/share/hadoop/common/lib/*:/opt/bigdata/hadoop/default/share/hadoop/common/*:/opt/bigdata/hadoop/default/share/hadoop/hdfs:/opt/bigdata/hadoop/default/share/hadoop/hdfs/lib/*:/opt/bigdata/hadoop/default/share/hadoop/hdfs/*:/opt/bigdata/hadoop/default/share/hadoop/mapreduce/lib/*:/opt/bigdata/hadoop/default/share/hadoop/mapreduce/*:/opt/bigdata/hadoop/default/share/hadoop/yarn:/opt/bigdata/hadoop/default/share/hadoop/yarn/lib/*:/opt/bigdata/hadoop/default/share/hadoop/yarn/*:/opt/bigdata/hive/default/lib/*' -Djava.library.path=:/opt/bigdata/hadoop/default/lib org.apache.flume.node.Application -f conf/file-to-hdfs.conf -n a1
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/bigdata/flume/apache-flume-1.9.0-bin/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/bigdata/hadoop/hadoop-3.2.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/bigdata/hive/apache-hive-2.3.5-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

  • 查看效果
  • 目錄已創建
  • 數據已經上傳
    在這裏插入圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章