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í)間間隔生成或者文本大小生成。