入門案列2 實時監控單個追加檔案

2021-10-05 06:55:44 字數 2508 閱讀 6420

1)案例需求:實時監控 hive 日誌,並上傳到 hdfs 中

2)需求分析:

3)實現步驟:

1.flume 要想將資料輸出到 hdfs,須持有 hadoop 相關 jar 包

commons-configuration-1.6.jar、

hadoop-auth-2.7.7.jar、

hadoop-common-2.7.7.jar、

hadoop-hdfs-2.7.7.jar、

commons-io-2.4.jar、

htrace-core-3.1.0-incubating.jar

拷貝到/export/servers/flume/lib 資料夾下

2.建立 flume-file-hdfs.conf 檔案

注:要想讀取 linux 系統中的檔案,就得按照 linux 命令的規則執行命令。由於 hive 日誌

在 linux 系統中所以讀取檔案的型別選擇:exec 即 execute 執行的意思。表示執行 linux

命令來讀取檔案。

# 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 /export/servers/hive/logs/hive.log

a2.sources.r2.shell = /bin/bash -c

# describe the sink

a2.sinks.k2.type = hdfs

a2.sinks.k2.hdfs.path = hdfs://hadoop102: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 = 30

#設定每個檔案的滾動大小

a2.sinks.k2.hdfs.rollsize = 134217700

#檔案的滾動與 event 數量無關

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

注意:

對於所有與時間相關的轉義序列,event header 中必須存在以 「timestamp」的 key(除非

hdfs.uselocaltimestamp 設定為 true,此方法會使用 timestampinterceptor 自動新增

timestamp)。

a3.sinks.k3.hdfs.uselocaltimestamp = true

3.執行 flume

bin/flume-ng agent --conf conf/ --name a2 --conf-file job/flume-file-hdfs.conf
4.開啟 hadoop 和 hive 並操作 hive 產生日誌

start-dfs.sh 

start-yarn.sh

5.在 hdfs 上檢視檔案。

mycat入門案列

mycat就是乙個加強版的mysql,使用的命令和mysql一樣 mycat有3個主配置檔案 1 schema.xml 定義邏輯庫和邏輯表 2 service.xml 定義了使用者登入資訊 使用者名稱和密碼等 3 rule.xml 定義了分片規則等 首先貼一下我的配置 schema.xml sele...

多執行緒案列 單例模型

單列模型 餓漢模式 public class singleton public static singleton getinstance 單列模型 餓漢模式 基本思想就是,什麼時候用到,什麼時候在初始化物件,和餓漢模式共同點,只會有乙個物件 public class singleton1 retur...

python2 監控error日誌,實時傳送到釘釘

晉級版python3的 這個比較老了也可參考 原理用python常鏈結乙個日誌檔案,每當有新的內容寫入,就通過釘釘機械人 到群裡 usr bin python coding utf 8 import urllib,urllib2,json import sys,shutil,os,string,da...