一、目的
為了實(shí)現(xiàn)用Flume實(shí)時(shí)采集Hive的操作日志到HDFS中,于是進(jìn)行了一場實(shí)驗(yàn)
二、前期準(zhǔn)備
(一)安裝好Hadoop、Hive、Flume等工具
(二)查看Hive的日志在Linux系統(tǒng)中的文件路徑
[root@hurys23 conf]# find / -name hive.log
/home/log/hive312/hive.log
(三)在HDFS中創(chuàng)建文件夾flume,即Hive日志寫入的HDFS文件
三、創(chuàng)建Flume的任務(wù)文件
[root@hurys23 conf]# vi ?flume-file-hdfs.conf
# Name the components on this agent
a2.sources = r2
a2.sinks = k2
a2.channels = c2
# Describe/configure the source
a2.sources.r2.type = exec
a2.sources.r2.command = tail -F /home/log/hive312/hive.log
# Describe the sink
a2.sinks.k2.type = hdfs
a2.sinks.k2.hdfs.path = hdfs://hurys23:8020/flume/%Y%m%d/%H
#上傳文件的前綴
a2.sinks.k2.hdfs.filePrefix = logs-
#是否按照時(shí)間滾動文件夾
a2.sinks.k2.hdfs.round = true
#多少時(shí)間單位創(chuàng)建一個(gè)新的文件夾
a2.sinks.k2.hdfs.roundValue = 1
#重新定義時(shí)間單位
a2.sinks.k2.hdfs.roundUnit = hour
#是否使用本地時(shí)間戳
a2.sinks.k2.hdfs.useLocalTimeStamp = true
#積攢多少個(gè) Event 才 flush 到 HDFS 一次
a2.sinks.k2.hdfs.batchSize = 100
#設(shè)置文件類型,可支持壓縮
a2.sinks.k2.hdfs.fileType = DataStream
#多久生成一個(gè)新的文件
a2.sinks.k2.hdfs.rollInterval = 60
#設(shè)置每個(gè)文件的滾動大小
a2.sinks.k2.hdfs.rollSize = 134217700
#文件的滾動與 Event 數(shù)量無關(guān)
a2.sinks.k2.hdfs.rollCount = 0
# 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
注意:
1、配置文件中的各項(xiàng)參數(shù)需要調(diào)式,這里只是為了演示,實(shí)現(xiàn)目的、打通路徑即可!實(shí)際在項(xiàng)目中操作時(shí)需要調(diào)試參數(shù)。
2、a2.sources.r2.command = tail -F /home/log/hive312/hive.log? ? ? ? ? ?為hive.log在Linux中的路徑
3、a2.sinks.k2.hdfs.path = hdfs://hurys23:8020/flume/%Y%m%d/%H? ? ??為寫入的HDFS文件路徑
四、啟動Flume任務(wù)文件
[root@hurys23 flume190]# bin/flume-ng agent -n a2 ?-f /usr/local/hurys/dc_env/flume/flume190/conf/flume-file-hdfs.conf
五、Flume任務(wù)運(yùn)行時(shí)寫入的HDFS文件狀況
(一)目前時(shí)間
2023/12/5 14時(shí)
(二)HDFS的flume文件夾中根據(jù)時(shí)間戳自動生成20231205文件夾、14文件夾及其logs文件
(三)HDFS的log文件內(nèi)容,以logs-.1701757858263為例
六、關(guān)閉Flume任務(wù)
首先jps查看Flume任務(wù),然后直接kill程序
[root@hurys23 conf]# jps
28385 NodeManager
27938 SecondaryNameNode
16642 RunJar
27496 NameNode
27657 DataNode
8717 Jps
28215 ResourceManager
8282 Application
[root@hurys23 conf]# kill -9 8282
Hive日志成功采集到HDFS!演示就先到這里吧,后面如果有需要就再更新。文章來源:http://www.zghlxwxcb.cn/news/detail-759464.html
再提醒一遍,博客中Flume配置文件里面的參數(shù)只是為了演示而已,具體實(shí)踐時(shí)需要根據(jù)實(shí)際情況進(jìn)行調(diào)整,不要照搬?。?!文章來源地址http://www.zghlxwxcb.cn/news/detail-759464.html
到了這里,關(guān)于二百一十一、Flume——Flume實(shí)時(shí)采集Linux中的Hive日志寫入到HDFS中(親測、附截圖)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!