flume

數據(日志)采集

數據從A服務器到B服務器?

簡單方式:

1)數據量小 ?命令 scp xxx

2)開發java/python代碼 實現日志收集,還需要寫監控健壯性的代碼,麻煩

缺點:場景變了,代碼需要改寫;監控代碼

3)一般自己寫的代碼適合場景比較單一。

flume能實現的是:

把A服務器的數據收集到B,只需通過配置文件就可以了。


Flume的版本:

Flume OG 0.9

FLume NG 1.x(工作中使用的版本)

版本:flume-ng-1.5.0-cdh5.2.0.tar


Flume的組成:

sqoop,azkaban,kafka,flume--小工具,具體場景下還需研究

flume:Flume is a distributed, reliable, and available service for efficiently collecting, aggregating, and moving large amounts of log data.

flume是分布式高可用有效收集、聚合、移動大量日志數據的服務。

It uses a simple extensible data model that allows for online analytic application.

它使用一個簡單可擴展的數據模型使得在線分析應用程序可以被支持。

Flume的組成

Flume只有一個角色:Agent,類似于kafka中broker

Agent有三個部分:

source:用來采集數據(類似于kafka中producer)并發送數據到channel

sink:從channel中獲取數據,并向HDFS寫數據

channel:信道,連接source和sink


flume集群

In order to flow the data across multiple agents or hops, the sink of the previous agent and source of the current hop need to be avro type with the sink pointing to the hostname (or IP address) and port of the source.

A very common scenario in log collection is a large number of log producing clients sending data to a few consumer agents that are attached to the storage subsystem. For example, logs collected from hundreds of web servers sent to a dozen of agents that write to HDFS cluster.


多臺flume收集數據并整合

This can be achieved in Flume by configuring a number of first tier agents with an avro sink, all pointing to an avro source of single agent (Again you could use the thrift sources/sinks/clients in such a scenario). This source on the second tier agent consolidates the received events into a single channel which is consumed by a sink to its final destination.


案例一:


flume業務場景下的配置和使用

具備監控目錄功能的source:spooling dirctory

可以將數據展示在屏幕上的sink

配置文件后綴必須是properties

1、定義角色 a1 ?a1.sources ?a1.channels a1.sinks

2、配置一個spooldir類型的source

固定格式:a1.sources.r1.type=spooldir

3、配置channels

4、配置sink

首先配置logger sink 指定打印日志級別為打印到控制臺

5、組合三部分之間的關系

連接條件:channels channel?


運行flume

bin/flume-ng agent --conf conf --conf-file conf/spooldir.properties --name a1 -Dflume.root.logger=INFO,console

--conf-file:指定我們的properties配置文件

--name a1:配置文件中的agent的名字

-Dflume.root.logger=INFO,console :表示打印到控制臺


問題:為什么有一個agent分為三個部分?

因為分為三個部分,可以實現隨機組合。

比如:source可以監控各種目錄

sink可以輸出數據到各種平臺

channel可以是內存,也可以是磁盤


需求2:查看tomcat.log中最新的日志

tail -f tomcat.log

于是有exec source

必配三個參數

type:exec?

command :tail -F ?/home/hadoop/flume1705/tomcat.log

channel--配在最后

sink

type :hdfs

hdfs.path ? ? ?/bigdata/%y-%m-%d/%H%M

hdfs.filePrefix=aura-

目錄是否回滾:以下配置表示每10分鐘回滾一次

回滾即每個一段時間會合并和刪除一些日志。

hdfs.round=true?

hdfs.roundValue=10

hdfs.roundUnit=minute

每隔10分鐘新產生一個目錄,以時間結尾的目錄


回滾文件參數說明

hdfs.useLocalTimeStamp=true 使用本機時間

hdfs.fileType=DataStream 數據流


exec source的運用

tail -F:關心的是文件名

tail -f:關心的是文件獨一無二的id號

日志回滾時文件id號不變,只是文件名的后綴時間變了,因此必須用tail -F

運行

bin/flume-ng agent --conf conf --conf-file conf/tailcat.properties --name a1 -Dflume.root.logger=INFO,console


數據倉庫的分層

ODS DM DW


一個項目中所用技術和場合
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 博客原文 翻譯作品,水平有限,如有錯誤,煩請留言指正。原文請見 官網英文文檔 引言 概述 Apache Flume...
    rabbitGYK閱讀 11,538評論 13 34
  • Flume的官網地址:http://flume.apache.org/FlumeUserGuide.html#ex...
    24格的世界閱讀 926評論 0 1
  • 七月,開始了人生中第一次正經的工作,卻一直拖到八月底才來回顧這段經歷,想想從前的自己,每一天都有迫不及待想要記錄的...
    毛阿瑩閱讀 271評論 0 0
  • 自9日以來,沒有在凌晨一點前睡的。今早起來,哪哪都不舒服,尤其頭和胃:頭痛欲裂,胃疼,感覺里面有亂七八糟的柴草堆。...
    果菲的世界閱讀 531評論 0 0
  • 自古以來,不管是東方人還是西方人,都非常重視早餐。人們認為,早餐是一天中第一餐,也是最重要的一餐。 然而,隨著經濟...
    Zermatt閱讀 4,007評論 0 0