flume筆記

flume 安裝后基本的測試驗證:

配置

source 使用 necat 類型,sink 采用 file_roll 類型, 從監聽端口獲取數據,保存到本地文件。 拷貝配置模板:

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

功能驗證

1.建立輸出目錄

mkdir -p /tmp/log/flume

2.啟動服務

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

運行日志位于logs目錄,或者啟動時添加-Dflume.root.logger=INFO,console 選項前臺啟動,輸出打印日志,查看具體運行日志,服務異常時查原因。

3.發送數據

telnet localhost 8888

輸入

helloworld!hello Flume!

4.查看數據文件 查看 /tmp/log/flume 目錄文件:

# 文件名不同,需要根據實際情況修改和查看

cat /tmp/log/flume/1447671188760-2

hello world!hello Flume!

在修改配置后,一定要重啟flume,否則配置無效。啟動flume之后,與端口進行了綁定。再通過telnet向指定端口發送數據。假如,首先發送數據,然后配置重啟flume,會報異常 org.apache.flume.FlumeException: java.net.BindException: Address already in use。

原因解析:如果首先發送數據,則發送端與該端口建立起了一個socket連接。當此時使用flume的netcat監聽端口獲取數據,則無法實現端口綁定。

雖然會一直報異常,但是對應的文件仍然會以一定的時間間隔生成或者文本大小生成。

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

推薦閱讀更多精彩內容