主頁 >  其他 > Flume日志采集、聚合和傳輸系統

Flume日志采集、聚合和傳輸系統

2022-01-21 07:25:55 其他

Flume

  • Flume介紹
    • 簡述
    • 運行機制
    • Flume 結構圖
      • 簡單結構
      • 復雜結構
  • Flume簡單示例
    • Flume 的安裝部署
      • 下載解壓修改組態檔
      • 開發組態檔
      • 啟動組態檔
      • 安裝 Telnet 準備測驗
    • 采集示例
      • 采集目錄到 HDFS
        • Flume 組態檔
        • 啟動 Flume
        • 上傳檔案到指定目錄
      • 采集檔案到 HDFS
        • 定義 Flume 組態檔
        • 啟動 Flume
        • 開發 Shell 腳本定時追加檔案內容
        • 啟動腳本
      • Agent級聯
        • Node2安裝Flume
        • Node2配置Flume
        • 開發腳本向檔案中寫入資料
        • 第一臺Flume組態檔
        • 順序啟動
  • 高可用方案
    • 角色分配
    • Node01安裝和配置
    • Node02 與 Node03 配置 FlumeCollection
    • 順序啟動
  • Flume 的負載均衡
    • 步驟一:開發node01服務?的flume配置
    • 步驟二:開發node02服務?的flume配置
    • 步驟三:開發node03服務?flume配置
    • 步驟四:準備啟動flume服務
    • 步驟五:node01服務?運行腳本產生資料
  • Flume案例
    • 采集端組態檔開發
    • 服務端組態檔開發
    • 采集端檔案生成腳本
    • 順序啟動服務
  • tips:解決中文亂碼

Flume介紹

簡述

  • Flume是一個分布式、可靠、和高可用的?量日志采集、聚合和傳輸的系統
  • Flume可以采集檔案,socket資料包、檔案、檔案夾、kafka等各種形式源資料,又可以將采集到的資料(下沉sink)輸出到HDFS、hbase、hive、kafka等眾多外部存盤系統中
  • 一般的采集需求,通過對flume的簡單配置即可實作
  • Flume針對特殊場景也具備良好的自定義擴展能力,因此,flume可以適用于大部分的日常資料采集場景

運行機制

1.Flume分布式系統中最核心的角色是agent,flume采集系統就是由一個個agent所連接起來形成

2.每一個agent相當于一個資料傳遞員,內部有三個組件:

  • Source:采集組件,用于跟資料源對接,以獲取資料
  • Sink:下沉組件,用于往下一級agent傳遞資料或者往最終存盤系統傳遞資料
  • Channel:傳輸通道組件,用于從source將資料傳遞到sink

Flume 結構圖

簡單結構

單個 Agent 采集資料
在這里插入圖片描述

復雜結構

多級 Agent 之間串聯
在這里插入圖片描述

Flume簡單示例

使用網路telent命令向一臺機?發送一些網路資料,然后通過flume采集網路埠資料

Flume 的安裝部署

下載解壓修改組態檔

下載地址: http://archive.apache.org/dist/flume/1.8.0/apache-flume-1.8.0-bin.tar.gz
Flume的安裝非常簡單,只需要解壓即可,當然,前提是已有hadoop環境,上傳安裝包到資料源所在節點上
cd /export/softwares/
tar -zxvf apache-flume-1.8.0-bin.tar.gz -C …/servers/
cd /export/servers/apache-flume-1.8.0-bin/conf
cp flume-env.sh.template flume-env.sh
vim flume-env.sh
export JAVA_HOME=/export/servers/jdk1.8.0_141

開發組態檔

根據資料采集的需求配置采集方案,描述在組態檔中(檔案名可任意自定義),配置我們的網路收集的組態檔
在flume的conf目錄下新建一個組態檔(采集方案)
vim /export/servers/apache-flume-1.8.0-bin/conf/netcat-logger.conf

# 定義這個agent中各組件的名字 
a1.sources = r1 
a1.sinks = k1 
a1.channels = c1 

# 描述和配置source組件:r1 
a1.sources.r1.type = netcat 
a1.sources.r1.bind = 192.168.174.1 
a1.sources.r1.port = 44444 

# 描述和配置sink組件:k1 
a1.sinks.k1.type = logger 

# 描述和配置channel組件,此處使用是記憶體快取的方式 
a1.channels.c1.type = memory 
a1.channels.c1.capacity = 1000 
a1.channels.c1.transactionCapacity = 100 

# 描述和配置source channel sink之間的連接關系 
a1.sources.r1.channels = c1 
a1.sinks.k1.channel = c1

啟動組態檔

指定采集方案組態檔,在相應的節點上啟動flume agent,先用一個最簡單的例子來測驗一下程式環境是否正常,啟動agent去采集資料
bin/flume-ng agent -c conf -f conf/netcat-logger.conf -n a1 -Dflume.root.logger=INFO,console

  • c conf 指定flume自身的組態檔所在目錄
  • f conf/netcat-logger.con 指定我們所描述的采集方案
  • n a1 指定我們這個agent的名字

安裝 Telnet 準備測驗

在機?上面安裝telnet客戶端,用于模擬資料的發送

yum -y install telnet
telnet node03 44444  #使用telnet模擬資料發送

采集示例

采集目錄到 HDFS

某服務?的某特定目錄下,會不斷產生新的檔案,每當有新檔案出現,就需要把檔案采集到HDFS中去

根據需求,首先定義以下3大要素

  1. 資料源組件,即source ——監控檔案目錄 : spooldir
    • 監視一個目錄,只要目錄中出現新檔案,就會采集檔案中的內容
    • 采集完成的檔案,會被agent自動添加一個后綴:COMPLETED
    • 所監視的目錄中不允許重復出現相同檔案名的檔案
  2. 下沉組件,即sink——HDFS檔案系統 : hdfs sink
  3. 通道組件,即channel——可用file channel 也可以用記憶體channel

Flume 組態檔

cd /export/servers/apache-flume-1.8.0-bin/conf
mkdir -p /export/servers/dirfile
vim spooldir.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
##注意:不能往監控目中重復丟同名檔案
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /export/servers/dirfile
a1.sources.r1.fileHeader = true

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
a1.sinks.k1.hdfs.path = hdfs://node:8020/spooldir/files/%y-%m-%d/%H%M/
a1.sinks.k1.hdfs.filePrefix = events-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
a1.sinks.k1.hdfs.rollInterval = 3
a1.sinks.k1.hdfs.rollSize = 20
a1.sinks.k1.hdfs.rollCount = 5
a1.sinks.k1.hdfs.batchSize = 1
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#生成的檔案型別,默認是Sequencefile,可用DataStream,則為普通文本
a1.sinks.k1.hdfs.fileType = DataStream

# Use a channel which buffers events in memory
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

Channel引數解釋:
capacity:默認該通道中最大的可以存盤的event數量
trasactionCapacity:每次最大可以從source中拿到或者送到sink中的event數量
keep-alive:event添加到通道中或者移出的允許時間

啟動 Flume

bin/flume-ng agent -c ./conf -f ./conf/spooldir.conf -n a1 -Dflume.root.logger=INFO,console

上傳檔案到指定目錄

將不同的檔案上傳到下面目錄里面去,注意檔案不能重名
cd /export/servers/dirfile

采集檔案到 HDFS

業務系統使用log4j生成的日志,日志內容不斷增加,需要把追加到日志檔案中的資料實時采集到hdfs

根據需求,首先定義以下3大要素:

  • 采集源,即source——監控檔案內容更新 : exec ‘tail -F file’
  • 下沉目標,即sink——HDFS檔案系統 : hdfs sink
  • Source和sink之間的傳遞通道——channel,可用file channel 也可以用 記憶體channel

定義 Flume 組態檔

cd /export/servers/apache-flume-1.8.0-bin/conf
vim tail-file.conf
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1

# Describe/configure tail -F source1
agent1.sources.source1.type = exec
agent1.sources.source1.command = tail -F /export/servers/taillogs/access_log
agent1.sources.source1.channels = channel1

# Describe sink1
agent1.sinks.sink1.type = hdfs
#a1.sinks.k1.channel = c1
agent1.sinks.sink1.hdfs.path = hdfs://node01:8020/weblog/flume-collection/%y-%m-%d/%H-%
agent1.sinks.sink1.hdfs.filePrefix = access_log
agent1.sinks.sink1.hdfs.maxOpenFiles = 5000
agent1.sinks.sink1.hdfs.batchSize= 100
agent1.sinks.sink1.hdfs.fileType = DataStream
agent1.sinks.sink1.hdfs.writeFormat =Text
agent1.sinks.sink1.hdfs.round = true
agent1.sinks.sink1.hdfs.roundValue = 10
agent1.sinks.sink1.hdfs.roundUnit = minute
agent1.sinks.sink1.hdfs.useLocalTimeStamp = true

# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.keep-alive = 120
agent1.channels.channel1.capacity = 500000
agent1.channels.channel1.transactionCapacity = 600

# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1

啟動 Flume

cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin
bin/flume-ng agent -c conf -f conf/tail-file.conf -n agent1 -Dflume.root.logger=INFO,console

開發 Shell 腳本定時追加檔案內容

mkdir -p /export/servers/shells/
cd /export/servers/shells/
vim tail-file.sh

#!/bin/bash
while true
do
 date >> /export/servers/taillogs/access_log;
 sleep 0.5;
done

啟動腳本

# 創建檔案夾
mkdir -p /export/servers/taillogs
# 啟動腳本
sh /export/servers/shells/tail-file.sh

Agent級聯

第一個agent負責收集檔案當中的資料,通過網路發送到第二個agent當中去
第二個agent負責接收第一個agent發送的資料,并將資料保存到hdfs上面去

Node2安裝Flume

將第一臺機?上面解壓后的flume檔案夾拷貝到第二臺機?上面去
cd /export/servers
scp -r apache-flume-1.8.0-bin/ node2:$PWD

Node2配置Flume

在node2機?配置flume
cd /export/servers/ apache-flume-1.8.0-bin/conf
vim tail-avro-avro-logger.conf

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /export/servers/taillogs/access_log
a1.sources.r1.channels = c1

# Describe the sink
##sink端的avro是一個資料發送者
a1.sinks = k1
a1.sinks.k1.type = avro
a1.sinks.k1.channel = c1
a1.sinks.k1.hostname = 192.168.174.120
a1.sinks.k1.port = 4141
a1.sinks.k1.batch-size = 10

# Use a channel which buffers events in memory
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

開發腳本向檔案中寫入資料

直接將第一臺下面的腳本和資料拷貝到node2即可,第一臺機?上執行以下命令
cd /export/servers
scp -r shells/ taillogs/ node2:$PWD

第一臺Flume組態檔

在第一臺機?上開發flume的組態檔
cd /export/servers/apache-flume-1.8.0-bin/conf
vim avro-hdfs.conf

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
##source中的avro組件是一個接收者服務
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 192.168.xxx.xxx
a1.sources.r1.port = 6666

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://node01:8020/av /%y-%m-%d/%H%M/
a1.sinks.k1.hdfs.filePrefix = events-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
a1.sinks.k1.hdfs.rollInterval = 3
a1.sinks.k1.hdfs.rollSize = 20
a1.sinks.k1.hdfs.rollCount = 5
a1.sinks.k1.hdfs.batchSize = 1
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#生成的檔案型別,默認是Sequencefile,可用DataStream,則為普通文本
a1.sinks.k1.hdfs.fileType = DataStream

# Use a channel which buffers events in memory
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

順序啟動

第一臺機?啟動flume行程
cd /export/servers/apache-flume-1.8.0-bin
bin/flume-ng agent -c conf -f conf/avro-hdfs.conf -n a1 -Dflume.root.logger=INFO,console

node2機?啟動flume行程
cd /export/servers/apache-flume-1.8.0-bin/
bin/flume-ng agent -c conf -f conf/tail-avro-avro-logger.conf -n a1 -Dflume.root.logger

node2機?啟shell腳本生成檔案
cd /export/servers/shells
sh tail-file.sh

高可用方案

示例搭建一個高可用的Flume NG集群

角色分配

Flume的Agent和Collector分布如下表所示:

名稱HOST角色
Agent1node01Web Server
Collector1node02AgentMstr1
Collector2node03AgentMstr2

圖中所示,Agent1資料分別流入到Collector1和Collector2,Flume NG本身提供了Failover機制,可以
自動切換和恢復,有3個產生日志服務?分布在不同的機房,要把所有的日志都收集到一個
集群中存盤,

Node01安裝和配置

將flume安裝包以及檔案生產的兩個目錄拷貝到node01機?上面去

node02機?執行以下命令

cd /export/servers
scp -r apache-flume-1.8.0-bin/ node01:$PWD
scp -r shells/ taillogs/ node01:$PWD

node01機?配置agent的組態檔

cd /export/servers/apache-flume-1.8.0-bin/conf
vim agent.conf
#agent1 name
agent1.channels = c1
agent1.sources = r1
agent1.sinks = k1 k2

##set gruop
agent1.sinkgroups = g1

agent1.sources.r1.channels = c1
agent1.sources.r1.type = exec
agent1.sources.r1.command = tail -F /export/servers/taillogs/access_log

##set channel
agent1.channels.c1.type = memory
agent1.channels.c1.capacity = 1000
agent1.channels.c1.transactionCapacity = 100

## set sink1
agent1.sinks.k1.channel = c1
agent1.sinks.k1.type = avro
agent1.sinks.k1.hostname = node02
agent1.sinks.k1.port = 52020

## set sink2
agent1.sinks.k2.channel = c1
agent1.sinks.k2.type = avro
agent1.sinks.k2.hostname = node03
agent1.sinks.k2.port = 52020

##set sink group
agent1.sinkgroups.g1.sinks = k1 k2

##set failover
agent1.sinkgroups.g1.processor.type = failover
agent1.sinkgroups.g1.processor.priority.k1 = 10
agent1.sinkgroups.g1.processor.priority.k2 = 1
agent1.sinkgroups.g1.processor.maxpenalty = 10000

Node02 與 Node03 配置 FlumeCollection

node02機?修改組態檔

cd /export/servers/apache-flume-1.8.0-bin/conf
vim collector.conf
#set Agent name
a1.sources = r1
a1.channels = c1
a1.sinks = k1

##set channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

## other node,nna to nns
a1.sources.r1.type = avro
a1.sources.r1.bind = node02
a1.sources.r1.port = 52020
a1.sources.r1.channels = c1

##set sink to hdfs
a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path= hdfs://node01:8020/flume/failover/
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.writeFormat=TEXT
a1.sinks.k1.hdfs.rollInterval=10
a1.sinks.k1.channel=c1
a1.sinks.k1.hdfs.filePrefix=%Y-%m-%d

node03機?修改組態檔

cd /export/servers/apache-flume-1.8.0-bin/conf
vim collector.conf
#set Agent name
a1.sources = r1
a1.channels = c1
a1.sinks = k1

##set channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

## other node,nna to nns
a1.sources.r1.type = avro
a1.sources.r1.bind = node03
a1.sources.r1.port = 52020
a1.sources.r1.channels = c1

##set sink to hdfs
a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path= hdfs://node01:8020/flume/failover/
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.writeFormat=TEXT
a1.sinks.k1.hdfs.rollInterval=10
a1.sinks.k1.channel=c1
a1.sinks.k1.hdfs.filePrefix=%Y-%m-%d

順序啟動

node03機?上面啟動flume
cd /export/servers/apache-flume-1.8.0-bin
bin/flume-ng agent -n a1 -c conf -f conf/collector.conf -Dflume.root.logger=DEBUG,console

node02機?上面啟動flume
cd /export/servers/apache-flume-1.8.0-bin
bin/flume-ng agent -n a1 -c conf -f conf/collector.conf -Dflume.root.logger=DEBUG,console

node01機?上面啟動flume
cd /export/servers/apache-flume-1.8.0-bin
bin/flume-ng agent -n agent1 -c conf -f conf/agent.conf -Dflume.root.logger=DEBUG,console

node01機?啟動檔案產生腳本
cd /export/servers/shells
sh tail-file.sh

Flume 的負載均衡

負載均衡是用于解決一臺機?(一個行程)無法解決所有請求而產生的一種演算法,Load balancing Sink Processor 能夠實作 load balance 功能,如下圖Agent1 是一個路由節點,負責將 Channel 暫存的Event 均衡到對應的多個 Sink組件上,而每個 Sink 組件分別連接到一個獨立的 Agent 上,示例配置,如下所示:
在這里插入圖片描述
通過三臺機?來進行模擬flume的負載均衡
三臺機?規劃如下:
node01:采集資料,發送到node02和node03機?上去
node02:接收node01的部分資料
node03:接收node01的部分資料

步驟一:開發node01服務?的flume配置

node01服務?配置:

cd /export/servers/apache-flume-1.8.0-bin/conf
vim load_banlancer_client.conf
# agent name
<p class="mume-header " id="agent-name"></p>
a1.channels = c1
a1.sources = r1
a1.sinks = k1 k2

# set gruop
<p class="mume-header " id="set-gruop"></p>
a1.sinkgroups = g1

# set channel
<p class="mume-header " id="set-channel"></p>
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.sources.r1.channels = c1
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /export/servers/taillogs/access_log

# set sink1
<p class="mume-header " id="set-sink1"></p>
a1.sinks.k1.channel = c1
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = node02
a1.sinks.k1.port = 52020

# set sink2
<p class="mume-header " id="set-sink2"></p>
a1.sinks.k2.channel = c1
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = node03
a1.sinks.k2.port = 52020

# set sink group
<p class="mume-header " id="set-sink-group"></p>
a1.sinkgroups.g1.sinks = k1 k2

# set failover
<p class="mume-header " id="set-failover"></p>
a1.sinkgroups.g1.processor.type = load_balance
a1.sinkgroups.g1.processor.backoff = true
a1.sinkgroups.g1.processor.selector = round_robin
a1.sinkgroups.g1.processor.selector.maxTimeOut=10000

步驟二:開發node02服務?的flume配置

node02服務?配置:

cd /export/servers/apache-flume-1.8.0-bin/conf
vim load_banlancer_server.conf
# Name the components on this agent
<p class="mume-header " id="name-the-components-on-this-agent"></p>
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
<p class="mume-header " id="describeconfigure-the-source"></p>
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = node02
a1.sources.r1.port = 52020

# Describe the sink
<p class="mume-header " id="describe-the-sink"></p>
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
<p class="mume-header " id="use-a-channel-which-buffers-events-in-memory"></p>
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
<p class="mume-header " id="bind-the-source-and-sink-to-the-channel"></p>
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

步驟三:開發node03服務?flume配置

node03服務?配置

cd /export/servers/apache-flume-1.8.0-bin/conf
vim load_banlancer_server.conf
# Name the components on this agent
<p class="mume-header " id="name-the-components-on-this-agent-1"></p>
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
<p class="mume-header " id="describeconfigure-the-source-1"></p>
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = node03
a1.sources.r1.port = 52020

# Describe the sink
<p class="mume-header " id="describe-the-sink-1"></p>
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
<p class="mume-header " id="use-a-channel-which-buffers-events-in-memory-1"></p>
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
<p class="mume-header " id="bind-the-source-and-sink-to-the-channel-1"></p>
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

步驟四:準備啟動flume服務

啟動node03的flume服務
cd /export/servers/apache-flume-1.8.0-bin
bin/flume-ng agent -n a1 -c conf -f conf/load_banlancer_server.conf -Dflume.root.logger

啟動node02的flume服務
cd /export/servers/apache-flume-1.8.0-bin
bin/flume-ng agent -n a1 -c conf -f conf/load_banlancer_server.conf -Dflume.root.logger

啟動node01的flume服務
cd /export/servers/apache-flume-1.8.0-bin
bin/flume-ng agent -n a1 -c conf -f conf/load_banlancer_client.conf -Dflume.root.logger

步驟五:node01服務?運行腳本產生資料

cd /export/servers/shells
sh tail-file.sh

Flume案例

A、B兩臺日志服務機?實時生產日志主要型別為access.log、nginx.log、web.log,現在需要把A、B 機?中的access.log、nginx.log、web.log 采集匯總到C機?上然后統一收集到hdfs中,但是在hdfs中要求的目錄為:/source/logs/access/20210101/** /source/logs/nginx/20210101/** /source/logs/web/20210101/**

在這里插入圖片描述
在這里插入圖片描述
服務?A對應的IP為 192.168.174.1
服務?B對應的IP為 192.168.174.2
服務?C對應的IP為 192.168.174.3

采集端組態檔開發

node01與node02服務?開發flume的組態檔

cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf
vim exec_source_avro_sink.conf
# Name the components on this agent
<p class="mume-header " id="name-the-components-on-this-agent-2"></p>
a1.sources = r1 r2 r3
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
<p class="mume-header " id="describeconfigure-the-source-2"></p>
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /export/servers/taillogs/access.log
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = static
## static攔截?的功能就是往采集到的資料的header中插入自己定義的key-value對
<p class="mume-header " id="static攔截?的功能就是往采集到的資料的header中插入自己定義的key-value"></p>
a1.sources.r1.interceptors.i1.key = type
a1.sources.r1.interceptors.i1.value = access
a1.sources.r2.type = exec
a1.sources.r2.command = tail -F /export/servers/taillogs/nginx.log
a1.sources.r2.interceptors = i2
a1.sources.r2.interceptors.i2.type = static
a1.sources.r2.interceptors.i2.key = type
a1.sources.r2.interceptors.i2.value = nginx
a1.sources.r3.type = exec
a1.sources.r3.command = tail -F /export/servers/taillogs/web.log
a1.sources.r3.interceptors = i3
a1.sources.r3.interceptors.i3.type = static
a1.sources.r3.interceptors.i3.key = type
a1.sources.r3.interceptors.i3.value = web

# Describe the sink
<p class="mume-header " id="describe-the-sink-2"></p>
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = node03
a1.sinks.k1.port = 41414

# Use a channel which buffers events in memory
<p class="mume-header " id="use-a-channel-which-buffers-events-in-memory-2"></p>
a1.channels.c1.type = memory
a1.channels.c1.capacity = 20000
a1.channels.c1.transactionCapacity = 10000

# Bind the source and sink to the channel
<p class="mume-header " id="bind-the-source-and-sink-to-the-channel-2"></p>
a1.sources.r1.channels = c1
a1.sources.r2.channels = c1
a1.sources.r3.channels = c1
a1.sinks.k1.channel = c1

服務端組態檔開發

在node03上面開發flume組態檔

cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf
vim avro_source_hdfs_sink.conf
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# 定義source
<p class="mume-header " id="定義source"></p>
a1.sources.r1.type = avro
a1.sources.r1.bind = 192.168.174.3
a1.sources.r1.port =41414
# 添加時間攔截?
<p class="mume-header " id="添加時間攔截?"></p>
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder

# 定義channels
<p class="mume-header " id="定義channels"></p>
a1.channels.c1.type = memory
a1.channels.c1.capacity = 20000
a1.channels.c1.transactionCapacity = 10000

# 定義sink
<p class="mume-header " id="定義sink"></p>
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path=hdfs://192.168.174.1:8020/source/logs/%{type}/%Y%m%d
a1.sinks.k1.hdfs.filePrefix =events
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.writeFormat = Text
# 時間型別
<p class="mume-header " id="時間型別"></p>
a1.sinks.k1.hdfs.useLocalTimeStamp = true
# 生成的檔案不按條數生成
<p class="mume-header " id="生成的檔案不按條數生成"></p>
a1.sinks.k1.hdfs.rollCount = 0
# 生成的檔案按時間生成
<p class="mume-header " id="生成的檔案按時間生成"></p>
a1.sinks.k1.hdfs.rollInterval = 30
# 生成的檔案按大小生成
<p class="mume-header " id="生成的檔案按大小生成"></p>
a1.sinks.k1.hdfs.rollSize = 10485760
# 批量寫入hdfs的個數
<p class="mume-header " id="批量寫入hdfs的個數"></p>
a1.sinks.k1.hdfs.batchSize = 10000
# flume操作hdfs的執行緒數(包括新建,寫入等)
<p class="mume-header " id="flume操作hdfs的執行緒數包括新建寫入等"></p>
a1.sinks.k1.hdfs.threadsPoolSize=10
# 操作hdfs超時時間
<p class="mume-header " id="操作hdfs超時時間"></p>
a1.sinks.k1.hdfs.callTimeout=30000

# 組裝source、channel、sink
<p class="mume-header " id="組裝source-channel-sink"></p>
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

采集端檔案生成腳本

在node01與node02上面開發shell腳本,模擬資料生成

cd /export/servers/shells
vim server.sh
# !/bin/bash
<p class="mume-header " id="binbash"></p>
while true
do
	date >> /export/servers/taillogs/access.log;
	date >> /export/servers/taillogs/web.log;
	date >> /export/servers/taillogs/nginx.log;
	sleep 0.5;
done

順序啟動服務

node03啟動flume實作資料收集
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin
bin/flume-ng agent -c conf -f conf/avro_source_hdfs_sink.conf -name a1 -Dflume.root.logger=DEBUG,console

node01與node02啟動flume實作資料監控
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin
bin/flume-ng agent -c conf -f conf/exec_source_avro_sink.conf -name a1 -Dflume.root.logger=DEBUG,console

node01與node02啟動生成檔案腳本
cd /export/servers/shells
sh server.sh

在這里插入圖片描述

tips:解決中文亂碼

在這里插入圖片描述

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/417167.html

標籤:其他

上一篇:傳智健康day04 預約管理-套餐管理

下一篇:整合spingBoot + dubbo + zookeeper實作分布式開發應用

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more