使用flume實時監控hive文件到HDFS

Flume最主要的作用就是,實時讀取服務器本地磁盤的數據,將數據寫入HDFS。

Flume組成架構如下所示:

Flume Agent內部原理如圖所示:

 

1.配置hive日誌文件存放位置:

2.修改配置項:

在hive的根目錄下創建logs文件夾 

3.創建flume的配置文件

在flume的根目錄下創建job文件夾用來存放flume的配置文件:

 創建file-flume-hdfs.conf配置文件:

 file-flume-hdfs.conf配置文件內容如下所示:

# Name the components on this agent
a2.sources = r2   #定義source
a2.sinks = k2     #定義sink
a2.channels = c2  #定義channel
# Describe/configure the source
a2.sources.r2.type = exec #定義source類型爲exec可執行命令的
a2.sources.r2.command = tail -F /usr/local/hive/logs/hive.log  #hive日誌信息存放信息
a2.sources.r2.shell = /bin/bash -c  #執行shell腳本的絕對路徑
# Describe the sink 
a2.sinks.k2.type = hdfs 
a2.sinks.k2.hdfs.path = hdfs://master:9000/flume/%Y%m%d/%H 
a2.sinks.k2.hdfs.filePrefix = logs- #上傳文件的前綴 
a2.sinks.k2.hdfs.round = true       #是否按照時間滾動文件夾
a2.sinks.k2.hdfs.roundValue = 1     #多少時間單位創建一個新的文件夾
a2.sinks.k2.hdfs.roundUnit = hour   #重新定義時間單位
a2.sinks.k2.hdfs.useLocalTimeStamp = true  #是否使用本地時間戳
a2.sinks.k2.hdfs.batchSize = 1000   #積攢多少個Event才flush到HDFS一次
a2.sinks.k2.hdfs.fileType = DataStream #設置文件類型,可支持壓縮
a2.sinks.k2.hdfs.rollInterval = 600    #多久生成一個新的文件
a2.sinks.k2.hdfs.rollSize = 134217700  #設置每個文件的滾動大小
a2.sinks.k2.hdfs.rollCount = 0         #文件的滾動與Event數量無關
a2.sinks.k2.hdfs.minBlockReplicas = 1  #最小冗餘數
# Use a channel which buffers events in memory 
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a2.sources.r2.channels = c2 
a2.sinks.k2.channel = c2 

4.上傳jar包到flume的lib文件夾下:

5. 啓動flume

6.打開HDFS查看文件:

 

這樣,hive的日誌文件就實時發送到HDFS上 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章