flume筆記

flume 安裝后基本的測(cè)試驗(yàn)證:

配置

source 使用 necat 類型,sink 采用 file_roll 類型, 從監(jiān)聽(tīng)端口獲取數(shù)據(jù),保存到本地文件。 拷貝配置模板:

cp conf/flume-conf.properties.template conf/flume-conf.properties

編輯配置如下:

# The configuration file needs to define the sources,

# the channels and the sinks.

# Sources, channels and sinks are defined per agent,

# in this case called 'agent'

agent.sources = r1

agent.channels = c1

agent.sinks = s1

# For each one of the sources, the type is defined

agent.sources.r1.type = netcat

agent.sources.r1.bind = localhost

agent.sources.r1.port = 8888

# The channel can be defined as follows.

agent.sources.r1.channels = c1

# Each sink's type must be defined

agent.sinks.s1.type = file_roll

agent.sinks.s1.sink.directory = /tmp/log/flume

#Specify the channel the sink should use

agent.sinks.s1.channel = c1

# Each channel's type is defined.

agent.channels.c1.type = memory

# Other config values specific to each type of channel(sink or source)

# can be defined as well

# In this case, it specifies the capacity of the memory channel

agent.channels.c1.capacity = 100

功能驗(yàn)證

1.建立輸出目錄

mkdir -p /tmp/log/flume

2.啟動(dòng)服務(wù)

bin/flume-ng agent --conf conf -f conf/flume-conf.properties -n agent&

運(yùn)行日志位于logs目錄,或者啟動(dòng)時(shí)添加-Dflume.root.logger=INFO,console 選項(xiàng)前臺(tái)啟動(dòng),輸出打印日志,查看具體運(yùn)行日志,服務(wù)異常時(shí)查原因。

3.發(fā)送數(shù)據(jù)

telnet localhost 8888

輸入

helloworld!hello Flume!

4.查看數(shù)據(jù)文件 查看 /tmp/log/flume 目錄文件:

# 文件名不同,需要根據(jù)實(shí)際情況修改和查看

cat /tmp/log/flume/1447671188760-2

hello world!hello Flume!

在修改配置后,一定要重啟flume,否則配置無(wú)效。啟動(dòng)flume之后,與端口進(jìn)行了綁定。再通過(guò)telnet向指定端口發(fā)送數(shù)據(jù)。假如,首先發(fā)送數(shù)據(jù),然后配置重啟flume,會(huì)報(bào)異常 org.apache.flume.FlumeException: java.net.BindException: Address already in use。

原因解析:如果首先發(fā)送數(shù)據(jù),則發(fā)送端與該端口建立起了一個(gè)socket連接。當(dāng)此時(shí)使用flume的netcat監(jiān)聽(tīng)端口獲取數(shù)據(jù),則無(wú)法實(shí)現(xiàn)端口綁定。

雖然會(huì)一直報(bào)異常,但是對(duì)應(yīng)的文件仍然會(huì)以一定的時(shí)間間隔生成或者文本大小生成。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容