hive读取hdfs存放文件_数据获取层之Flume快速入门(一) 实时监控单个追加文件
生活随笔
收集整理的這篇文章主要介紹了
hive读取hdfs存放文件_数据获取层之Flume快速入门(一) 实时监控单个追加文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實時監控 Hive 日志,并上傳到 HDFS 中
實現步驟
1、Flume 要想將數據輸出到 HDFS,必須持有 Hadoop 相關 jar 包
commons-configuration-1.6.jar、hadoop-auth-2.7.2.jar、hadoop-common-2.7.2.jar、hadoop-hdfs-2.7.2.jar、commons-io-2.4.jar、htrace-core-3.1.0-incubating.jar準備好以上這些包拷貝到/opt/module/flume/lib 文件夾下。
2、創建 flume-file-hdfs.conf 文件
進入flume下的job目錄創建文件
cd /opt/module/flume/jobvim flume-file-hdfs.conf添加如下內容
# Name the components on this agenta2.sources = r2a2.sinks = k2a2.channels = c2# Describe/configure the sourcea2.sources.r2.type = execa2.sources.r2.command = tail -F /opt/module/hive/logs/hive.loga2.sources.r2.shell = /bin/bash -c# Describe the sinka2.sinks.k2.type = hdfsa2.sinks.k2.hdfs.path = hdfs://hadoop101: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#積攢多少個 Event 才 flush 到 HDFS 一次a2.sinks.k2.hdfs.batchSize = 1000#設置文件類型,可支持壓縮a2.sinks.k2.hdfs.fileType = DataStream#多久生成一個新的文件a2.sinks.k2.hdfs.rollInterval = 60#設置每個文件的滾動大小a2.sinks.k2.hdfs.rollSize = 134217700#文件的滾動與 Event 數量無關a2.sinks.k2.hdfs.rollCount = 0# Use a channel which buffers events in memorya2.channels.c2.type = memorya2.channels.c2.capacity = 1000a2.channels.c2.transactionCapacity = 100# Bind the source and sink to the channela2.sources.r2.channels = c2a2.sinks.k2.channel = c2注:
(1)要想讀取 Linux 系統中的文件,就得按照 Linux 命令的規則執行命令。由于 Hive 日志在 Linux 系統中所以讀取文件的類型選擇:exec 即 execute 執行的意思。表示執行 Linux命令來讀取文件。
(2)對于所有與時間相關的轉義序列,Event Header 中必須存在以 “timestamp”的 key(除非hdfs.useLocalTimeStamp 設置為 true,此方法會使用 TimestampInterceptor 自動添加timestamp)。
a3.sinks.k3.hdfs.useLocalTimeStamp = true3、運行 Flume
cd /opt/module/flumebin/flume-ng agent --conf conf/ --name a2 --conf-file job/flume-file-hdfs.conf4、開啟 Hadoop 和 Hive 并操作 Hive 產生日志
[hd@hadoop101 hadoop-2.7.2]$ sbin/start-dfs.sh[hd@hadoop102 hadoop-2.7.2]$ sbin/start-yarn.sh[hd@hadoop103 hive]$ bin/hivehive (default)5、在 HDFS 上查看文件。
總結
以上是生活随笔為你收集整理的hive读取hdfs存放文件_数据获取层之Flume快速入门(一) 实时监控单个追加文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python魔法方法与函数_在Pytho
- 下一篇: 友友球捕获率_神奇宝贝球内部秘密公开!大