大数据全系列 教程
1869个小节阅读:467.2k
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
[root@node1 ~]# yum install -y nc
[root@node2 ~]# yum install -y nc
[root@node3 ~]# yum install -y nc
[root@node4 ~]# yum install -y nc
创建工作目录
xxxxxxxxxx
[root@node3 ~]# cd /opt/flume-1.9.0/
[root@node3 flume-1.9.0]# mkdir jobs
创建并添加配置文件,参考官网文档:https://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html的A simple example:
x# Name the components on this agent
# a1:表示的agent的名称
# agent a1下的所有source
a1.sources = r1
# agent a1下的所有的sink
a1.sinks = k1
# agent a1下的所有的 channel
a1.channels = c1
# Describe/configure the source source的配置
# 指定sources.r1类型
a1.sources.r1.type = netcat
# 指定监听服务器的主机名或ip地址
a1.sources.r1.bind = localhost
# 指定监听服务器的端口号
a1.sources.r1.port = 44444
# Describe the sink sink相关参数的配置
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
# channel相关参数的配置
# channel的类型
a1.channels.c1.type = memory
# channel的容量
a1.channels.c1.capacity = 1000
# 进入channel的event事件的事务容量
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
# 将具体的source-channel-sink进行绑定
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
检查端口4444是否被占用
xxxxxxxxxx
[root@node3 ~]# netstat -nlp|grep 44444
[root@node3 ~]#
查看命令的帮助
xxxxxxxxxx
[root@node1 conf]# flume-ng help
Usage: /opt/flume/bin/flume-ng <command> [options]...
commands:
help display this help text
agent run a Flume agent指定agent的名称
global options:
--conf,-c <conf> use configs in <conf> directory 配置文件目录
-Dproperty=value sets a Java system property value指定java的系统属性值
-Xproperty=value sets a Java -X option
agent options:
--name,-n <name> the name of this agent (required)指定agent的名称
--conf-file,-f <file> specify a config file (required if -z missing)如果不指定-z选项,则必须指定配置文件
--zkConnString,-z <str> specify the ZooKeeper connection to use
启动Flume并监听44444端口
xxxxxxxxxx
[root@node3 jobs]# cd ../
#方式一
[root@node3 flume-1.9.0]# flume-ng agent --conf jobs/ --name a1 --conf-file jobs/netcat-logger.conf -Dflume.root.logger=INFO,console
#方式二
[root@node3 flume-1.9.0]# flume-ng agent -c jobs/ -n a1 -f jobs/netcat-logger.conf -Dflume.root.logger=INFO,console
分别在node2、node3上使用netcat工具发送数据
xxxxxxxxxx
[root@node2 ~]# nc node3 44444
Ncat: Connection refused.
[root@node2 ~]# nc 192.168.20.103 44444
Ncat: Connection refused.
在node2上无论使用node3还是192.168.20.103都无法和flume建立连接。
在node3上,复制一个node3的连接窗口做如下操作:
xxxxxxxxxx
[root@node3 flume-1.9.0]# nc localhost 44444
A
OK
B
OK
然后去node3的flume窗口查看:
xxxxxxxxxx
12-20 11:21:27,796 INFO source.NetcatSource: Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/127.0.0.1:44444]
12-20 11:22:05,709 INFO sink.LoggerSink: Event: { headers:{} body: 41 A }
12-20 11:22:05,738 INFO sink.LoggerSink: Event: { headers:{} body: 42 B }
说明可以接受到数据。
为什么在node2上不行,而在node3上可以呢?
这是因为在netcat-logger.conf文件中a1.sources.r1.bind = localhost,监听的是localhost,所以只能在node3上通过nc localhost 44444连接
修改netcat-logger.conf文件中a1.sources.r1.bind = node3
通过Ctrl+C将flume关闭后,再次重启。然后在执行步骤7
xxxxxxxxxx
[root@node2 ~]# nc node3 44444
A
OK
^C
[root@node2 ~]# nc 192.168.20.103 44444
W
OK