一.环境准备
1.下载Javajdk,Flume的压缩包。
地址如下:https://www.oracle.com/java/technologies/downloads/
https://flume.apache.org/download.html
2.环境配置JAVA_HOME和FLUME_HOME
在设置—系统中,进入到高级系统设置—环境变量。新建系统变量如图:
地址为jdk文件路径和flume解压文件夹路径
在PATH变量中新建如图:
3.修改flume文件下conf目录中的template文件,复制一份并删除.template后缀
这里说明具体方式:用记事本打开c++文件,另存为(文件类型为所有类型),文件名删除.template即可。
4.在cmd(win+r)窗口下输入:java -version 和 flume-ng version,可查看到版本号即配置成功。
二.采集端口数据
1.创建agent文件(纯文本文件)
以conf目录下的“flume-conf.properties.template”文件为模板,用记事本打卡,修改# in this case agent以下的内容。(即写入source channel sink)另存为一个文件。
参考如下:
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 = 2022
# 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 channela1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2.在cmd窗口中,切换到flume的bin目录,运行端口监听命令:flume ng.cmd agent -conf ..\conf -conf-file ..\conf\example.conf - name a1 property flume.root.logger=INFO,console
3.新开一个cmd窗口,输入“telnet 127.0.0.1 2022”模拟发送数据。
在bin目录下的example文件里查看最后一条数据,符合即监听成功。