數(shù)據(jù)(日志)采集
數(shù)據(jù)從A服務(wù)器到B服務(wù)器?
簡單方式:
1)數(shù)據(jù)量小 ?命令 scp xxx
2)開發(fā)java/python代碼 實(shí)現(xiàn)日志收集,還需要寫監(jiān)控健壯性的代碼,麻煩
缺點(diǎn):場景變了,代碼需要改寫;監(jiān)控代碼
3)一般自己寫的代碼適合場景比較單一。
flume能實(shí)現(xiàn)的是:
把A服務(wù)器的數(shù)據(jù)收集到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是分布式高可用有效收集、聚合、移動大量日志數(shù)據(jù)的服務(wù)。
It uses a simple extensible data model that allows for online analytic application.
它使用一個簡單可擴(kuò)展的數(shù)據(jù)模型使得在線分析應(yīng)用程序可以被支持。

Flume只有一個角色:Agent,類似于kafka中broker
Agent有三個部分:
source:用來采集數(shù)據(jù)(類似于kafka中producer)并發(fā)送數(shù)據(jù)到channel
sink:從channel中獲取數(shù)據(jù),并向HDFS寫數(shù)據(jù)
channel:信道,連接source和sink

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.

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.
案例一:

具備監(jiān)控目錄功能的source:spooling dirctory
可以將數(shù)據(jù)展示在屏幕上的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、組合三部分之間的關(guān)系
連接條件:channels channel?
運(yùn)行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分為三個部分?
因?yàn)榉譃槿齻€部分,可以實(shí)現(xiàn)隨機(jī)組合。
比如:source可以監(jiān)控各種目錄
sink可以輸出數(shù)據(jù)到各種平臺
channel可以是內(nèi)存,也可以是磁盤
需求2:查看tomcat.log中最新的日志
tail -f tomcat.log
于是有exec source
必配三個參數(shù)
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分鐘新產(chǎn)生一個目錄,以時間結(jié)尾的目錄

hdfs.useLocalTimeStamp=true 使用本機(jī)時間
hdfs.fileType=DataStream 數(shù)據(jù)流

tail -F:關(guān)心的是文件名
tail -f:關(guān)心的是文件獨(dú)一無二的id號
日志回滾時文件id號不變,只是文件名的后綴時間變了,因此必須用tail -F
運(yùn)行
bin/flume-ng agent --conf conf --conf-file conf/tailcat.properties --name a1 -Dflume.root.logger=INFO,console
數(shù)據(jù)倉庫的分層
ODS DM DW
