Flume總結(1)--單個agent採集的基本配置

来源:http://www.cnblogs.com/tianjun2012/archive/2017/05/08/6825066.html
-Advertisement-
Play Games

一、日誌採集:從網路埠接收數據,下沉到logger 文件netcat-logger.conf: 啟動命令:#告訴flum啟動一個agent,指定配置參數, --name:agent的名字,flume-ng agent --conf conf --conf-file conf/netcat-logg ...


一、日誌採集:從網路埠接收數據,下沉到logger

文件netcat-logger.conf:

 1 # Name the components on this agent
 2 #給那三個組件取個名字
 3 a1.sources = r1
 4 a1.sinks = k1
 5 a1.channels = c1
 6 
 7 # Describe/configure the source
 8 #類型, 從網路埠接收數據,在本機啟動, 所以localhost, type=spoolDir採集目錄源,目錄里有就採
 9 a1.sources.r1.type = netcat
10 a1.sources.r1.bind = localhost
11 a1.sources.r1.port = 44444
12 
13 # Describe the sink
14 a1.sinks.k1.type = logger
15 
16 # Use a channel which buffers events in memory
17 #下沉的時候是一批一批的, 下沉的時候是一個個eventChannel參數解釋:
18 #capacity:預設該通道中最大的可以存儲的event數量
19 #trasactionCapacity:每次最大可以從source中拿到或者送到sink中的event數量
20 a1.channels.c1.type = memory
21 a1.channels.c1.capacity = 1000
22 a1.channels.c1.transactionCapacity = 100
23 
24 # Bind the source and sink to the channel
25 a1.sources.r1.channels = c1
26 a1.sinks.k1.channel = c1

啟動命令:
#告訴flum啟動一個agent,指定配置參數, --name:agent的名字,
flume-ng agent --conf conf --conf-file conf/netcat-logger.conf --name a1 -Dflume.root.logger=INFO,console

傳入數據:

[root@mini03 ~]# telnet localhost 44444

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello world!^H^H^H^H^H^H^H^H^H^H^H^H^H^H
OK
tianjun2012!
OK
控制台看到的數據
2017-05-08 13:41:35,766 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:94)] Event: { headers:{} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 21 08 08 08 08 hello world!.... }
2017-05-08 13:41:40,153 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:94)] Event: { headers:{} body: 74 69 61 6E 6A 75 6E 32 30 31 32 21 0D tianjun2012!. }

 二、監視文件夾

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

測試: 往/home/hadoop/flumespool放文件(mv ././xxxFile /home/hadoop/flumeSpool),但是不要在裡面生成文件

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

# Describe/configure the source
#監聽目錄,spoolDir指定目錄, fileHeader要不要給文件夾前墜名
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /home/hadoop/flumespool
a1.sources.r1.fileHeader = true

# Describe the sink
a1.sinks.k1.type = logger

# 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

三、用tail命令獲取數據,下沉到hdfs

 1 # Name the components on this agent
 2 a1.sources = r1
 3 a1.sinks = k1
 4 a1.channels = c1
 5 
 6 # Describe/configure the source
 7 a1.sources.r1.type = exec
 8 a1.sources.r1.command = tail -F /home/hadoop/log/test.log
 9 a1.sources.r1.channels = c1
10 
11 # Describe the sink
12 a1.sinks.k1.type = hdfs
13 a1.sinks.k1.channel = c1
14 a1.sinks.k1.hdfs.path = hdfs://mini01:9000/flume/events/%y-%m-%d/%H%M/
15 a1.sinks.k1.hdfs.filePrefix = events-
16 a1.sinks.k1.hdfs.round = true
17 a1.sinks.k1.hdfs.roundValue = 10
18 a1.sinks.k1.hdfs.roundUnit = minute
19 a1.sinks.k1.hdfs.rollInterval = 3
20 a1.sinks.k1.hdfs.rollSize = 20
21 a1.sinks.k1.hdfs.rollCount = 5
22 a1.sinks.k1.hdfs.batchSize = 1
23 a1.sinks.k1.hdfs.useLocalTimeStamp = true
24 #生成的文件類型,預設是Sequencefile,可用DataStream,則為普通文本
25 a1.sinks.k1.hdfs.fileType = DataStream
26 
27 
28 
29 # Use a channel which buffers events in memory
30 a1.channels.c1.type = memory
31 a1.channels.c1.capacity = 1000
32 a1.channels.c1.transactionCapacity = 100
33 
34 # Bind the source and sink to the channel
35 a1.sources.r1.channels = c1
36 a1.sinks.k1.channel = c1

啟動命令:
flume-ng agent -c conf -f conf/tail-hdfs.conf -n a1

模擬寫入日誌:

1 [root@mini03 log]# i=1;
2 while(( $i<=500000 ));
3  do echo $i >> /home/hadoop/log/test.log;
4  sleep 0.5; 
5 let 'i++';done

查看hdfs上的文件內容

 1 [root@mini01 ~]# hdfs dfs -cat /flume/events/17-05-08/1530/*
 2 1
 3 2
 4 3
 5 4
 6 5
 7 6
 8 7
 9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
21 20

註意,本例中,為了快速看到效果,這個值都設置比較小,真實情況需要調整

a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.rollInterval = 3
a1.sinks.k1.hdfs.rollSize = 20
a1.sinks.k1.hdfs.rollCount = 5
22 a1.sinks.k1.hdfs.batchSize = 1


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • #####集合的一些常用方法#####list1=set([1,2,3,4])list2=set([1,2,3,4,5,6])###集合的交集(返回兩個集合裡面共同有的部分){1, 2, 3, 4}print(list1.intersection(list2))###集合的並集(返回合併兩個集合去掉 ...
  • //如果表達式以一個字元串起頭,那麼後續所有操作數必須是字元串類型 //thinking in java 書中p53 3.13 字元串操作符+和+= import static net.mindview.util.Print.*;public class StringOperators { publ ...
  • 1.下載好jdk1.8.0版本或以上版本 2.配置JAVA_HOME,CLASSPATH,PATH 其中JAVA_HOME必須的 2.1 JAVA_HOME=E:\java\jdk1.8.0_77 2.2 CLASSPATH(告訴java程式運行時,你的類或者類庫在哪裡) (a).; E:\java ...
  • 1.用例情景 1)定義一個鬧鐘(目標類),裡面我們感興趣的是時間值times,當times大於9.15時,通知觀察者。 2)定義兩個觀察者,userA,userB,當收到times值時,作出判斷,當times值大於9.30的時候就作出反映(列印一天出發的消息)。 2.設計思路 1)定義兩個介面 2) ...
  • 1 #include 2 #include 3 4 using namespace std; 5 6 7 class STAbstractProductA 8 { 9 public: 10 virtual void use() = 0; 11 }; 12 13 class STProductA1: ... ...
  • 起源 user 在插著 充電器 打電話的狀況下, 為了安全起見, 避免 充電器在這時損害手機,間接造成 user 的傷害, 而有了這 feature, 在 battery voltage Vbat 4V 時,不充電; 在 battery voltage Vbat V_CC2TOPOFF_THRES) ...
  • Zookeeper是一個分散式應用程式協調服務,功能包含:配置管理、名字服務、分散式鎖、集群管理等,適合使用在讀多於寫的操作。 1. 配置管理 分散式系統都有好多機器,比如我在搭建hadoop的HDFS的時候,需要在一個主機器上(Master節點)配置好HDFS需要的各種配置文件,然後通過scp命令 ...
  • 驚悚!異能者為了美女居然..... 備忘錄模式(Memento): 在不破壞封閉的前提下, 捕獲一個對象的內部狀態, 併在該對象之外保存這個狀態. 這樣以後就可將該對象恢復到原先保存的狀態. 備忘者模式優點: 發起人備份狀態不需要自己管理, 可以備份到外部, 這樣可以很好的保持封裝的邊界, 這樣做的 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...