數據(日志)采集
數據從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只有一個角色:Agent,類似于kafka中broker
Agent有三個部分:
source:用來采集數據(類似于kafka中producer)并發送數據到channel
sink:從channel中獲取數據,并向HDFS寫數據
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.
案例一:
具備監控目錄功能的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 數據流
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