Flume初体验

需求:从网络端口接受数据,输出到控制台
Agent选型:netcat+source + memory channel + logger sink

官网提供的配置

# example.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# Describe the sink
a1.sinks.k1.type = logger

# 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

参照上述官网的配置,新建simple-example.conf文件,配置如下
# Name the components on this agent
simple-agent.sources = netcat-source
simple-agent.sinks = logger-sink
simple-agent.channels = memory-channel

# Describe/configure the source
simple-agent.sources.netcat-source.type = netcat
simple-agent.sources.netcat-source.bind = Master
simple-agent.sources.netcat-source.port = 44444

# Describe the sink
simple-agent.sinks.logger-sink.type = logger

# Use a channel which buffers events in memory
simple-agent.channels.memory-channel.type = memory

# Bind the source and sink to the channel
simple-agent.sources.netcat-source.channels = memory-channel
simple-agent.sinks.logger-sink.channel = memory-channel

配置完成后,输入如下命令来启动flume

flume-ng agent \
--conf $FLUME_HOME/conf \
--name simple-agent \
--conf-file $FLUME_HOME/config/simple-example.conf \
-Dflume.root.logger=INFO,console

参数说明:
–conf:指定flume的配置文件所在目录
–name:指定Agent的名称
–conf-file:指定编写的flume配置文件
-Dflume.root.logger:指定日志级别

flume启动后,打印的日志中可以看到如下信息(部分日志)

Creating instance of source netcat-source, type netcat
Creating instance of sink: logger-sink, type: logger
Creating instance of channel memory-channel type memory
Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/192.168.242.150:44444]

输入jps命令可以查看到一个Application的进程,如果有这个进程,说明我们的flume启动成功了

[hadoop@Master ~]$ jps
3091 Jps
2806 Application
[hadoop@Master ~]$ jps -m
2806 Application --name simple-agent --conf-file /opt/flume/config/simple-example.conf
3101 Jps -m

测试(启动一个telnet进程,telnet 数据输入)

$ telnet Master 44444

查看Flume控制台的输出(Event是Flume数据传输的基本单元,由可选的header和一个byte array的数据构成)

Event: { headers:{} body: 68 65 6C 6C 6F 0D                               hello. }
Event: { headers:{} body: 66 6C 75 6D 65 0D                               flume. }

你可能感兴趣的:(Flume,Flume)