• Flume基础(四):企业开发案例(一)


    1 监控端口数据官方案例

    1)案例需求:首先,Flume 监控本机 44444 端口,然后通过 telnet 工具向本机 44444 端口发
    送消息,最后 Flume 将监听的数据实时显示在控制台。
    2)需求分析:
     
    3)实现步骤:
    1.安装 telnet 工具
    将 rpm 软 件 包 (xinetd-2.3.14-40.el6.x86_64.rpm 、 telnet-0.17-48.el6.x86_64.rpm 和telnet-server-0.17-48.el6.x86_64.rpm)拷入/opt/software 文件夹下面。执行 RPM 软件包安装命令:
    [atguigu@hadoop102 software]$ sudo rpm -ivh 
    xinetd-2.3.14-40.el6.x86_64.rpm
    [atguigu@hadoop102 software]$ sudo rpm -ivh 
    telnet-0.17-48.el6.x86_64.rpm
    [atguigu@hadoop102 software]$ sudo rpm -ivh 
    telnet-server-0.17-48.el6.x86_64.rpm
    2.判断 44444 端口是否被占用 
    [atguigu@hadoop102 flume-telnet]$ sudo netstat -tunlp | grep 44444
    功能描述:netstat 命令是一个监控 TCP/IP 网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息。
    基本语法:netstat [选项]
    选项参数:
    -t 或--tcp:显示 TCP 传输协议的连线状况;
    -u 或--udp:显示 UDP 传输协议的连线状况;
    -n 或--numeric:直接使用 ip 地址,而不通过域名服务器;
    -l 或--listening:显示监控中的服务器的 Socket;
    -p 或--programs:显示正在使用 Socket 的程序识别码和程序名称;
     
    3.创建 Flume Agent 配置文件 flume-telnet-logger.conf
    在 flume 目录下创建 job 文件夹并进入 job 文件夹。 
    [atguigu@hadoop102 flume]$ mkdir job
    [atguigu@hadoop102 flume]$ cd job/
    在 job 文件夹下创建 Flume Agent 配置文件 flume-telnet-logger.conf。 
    [atguigu@hadoop102 job]$ touch flume-telnet-logger.conf
    在 flume-telnet-logger.conf 文件中添加如下内容。 
    [atguigu@hadoop102 job]$ vim flume-telnet-logger.conf
    添加内容如下: 
     
    # 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 = localhost
    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
    View Code

    4. 先开启 flume 监听端口
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name 
    a1 --conf-file job/flume-telnet-logger.conf 
    -Dflume.root.logger=INFO,console
    参数说明:
    --conf conf/ :表示配置文件存储在 conf/目录
    --name a1
    :表示给 agent 起名为 a1
    --conf-file job/flume-telnet.conf :flume 本次启动读取的配置文件是在 job 文件夹下的 flume-telnet.conf 文件。
    -Dflume.root.logger==INFO,console : -D 表 示 flume 运 行 时 动 态 修 改
    flume.root.logger 参数属性值,并将控制台日志打印级别设置为 INFO 级别。日志级别包括:log、info、warn、error。 
     
    5.使用 telnet 工具向本机的 44444 端口发送内容 
    [atguigu@hadoop102 ~]$ telnet localhost 44444

    6.在 Flume 监听页面观察接收数据情况

    本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/13378741.html

  • 相关阅读:
    20200213 超级聊天术
    20220210 java.util.Properties
    20220210 java.util.concurrent.BlockingQueue 方法说明
    20220210 java.util.Queue
    20220210 java.lang.Long
    20220210 Java 反射基础类
    一组很有意思的Principles
    python logging用法的简单总结
    好好的Typora收费了!_2022_01_20
    一些常用的jQuery方法1_20220128
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/13378741.html
Copyright © 2020-2023  润新知