Flume的使用

1)编写example.conf文件(可以写在任意位置)

# example.conf: A single-node Flume configuration

# Name the components on this agent
#agent的名称.sources/sinks/channels = source_name/sink_mame/channel_name
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the sources
#agent_name.sources(多个sourse源).source_name(指定一个source).type(类型) 
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# Describe the sink
#agent_name.sinks(多个sink源).sink_name(指定一个sink).type(类型) 
#logger:控制台
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
#agent_name.channels(多个channel源).channel_name(指定一个channel).type(类型) 
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
#将sources、channels、sinks串联起来
#指定agent的source的channels
#指定agent的sink的channel
#注意单复数的问题,一个source可以对应多个channel,一个sink只能对应一个channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

2)启动flume

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

说明:
agent:command值
--name:指定agent的名称(自定义)
--conf:指定flume配置文件的地址
--conf-file:自己编写的example.conf文件的地址
-Dflume.root.logger=INFO,console 输出到控制台

3)测试
在打开一个命令行窗口,输入:

telnet localhost 44444

输入任意参数,这里我输入的是hello,观察flume框架的日志输出

org.apache.flume.sink.LoggerSink.process(LoggerSink.java:94)] Event: { headers:{} body: 68 65 6C 6C 6F 0D                               hello. }

你可能感兴趣的:(Flume的使用)