flume 监听端口数据案例

本文介绍了如何使用Flume监听特定端口的数据,并通过配置文件设置Flume代理来捕获数据,然后将其发送到日志记录器。实验环境中包括一个Flume节点和一个JDK节点,Flume版本为1.6.0。配置文件中定义了Netcat源、内存通道和日志记录器作为接收和处理数据的组件。在启动Flume代理后,使用telnet连接到监听的端口发送数据,Flume成功接收到并记录了这些信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Flume监听端口数据

实验环境

IP主机名组件版本
192.168.222.101masterflume1.6.0
192.168.222.102slave1jdk1.8
192.168.222.101masterjdk1.8

防火墙已关闭

1、配置conf文件

[root@master ~]# vim /usr/local/src/flume/conf/listen-port-data.conf 
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = netcat
# 配置主机名/IP地址
a1.sources.r1.bind = master
# 配置端口
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
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

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

2、运行flume

[root@master ~]# flume-ng agent --conf conf --conf-file /usr/local/src/flume/conf/listen-port-data.conf --name a1 -Dflume.root.logger=INFO,console
21/10/13 15:46:53 INFO node.Application: Starting new configuration:{ sourceRunners:{r1=EventDrivenSourceRunner: { source:org.apache.flume.source.NetcatSource{name:r1,state:IDLE} }} sinkRunners:{k1=SinkRunner: { policy:org.apache.flume.sink.DefaultSinkProcessor@4a52f3b4 counterGroup:{ name:null counters:{} } }} channels:{c1=org.apache.flume.channel.MemoryChannel{name: c1}} }
21/10/13 15:46:53 INFO node.Application: Starting Channel c1
21/10/13 15:46:53 INFO node.Application: Waiting for channel: c1 to start. Sleeping for 500 ms
21/10/13 15:46:53 INFO instrumentation.MonitoredCounterGroup: Monitored counter group for type: CHANNEL, name: c1: Successfully registered new MBean.
21/10/13 15:46:53 INFO instrumentation.MonitoredCounterGroup: Component type: CHANNEL, name: c1 started
21/10/13 15:46:54 INFO node.Application: Starting Sink k1
21/10/13 15:46:54 INFO node.Application: Starting Source r1
21/10/13 15:46:54 INFO source.NetcatSource: Source starting
21/10/13 15:46:54 INFO source.NetcatSource: Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/192.168.222.101:4444]

3、打开一个新的终端

  1. 安装telnet

    [root@master ~]# yum install -y telnet
    
  2. 使用telnet命令

    [root@master ~]# telnet master 4444
    Trying 192.168.222.101...
    Connected to master.
    Escape character is '^]'.
    
    OK
    this is my first demo
    OK
    
  3. 接收端信息

    21/10/13 15:51:46 INFO instrumentation.MonitoredCounterGroup: Component type: CHANNEL, name: c1 started
    21/10/13 15:51:46 INFO node.Application: Starting Sink k1
    21/10/13 15:51:46 INFO node.Application: Starting Source r1
    21/10/13 15:51:46 INFO source.NetcatSource: Source starting
    21/10/13 15:51:46 INFO source.NetcatSource: Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/192.168.222.101:4444]
    21/10/13 15:51:52 INFO sink.LoggerSink: Event: { headers:{} body: 0D                                              . }
    21/10/13 15:52:01 INFO sink.LoggerSink: Event: { headers:{} body: 74 68 69 73 20 69 73 20 6D 79 20 66 69 72 73 74 this is my first }
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值