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监听端口获取数据,则无法实现端口绑定。
虽然会一直报异常,但是对应的文件仍然会以一定的时间间隔生成或者文本大小生成。