Flume完整实例一:从指定网络端口采集数据输出到控制台

LZ最近在学习Flume(分布式日志收集框架),从简单的例子入手,以供参考
需求:从指定网络端口采集数据输出到控制台
首先要安装Flume,其源码是Java,所以先安装JDK(我装的是1.8),Flume解压配置好环境后,检测flume是否安装成功:在bin目录下,比如:/home/apache-flume-1.6.0-cdh5.7.0-bin/bin
输入:flume-ng version

使用flume的关键就是写agent配置文件,需要:
(1) 配置source
(2) 配置channel
(3) 配置sink
(4) 把以上三个组件串起来
实例代码如下:

# 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 = hadoop000
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

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

Agent选型(看官网):netcat source + memory channel + logger sink
解释:
(1)先描述agent
a1:agent名称
r1: source的名称
k1: sink的名称
c1: channel的名称

(2)具体配置source、sink、channel,因为sources是复数,即可能有多个source,所以用a1.sources.r1来指定哪一个source,可以去官网上找具体的source对应的类型,比如用netcat,看属性参数,官网例子中黑体是必须要配置的。官网教程

(3)新建一个conf文件,将配置文件写入

(4)在bin目录下启动agent,命令如下:

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

命令具体内容可以去控制台用flume-ng 查看

(5)使用telnet进行测试,另开一个页面输入:telnet hadoop000 44444
再输出一些信息,会实时打印在控制台
输入信息
控制台对应输出

猜你喜欢

转载自blog.csdn.net/yulutian/article/details/80822266