需求:从指定网络端口采集数据输出到控制台
使用flume的关键就是写配置文件
a)配置source
b)配置channel
c)配置sink
d)把以上三个组件串起来
我们看一下官网给的配置文件
# example.conf: A single-node Flume configurationa1:agent的名称r1:source的名称k1:sink的名称c1:channel的名称# Name the components on this agenta1.sources = r1 ??指定sourcea1.sinks = k1 ??指定sinka1.channels = c1 ??指定channel ???这里指定的只有一个# Describe/configure the source这个agent有多个source,我们指定source的类型为netcat,绑定到localhost,我这里也可以写成ubuntu,可以通过hostname查看,监听端口为44444a1.sources.r1.type = netcata1.sources.r1.bind = localhosta1.sources.r1.port = 44444# Describe the sink表示将logger输出到控制台a1.sinks.k1.type = logger# Use a channel which buffers events in memory使用channel存到内存当中a1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channel把以上三个组件串起来一个source可以接收不同的数据源a1.sources.r1.channels = c1但是sink只能sink到一个地方去a1.sinks.k1.channel = c1
我们直接在conf下建一个example.conf,把上面的内容删掉我们添加的,然后拷贝进去
然后启动agent,如何启动:
flume-ng agent --name agent的名字 --conf 配置文件(就是flume目录下的conf) --conf-file 刚才我们写的配置文件 -Dflume.root.logger=INFO,console
其中--name也可以写成-n,--conf也可以写成-c,--conf-file也可以写成-f,但是这样省略的太多了,还是写全名更清晰。-Dflume.root.logger=INFO,console 表示将日志输出到控制台
启动,我这里输入:flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/example.conf -Dflume.root.logger=INFO,console
启动成功,显示监听44444端口,我们通过telnet localhost 44444连接一下
可以看到每当我输入一条内容,都会显示一条ok,表示发送成功,我们再来看看flume
可以看到将我们输入的内容,收集起来了。
2018-11-08 01:01:24,702 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:94)] Event: { headers:{} body: 73 61 74 6F 72 69 0D satori. }
每一条记录都是一个event, 我们输入的内容在body里面
4.flume实战(一)
原文地址:https://www.cnblogs.com/traditional/p/9929786.html