Hadoop Guide--Flume

Flume的官網(wǎng)地址:http://flume.apache.org/FlumeUserGuide.html#exec-source

source,sink,channel:https://www.iteblog.com/archives/948

簡介Flume:

Flume是Cloudera提供的一個高可用的,高可靠的,分布式的海量日志采集、聚合和傳輸系統(tǒng),F(xiàn)lume提供在日志采集系統(tǒng)中定制各類的數(shù)據(jù)發(fā)送方,用于接收數(shù)據(jù),同時提供對數(shù)據(jù)進(jìn)行簡單的處理,并寫到各個數(shù)據(jù)接收方中的過程。


流程結(jié)構(gòu):

Flume的主要結(jié)構(gòu)分為三部分:source,channel,sink;其中source是源頭,負(fù)責(zé)采集日志;channel是管道,負(fù)責(zé)傳輸和暫時的存儲;sink為目的地,將采集的日志保存起來;

根據(jù)需求對Flume的三部分進(jìn)行組合,構(gòu)成一個完整的agent,處理日志的傳輸;PS:agent為flume處理消息的單位,數(shù)據(jù)經(jīng)過agent進(jìn)行傳輸。


具體配置:

(啟動flume的服務(wù)要安裝JDK)

source:包括的配置為{Avro,Thrift,Exec,Spooling,...}

sink:包括的配置為{HDFS,Hive,Avro,Thrift,Logger,...}

channel:包括的配置為{Memory,JDBC,Kafka,F(xiàn)ile,...}

PS:具體的配置參考Flume的官網(wǎng)進(jìn)行查詢;

一個簡單的Flume的配置為:


Sample example:

# example.conf: A single-node Flume configuration

# Name the components on this agent

a1.sources = r1 #定義數(shù)據(jù)的入口

a1.sinks = k1 #定義數(shù)據(jù)的出口

a1.channels = c1 #定義管道

# Describe/configure the source

a1.sources.r1.type = netcat #定義數(shù)據(jù)源的類型

a1.sources.r1.bind = localhost #監(jiān)聽地址

a1.sources.r1.port = 44444 #監(jiān)聽端口

# Describe the sink

a1.sinks.k1.type = logger? ? ? #定義數(shù)據(jù)出口,出口類型

# 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


source源的配置:(常見配置)

1.Avro配置:需要配置-channels,type,bind,port四組參數(shù);

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = avro #type為組件的名稱,需要填寫avro,avro方式使用RPC方式接收,故此需要端口號

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.bind = 0.0.0.0#限制接收數(shù)據(jù)的發(fā)送方ID,0.0.0.0是接收任何IP,不做限制

a1.sources.r1.port = 4141 #接收端口(與flume的客戶端的sink相呼應(yīng))

Avro的配置的話需要:需要在客戶端和接收端都要配置相應(yīng)的Avro配置才可。

2.exec source配置:可以通過指定操作對日志進(jìn)行讀取,使用exec時需要指定shell命令,對日志進(jìn)行讀取;exce的配置就是設(shè)定一個Linux命令,通過這個命令不斷的傳輸數(shù)據(jù);我們使用命令去查看tail -F 命令去查看日志的尾部;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = exce #type為組件的名稱,采用命令行的方式進(jìn)行讀取數(shù)據(jù)

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.command = tail -F /var/log/secure #監(jiān)控查看日志的尾部進(jìn)行輸出的操作

3.spooling-directory source配置:spo_dir可以讀取文件夾里的日志,使用時指定一個文件夾,可以讀取文件夾中的所有文件,該文件夾下的文件不可以進(jìn)行再打開編輯的操作,spool的目錄下不可包含相應(yīng)的子目錄;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = spooldir #type為組件的名稱,需要填寫spooldir為spool類型

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.spoolDir = /home/hadoop/flume/logs #spool接收的目錄信息

4.Syslogtcp source配置:Syslogtcp監(jiān)聽tcp端口作為數(shù)據(jù)源;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = syslogtcp #type為組件的名稱,需要填寫syslogtcp,監(jiān)聽端口號dd

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.port = 5140 #端口號

a1.sources.r1.host = localhost #發(fā)送方的IP地址

5.HTTP Source配置:是HTTP POST和GET來發(fā)送事件數(shù)據(jù),使用Hander程序?qū)崿F(xiàn)轉(zhuǎn)換;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = http #type為組件的名稱,需要填寫http類型

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.handler= org.example.rest.RestHandler

a1.sources.r1.handler.nickname=random.props

sink源的配置:(常見配置)

sink會消費(fèi)channel中的數(shù)據(jù),然后送給外部數(shù)據(jù)源或者source;

1.Hive sink:hive的數(shù)據(jù)是只限制了text和JSON數(shù)據(jù)直接在hive的表中或partition中;

hive的sink的主要參數(shù)詳解:

type:構(gòu)建的類型的名字,此處填寫hive;

hive.metastore:Hive metastore的URL;

hive.database:Hive database 名字;

hive table:Hive table名字;

使用hive的額話需要進(jìn)行先創(chuàng)建表的過程:

create table weblogs ( id int , msg string )

partitioned by (continent string, country string, time string)

clustered by (id) into 5 buckets

stored as orc;

a1.channels = c1

a1.channels.c1.type = memory

a1.sinks = k1

a1.sinks.k1.type = hive

a1.sinks.k1.channel = c1

a1.sinks.k1.hive.metastore = thrift://127.0.0.1:9083

a1.sinks.k1.hive.database = logsdb

a1.sinks.k1.hive.table = weblogs

a1.sinks.k1.hive.partition = asia,%{country},%y-%m-%d-%H-%M

a1.sinks.k1.useLocalTimeStamp = false

a1.sinks.k1.round = true

a1.sinks.k1.roundValue = 10

a1.sinks.k1.roundUnit = minute

a1.sinks.k1.serializer = DELIMITED

a1.sinks.k1.serializer.delimiter = "\t"

a1.sinks.k1.serializer.serdeSeparator = '\t'

a1.sinks.k1.serializer.fieldnames =id,,msg

2.Logger Sink:Logs是INFO level,This sink is the only exception which doesn’t require the extra configuration explained in the Logging raw data section.

a1.channels = c1

a1.sinks = k1

a1.sinks.k1.type = logger

a1.sinks.k1.channel = c1

3.Avro Sink:

需要配置hostname和port,需要在兩端都要安裝Avro的客戶端:

type:組件名稱,此處填寫Avro;

hostname和port:填寫地址;

a1.channels = c1

a1.sinks = k1

a1.sinks.k1.type = avro

a1.sinks.k1.channel = c1

a1.sinks.k1.hostname = 10.10.10.10

a1.sinks.k1.port = 4545

4.Kafka Sink:

a1.sinks.k1.channel = c1

a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink

a1.sinks.k1.kafka.topic = mytopic

a1.sinks.k1.kafka.bootstrap.servers = localhost:9092

a1.sinks.k1.kafka.flumeBatchSize = 20

a1.sinks.k1.kafka.producer.acks = 1

a1.sinks.k1.kafka.producer.linger.ms = 1

a1.sinks.ki.kafka.producer.compression.type = snappy

Channel 配置:(常見配置)

1.Memory Chanel:

使用Memory作為中間的緩存;

a1.channels = c1

a1.channels.c1.type = memory

a1.channels.c1.capacity = 10000

a1.channels.c1.transactionCapacity = 10000

a1.channels.c1.byteCapacityBufferPercentage = 20

a1.channels.c1.byteCapacity = 800000

2.JDBC Channel:

a1.channels = c1

a1.channels.c1.type = jdbc

3.Kafka Channel:

a1.channels.channel1.type = org.apache.flume.channel.kafka.KafkaChannel

a1.channels.channel1.kafka.bootstrap.servers = kafka-1:9092,kafka-2:9092,kafka-3:9092

a1.channels.channel1.kafka.topic = channel1

a1.channels.channel1.kafka.consumer.group.id = flume-consumer

4.File Channel:

a1.channels = c1

a1.channels.c1.type = file

a1.channels.c1.checkpointDir = /mnt/flume/checkpoint

a1.channels.c1.dataDirs = /mnt/flume/data


source源的配置:(常見配置)

1.Avro配置:需要配置-channels,type,bind,port四組參數(shù);

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = avro #type為組件的名稱,需要填寫avro,avro方式使用RPC方式接收,故此需要端口號

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.bind = 0.0.0.0#限制接收數(shù)據(jù)的發(fā)送方ID,0.0.0.0是接收任何IP,不做限制

a1.sources.r1.port = 4141 #接收端口(與flume的客戶端的sink相呼應(yīng))

Avro的配置的話需要:需要在客戶端和接收端都要配置相應(yīng)的Avro配置才可。

2.exec source配置:可以通過指定操作對日志進(jìn)行讀取,使用exec時需要指定shell命令,對日志進(jìn)行讀取;exce的配置就是設(shè)定一個Linux命令,通過這個命令不斷的傳輸數(shù)據(jù);我們使用命令去查看tail -F 命令去查看日志的尾部;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = exce #type為組件的名稱,采用命令行的方式進(jìn)行讀取數(shù)據(jù)

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.command = tail -F /var/log/secure #監(jiān)控查看日志的尾部進(jìn)行輸出的操作

3.spooling-directory source配置:spo_dir可以讀取文件夾里的日志,使用時指定一個文件夾,可以讀取文件夾中的所有文件,該文件夾下的文件不可以進(jìn)行再打開編輯的操作,spool的目錄下不可包含相應(yīng)的子目錄;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = spooldir #type為組件的名稱,需要填寫spooldir為spool類型

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.spoolDir = /home/hadoop/flume/logs #spool接收的目錄信息

4.Syslogtcp source配置:Syslogtcp監(jiān)聽tcp端口作為數(shù)據(jù)源;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = syslogtcp #type為組件的名稱,需要填寫syslogtcp,監(jiān)聽端口號dd

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.port = 5140 #端口號

a1.sources.r1.host = localhost #發(fā)送方的IP地址

5.HTTP Source配置:是HTTP POST和GET來發(fā)送事件數(shù)據(jù),使用Hander程序?qū)崿F(xiàn)轉(zhuǎn)換;

a1.sources = r1

a1.channels = c1

a1.sources.r1.type = http #type為組件的名稱,需要填寫http類型

a1.sources.r1.channels = c1 #匹配agent創(chuàng)建的channel即可

a1.sources.r1.handler= org.example.rest.RestHandler

a1.sources.r1.handler.nickname=random.props

sink源的配置:(常見配置)

sink會消費(fèi)channel中的數(shù)據(jù),然后送給外部數(shù)據(jù)源或者source;

1.Hive sink:hive的數(shù)據(jù)是只限制了text和JSON數(shù)據(jù)直接在hive的表中或partition中;

hive的sink的主要參數(shù)詳解:

type:構(gòu)建的類型的名字,此處填寫hive;

hive.metastore:Hive metastore的URL;

hive.database:Hive database 名字;

hive table:Hive table名字;

使用hive的額話需要進(jìn)行先創(chuàng)建表的過程:

create table weblogs ( id int , msg string )

partitioned by (continent string, country string, time string)

clustered by (id) into 5 buckets

stored as orc;

a1.channels = c1

a1.channels.c1.type = memory

a1.sinks = k1

a1.sinks.k1.type = hive

a1.sinks.k1.channel = c1

a1.sinks.k1.hive.metastore = thrift://127.0.0.1:9083

a1.sinks.k1.hive.database = logsdb

a1.sinks.k1.hive.table = weblogs

a1.sinks.k1.hive.partition = asia,%{country},%y-%m-%d-%H-%M

a1.sinks.k1.useLocalTimeStamp = false

a1.sinks.k1.round = true

a1.sinks.k1.roundValue = 10

a1.sinks.k1.roundUnit = minute

a1.sinks.k1.serializer = DELIMITED

a1.sinks.k1.serializer.delimiter = "\t"

a1.sinks.k1.serializer.serdeSeparator = '\t'

a1.sinks.k1.serializer.fieldnames =id,,msg

2.Logger Sink:Logs是INFO level,This sink is the only exception which doesn’t require the extra configuration explained in the Logging raw data section.

a1.channels = c1

a1.sinks = k1

a1.sinks.k1.type = logger

a1.sinks.k1.channel = c1

3.Avro Sink:

需要配置hostname和port,需要在兩端都要安裝Avro的客戶端:

type:組件名稱,此處填寫Avro;

hostname和port:填寫地址;

a1.channels = c1

a1.sinks = k1

a1.sinks.k1.type = avro

a1.sinks.k1.channel = c1

a1.sinks.k1.hostname = 10.10.10.10

a1.sinks.k1.port = 4545

4.Kafka Sink:

a1.sinks.k1.channel = c1

a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink

a1.sinks.k1.kafka.topic = mytopic

a1.sinks.k1.kafka.bootstrap.servers = localhost:9092

a1.sinks.k1.kafka.flumeBatchSize = 20

a1.sinks.k1.kafka.producer.acks = 1

a1.sinks.k1.kafka.producer.linger.ms = 1

a1.sinks.ki.kafka.producer.compression.type = snappy

Channel 配置:(常見配置)

1.Memory Chanel:

使用Memory作為中間的緩存;

a1.channels = c1

a1.channels.c1.type = memory

a1.channels.c1.capacity = 10000

a1.channels.c1.transactionCapacity = 10000

a1.channels.c1.byteCapacityBufferPercentage = 20

a1.channels.c1.byteCapacity = 800000

2.JDBC Channel:

a1.channels = c1

a1.channels.c1.type = jdbc

3.Kafka Channel:

a1.channels.channel1.type = org.apache.flume.channel.kafka.KafkaChannel

a1.channels.channel1.kafka.bootstrap.servers = kafka-1:9092,kafka-2:9092,kafka-3:9092

a1.channels.channel1.kafka.topic = channel1

a1.channels.channel1.kafka.consumer.group.id = flume-consumer

4.File Channel:

a1.channels = c1

a1.channels.c1.type = file

a1.channels.c1.checkpointDir = /mnt/flume/checkpoint

a1.channels.c1.dataDirs = /mnt/flume/data

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,401評論 6 531
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,011評論 3 413
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,263評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,543評論 1 307
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 71,323評論 6 404
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 54,874評論 1 321
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 42,968評論 3 439
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,095評論 0 286
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,605評論 1 331
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 40,551評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 42,720評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,242評論 5 355
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 43,961評論 3 345
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,358評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,612評論 1 280
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,330評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 47,690評論 2 370

推薦閱讀更多精彩內(nèi)容

  • 常用的source1.1 nettcat1.2 Avro Source1.3 Exec Source1.4 spo...
    水他閱讀 1,760評論 0 50
  • Flume的功能和架構(gòu)特點(diǎn) ** 功能 **flume 是一個分布式的,可靠的,可用的,可以非常有效率的對大數(shù)據(jù)的...
    心_的方向閱讀 2,528評論 1 10
  • 這里主要介紹幾種常見的日志的source來源,包括監(jiān)控文件型,監(jiān)控文件內(nèi)容增量,TCP和HTTP。 Spool類型...
    歡醉閱讀 1,408評論 0 10
  • kafka 集群開啟kafka服務(wù):nohup bin/kafka-server-start.sh config/...
    夙夜M閱讀 1,439評論 0 0
  • 1. Flume簡介 Apache Flume是一個分布式的、可靠的、可用的,從多種不同的源收集、聚集、移動大量日...
    奉先閱讀 4,507評論 2 5