• Flume-企业开发案例


    第 3 章 企业开发案例

    注释:一下hadoop102、hadoop103、hadoop104 分别由 node01、node03、node04 代替

    3.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
     
    或者:

        1在线安装

        分别执行如下两个命令:

        yum install telnet

        yum install telnet-server

      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
     
      
     
     
    注:配置文件来源于官方手册:
        http://flume.apache.org/FlumeUserGuide.html
     
    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 监听页面观察接收数据情况
     
     
     
     
     
     
     

    3.2 实时读取本地文件到 HDFS 案例

    1)案例需求:实时监控 Hive 日志,并上传到 HDFS 中
    2)需求分析:
     
     
    3)实现步骤:
     

    1.Flume 要想将数据输出到 HDFS,必须持有 Hadoop 相关 jar 包

    ommons-configuration-1.6.jar、
    hadoop-auth-2.7.2.jar、
    hadoop-common-2.7.2.jar、
    hadoop-hdfs-2.7.2.jar、
    commons-io-2.4.jar、
    htrace-core-3.1.0-incubating.jar
    拷贝到/opt/module/flume/lib 文件夹下。
     

    2.创建 flume-file-hdfs.conf 文件

    创建文件
    [atguigu@hadoop102 job]$ touch flume-file-hdfs.conf
    注:要想读取 Linux 系统中的文件,就得按照 Linux 命令的规则执行命令。由于 Hive
    日志在 Linux 系统中所以读取文件的类型选择:exec 即 execute 执行的意思。表示执行 Linux
    命令来读取文件。
    [atguigu@hadoop102 job]$ vi flume-file-hdfs.conf
     
     
    添加如下内容
    # Name the components on this agent
    a2.sources = r2
    a2.sinks = k2
    a2.channels = c2
    # Describe/configure the source
    a2.sources.r2.type = exec
    a2.sources.r2.command = tail -F /opt/sxt/hive/logs/hive.log
    a2.sources.r2.shell = /bin/bash -c
    # Describe the sink
    a2.sinks.k2.type = hdfs
    a2.sinks.k2.hdfs.path = /flume/%Y%m%d/%H
    #上传文件的前缀
    a2.sinks.k2.hdfs.filePrefix = logs-
    #是否按照时间滚动文件夹
    a2.sinks.k2.hdfs.round = true
    #多少时间单位创建一个新的文件夹
    a2.sinks.k2.hdfs.roundValue = 1
    #重新定义时间单位
    a2.sinks.k2.hdfs.roundUnit = hour
    #是否使用本地时间戳
    a2.sinks.k2.hdfs.useLocalTimeStamp = true
    #积攒多少个 Event 才 flush 到 HDFS 一次
    a2.sinks.k2.hdfs.batchSize = 1000
    #设置文件类型,可支持压缩
    a2.sinks.k2.hdfs.fileType = DataStream
    #多久生成一个新的文件
    a2.sinks.k2.hdfs.rollInterval = 600
    #设置每个文件的滚动大小
    a2.sinks.k2.hdfs.rollSize = 134217700
    #文件的滚动与 Event 数量无关
    a2.sinks.k2.hdfs.rollCount = 0
    #最小冗余数
    a2.sinks.k2.hdfs.minBlockReplicas = 1
    # Use a channel which buffers events in memory
    a2.channels.c2.type = memory
    a2.channels.c2.capacity = 1000
    a2.channels.c2.transactionCapacity = 100
    # Bind the source and sink to the channel
    a2.sources.r2.channels = c2
    a2.sinks.k2.channel = c2
     配置分析:
     
     

    3.执行监控配置

    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name a2 --conf-file job/flume-file-hdfs.conf

    4.开启 Hadoop 和 Hive 并操作 Hive 产生日志

    [atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh
    [atguigu@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh
    [atguigu@hadoop102 hive]$ bin/hive
    hive (default)>

    5.在 HDFS 上查看文件。

     

    3.3 实时读取目录文件到 HDFS 案例

    1)案例需求:使用 Flume 监听整个目录的文件
    2)需求分析:
     
     
    3)实现步骤:
     
      1.创建配置文件 flume-dir-hdfs.conf
    创建一个文件
      [atguigu@hadoop102 job]$ touch flume-dir-hdfs.conf
    打开文件
      [atguigu@hadoop102 job]$ vim flume-dir-hdfs.conf
    添加如下内容 
     
     
    # name
    a3.sources = r3 a3.sinks = k3 a3.channels = c3
    # Describe
    /configure the source a3.sources.r3.type = spooldir a3.sources.r3.spoolDir = /opt/sxt/flume/upload a3.sources.r3.fileSuffix = .COMPLETED a3.sources.r3.fileHeader = true #忽略所有以.tmp 结尾的文件,不上传 a3.sources.r3.ignorePattern = ([^ ]*.tmp)
    # Describe the sink a3.sinks.k3.type
    = hdfs a3.sinks.k3.hdfs.path =/flume/upload/%Y%m%d/%H #上传文件的前缀 a3.sinks.k3.hdfs.filePrefix = upload- #是否按照时间滚动文件夹 a3.sinks.k3.hdfs.round = true #多少时间单位创建一个新的文件夹 a3.sinks.k3.hdfs.roundValue = 1 #重新定义时间单位 a3.sinks.k3.hdfs.roundUnit = hour #是否使用本地时间戳 a3.sinks.k3.hdfs.useLocalTimeStamp = true #积攒多少个 Event 才 flush 到 HDFS 一次 a3.sinks.k3.hdfs.batchSize = 100 #设置文件类型,可支持压缩 a3.sinks.k3.hdfs.fileType = DataStream #多久生成一个新的文件 a3.sinks.k3.hdfs.rollInterval = 600 #设置每个文件的滚动大小大概是 128M a3.sinks.k3.hdfs.rollSize = 134217700 #文件的滚动与 Event 数量无关 a3.sinks.k3.hdfs.rollCount = 0 #最小冗余数 a3.sinks.k3.hdfs.minBlockReplicas = 1 # Use a channel which buffers events in memory a3.channels.c3.type = memory a3.channels.c3.capacity = 1000 a3.channels.c3.transactionCapacity = 100 # Bind the source and sink to the channel a3.sources.r3.channels = c3 a3.sinks.k3.channel = c3

     
    2. 启动监控文件夹命令
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name a3 --conf-file job/flume-dir-hdfs.conf
     
    说明: 在使用 Spooling Directory Source 时
    1) 不要在监控目录中创建并持续修改文件
    2) 上传完成的文件会以.COMPLETED 结尾
    3) 被监控文件夹每 500 毫秒扫描一次文件变动
     
    3. 向 upload 文件夹中添加文件
    在/opt/module/flume 目录下创建 upload 文件夹
    [atguigu@hadoop102 flume]$ mkdir upload
    向 upload 文件夹中添加文件
    [atguigu@hadoop102 upload]$ touch atguigu.txt
    [atguigu@hadoop102 upload]$ touch atguigu.tmp
    [atguigu@hadoop102 upload]$ touch atguigu.log
     
    4. 查看 HDFS 上的数据 
     
     

     
     

    3.4 单数据源多出口案例(选择器)

      单 Source 多 Channel、Sink 如图 7-2 所示
     
                                                           图 7-2 单 Source 多 Channel、Sink 
     
    1)案例需求:使用 Flume-1 监控文件变动,Flume-1 将变动内容传递给 Flume-2,Flume-2
    负责存储到 HDFS。同时 Flume-1 将变动内容传递给 Flume-3,Flume-3 负责输出到 Local
    FileSystem。
    2)需求分析: 
     
     
    3)实现步骤:
     

      0.准备工作

      在/opt/module/flume/job 目录下创建 group1 文件夹
      [atguigu@hadoop102 job]$ cd group1/
      
      在/opt/module/datas/目录下创建 flume3 文件夹
      [atguigu@hadoop102 datas]$ mkdir flume3
     

      1.创建 flume-file-flume.conf

      配置 1 个接收日志文件的 source 和两个 channel、两个 sink,分别输送给 flume-flume-hdfs
    和 flume-flume-dir。
      创建配置文件并打开
      [atguigu@hadoop102 group1]$ touch flume-file-flume.conf
      [atguigu@hadoop102 group1]$ vim flume-file-flume.conf
     
      添加如下内容
    # Name the components on this agent
    a1.sources = r1
    a1.sinks = k1 k2
    a1.channels = c1 c2
    
    # 将数据流复制给所有 channel a1.sources.r1.selector.type
    = replicating
    # Describe
    /configure the source a1.sources.r1.type = exec a1.sources.r1.command = tail -F /opt/sxt/hive/logs/hive.log a1.sources.r1.shell = /bin/bash -c
    # Describe the sink a1.sinks.k1.type
    = avro a1.sinks.k1.hostname = node01 a1.sinks.k1.port = 4141 a1.sinks.k2.type = avro a1.sinks.k2.hostname = node01 a1.sinks.k2.port = 4142
    # Describe the channel a1.channels.c1.type
    = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 a1.channels.c2.type = memory a1.channels.c2.capacity = 1000 a1.channels.c2.transactionCapacity = 100
    # Bind the source and sink to the channel a1.sources.r1.channels
    = c1 c2 a1.sinks.k1.channel = c1 a1.sinks.k2.channel = c2
      :Avro 是由 Hadoop 创始人 Doug Cutting 创建的一种语言无关的数据序列化和 RPC 框
    架。
      注:RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程
    序上请求服务,而不需要了解底层网络技术的协议。

      2.创建 flume-flume-hdfs.conf

    配置上级 Flume 输出的 Source,输出是到 HDFS 的 Sink。
    创建配置文件并打开
    [atguigu@hadoop102 group1]$ touch flume-flume-hdfs.conf
    [atguigu@hadoop102 group1]$ vim flume-flume-hdfs.conf
     
    添加如下内容
    # Name the components on this agent
    a2.sources = r1
    a2.sinks = k1
    a2.channels = c1
    
    # Describe
    /configure the source a2.sources.r1.type = avro a2.sources.r1.bind = node01 a2.sources.r1.port = 4141
    # Describe the sink a2.sinks.k1.type
    = hdfs a2.sinks.k1.hdfs.path = /flume2/%Y%m%d/%H
    #上传文件的前缀 a2.sinks.k1.hdfs.filePrefix = flume2- #是否按照时间滚动文件夹 a2.sinks.k1.hdfs.round = true #多少时间单位创建一个新的文件夹 a2.sinks.k1.hdfs.roundValue = 1 #重新定义时间单位 a2.sinks.k1.hdfs.roundUnit = hour #是否使用本地时间戳 a2.sinks.k1.hdfs.useLocalTimeStamp = true #积攒多少个 Event 才 flush 到 HDFS 一次 a2.sinks.k1.hdfs.batchSize = 100 #设置文件类型,可支持压缩 a2.sinks.k1.hdfs.fileType = DataStream #多久生成一个新的文件 a2.sinks.k1.hdfs.rollInterval = 600 #设置每个文件的滚动大小大概是 128M a2.sinks.k1.hdfs.rollSize = 134217700 #文件的滚动与 Event 数量无关 a2.sinks.k1.hdfs.rollCount = 0 #最小冗余数 a2.sinks.k1.hdfs.minBlockReplicas = 1
    # Describe the channel a2.channels.c1.type
    = memory a2.channels.c1.capacity = 1000 a2.channels.c1.transactionCapacity = 100
    # Bind the source and sink to the channel a2.sources.r1.channels
    = c1 a2.sinks.k1.channel = c1

    3.创建 flume-flume-dir.conf

      配置上级 Flume 输出的 Source,输出是到本地目录的 Sink。
    创建配置文件并打开
    [atguigu@hadoop102 group1]$ touch flume-flume-dir.conf
    [atguigu@hadoop102 group1]$ vim flume-flume-dir.conf
     
    添加如下内容
    # Name the components on this agent
    a3.sources = r1
    a3.sinks = k1
    a3.channels = c2
    
    # Describe
    /configure the source a3.sources.r1.type = avro a3.sources.r1.bind = node01 a3.sources.r1.port = 4142
    # Describe the sink a3.sinks.k1.type
    = file_roll a3.sinks.k1.sink.directory = /opt/sxt/datas/flume3
    # Describe the channel a3.channels.c2.type
    = memory a3.channels.c2.capacity = 1000 a3.channels.c2.transactionCapacity = 100
    # Bind the source and sink to the channel a3.sources.r1.channels
    = c2 a3.sinks.k1.channel = c2
    提示:输出的本地目录必须是已经存在的目录,如果该目录不存在,并不会创建新的目录。

    4.执行配置文件

    分别开启对应配置文件:flume-flume-dir,flume-flume-hdfs,flume-file-flume。
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name  a3 --conf-file job/group1/flume-flume-dir.conf
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name  a2 --conf-file job/group1/flume-flume-hdfs.conf
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name  a1 --conf-file job/group1/flume-file-flume.conf
    5.启动 Hadoop 和 Hive
    [atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh
    [atguigu@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh
    [atguigu@hadoop102 hive]$ bin/hive
    hive (default)>

    6.检查 HDFS 上数据 

     
     

    7 检查/opt/module/datas/flume3 目录中数据

    [atguigu@hadoop102 flume3]$ ll
    总用量 8
    -rw-rw-r--. 1 atguigu atguigu 5942 5 月 22 00:09 1526918887550-3
     
     
     
     
     

    3.5 单数据源多出口案例(Sink 组) 

      单 Source、Channel 多 Sink(负载均衡)如图 7-3 所示。
     
                                                                                        图 7-3 单 Source、Channel 多 Sink 
     
    1)案例需求:使用 Flume-1 监控文件变动,Flume-1 将变动内容传递给 Flume-2,Flume-2
      负责存储到 HDFS。同时 Flume-1 将变动内容传递给 Flume-3,Flume-3 也负责存储到 HDFS
    2)需求分析: 
     
     
    3)实现步骤:

      0.准备工作

      在/opt/module/flume/job 目录下创建 group2 文件夹
        [atguigu@hadoop102 job]$ cd group2/

      1.创建 flume-netcat-flume.conf

      配 置 1 个接收 日 志 文 件 的 source 和 1 个 channel、 两 个 sink , 分 别 输 送 给
      flume-flume-console1 和 flume-flume-console2。
      创建配置文件并打开 
      [atguigu@hadoop102 group2]$ touch flume-netcat-flume.conf
      [atguigu@hadoop102 group2]$ vim flume-netcat-flume.conf 
     
    添加如下内容 
    # Name the components on this agent
    a1.sources = r1
    a1.channels = c1
    a1.sinkgroups = g1
    a1.sinks = k1 k2
    # Describe/configure the source
    a1.sources.r1.type = netcat
    a1.sources.r1.bind = localhost
    a1.sources.r1.port = 44444
    a1.sinkgroups.g1.processor.type = load_balance
    a1.sinkgroups.g1.processor.backoff = true
    a1.sinkgroups.g1.processor.selector = round_robin
    a1.sinkgroups.g1.processor.selector.maxTimeOut=10000
    # Describe the sink
    a1.sinks.k1.type = avro
    a1.sinks.k1.hostname = node01
    a1.sinks.k1.port = 4141
    a1.sinks.k2.type = avro
    a1.sinks.k2.hostname = node01
    a1.sinks.k2.port = 4142
    # Describe the channel
    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.sinkgroups.g1.sinks = k1 k2
    a1.sinks.k1.channel = c1
    a1.sinks.k2.channel = c1
      注:Avro 是由 Hadoop 创始人 Doug Cutting 创建的一种语言无关的数据序列化和 RPC 框
    架。
      注:RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程
    序上请求服务,而不需要了解底层网络技术的协议。
     

    2.创建 flume-flume-console1.conf

    配置上级 Flume 输出的 Source,输出是到本地控制台。
    创建配置文件并打开
    [atguigu@hadoop102 group2]$ touch flume-flume-console1.conf
    [atguigu@hadoop102 group2]$ vim flume-flume-console1.conf
     
    添加如下内容 
    # Name the components on this agent
    a2.sources = r1
    a2.sinks = k1
    a2.channels = c1
    # Describe/configure the source
    a2.sources.r1.type = avro
    a2.sources.r1.bind = node01
    a2.sources.r1.port = 4141
    # Describe the sink
    a2.sinks.k1.type = logger
    # Describe the channel
    a2.channels.c1.type = memory
    a2.channels.c1.capacity = 1000
    a2.channels.c1.transactionCapacity = 100
    # Bind the source and sink to the channel
    a2.sources.r1.channels = c1
    a2.sinks.k1.channel = c1

    3.创建 flume-flume-console2.conf

    配置上级 Flume 输出的 Source,输出是到本地控制台。
    创建配置文件并打开
    [atguigu@hadoop102 group2]$ touch flume-flume-console2.conf
    [atguigu@hadoop102 group2]$ vim flume-flume-console2.conf
    添加如下内容 
    # Name the components on this agent
    a3.sources = r1
    a3.sinks = k1
    a3.channels = c2
    # Describe/configure the source
    a3.sources.r1.type = avro
    a3.sources.r1.bind = node01
    a3.sources.r1.port = 4142
    # Describe the sink
    a3.sinks.k1.type = logger
    # Describe the channel
    a3.channels.c2.type = memory
    a3.channels.c2.capacity = 1000
    a3.channels.c2.transactionCapacity = 100
    # Bind the source and sink to the channel
    a3.sources.r1.channels = c2
    a3.sinks.k1.channel = c2

    4.执行配置文件

    分别开启对应配置文件:flume-flume-console2,flume-flume-console1,flume-netcat-flume。
     
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name
    a3 --conf-file job/group2/flume-flume-console2.conf
    -Dflume.root.logger=INFO,console
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name
    a2 --conf-file job/group2/flume-flume-console1.conf
    -Dflume.root.logger=INFO,console
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name
    a1 --conf-file job/group2/flume-netcat-flume.conf 
     
     

    5. 使用 telnet 工具向本机的 44444 端口发送内容

    $ telnet localhost 44444
     

    6. 查看 Flume2 及 Flume3 的控制台打印日志 

     
     
     
     
     
     
     
     

    3.6 多数据源汇总案例

     
      多 Source 汇总数据到单 Flume 如图 7-4 所示。
     
                        图 7-4 多 Flume 汇总数据到单 Flume
     
     
    1) 案例需求:
      hadoop103 上的 Flume-1 监控文件/opt/module/group.log,
      hadoop102 上的 Flume-2 监控某一个端口的数据流,
      Flume-1 与 Flume-2 将数据发送给 hadoop104 上的 Flume-3,Flume-3 将最终数据打印到
    控制台。
     
    2)需求分析:
    3)实现步骤:

    0.准备工作

    分发 Flume
    [atguigu@hadoop102 module]$ xsync flume
    在hadoop102、hadoop103以及hadoop104的/opt/module/flume/job目录下创建一个group3
    文件夹。
    [atguigu@hadoop102 job]$ mkdir group3
    [atguigu@hadoop103 job]$ mkdir group3
    [atguigu@hadoop104 job]$ mkdir group3
     

    1.创建 flume1-logger-flume.conf

    配置 Source 用于监控 hive.log 文件,配置 Sink 输出数据到下一级 Flume。
    在 hadoop103 上创建配置文件并打开
    [atguigu@hadoop103 group3]$ touch flume1-logger-flume.conf
    [atguigu@hadoop103 group3]$ vim flume1-logger-flume.conf
    添加如下内容
    # Name the components on this agent
    a1.sources = r1
    a1.sinks = k1
    a1.channels = c1
    
    # Describe
    /configure the source a1.sources.r1.type = exec a1.sources.r1.command = tail -F /opt/sxt/group.log a1.sources.r1.shell = /bin/bash -c
    # Describe the sink a1.sinks.k1.type
    = avro a1.sinks.k1.hostname = node04 a1.sinks.k1.port = 4141
    # Describe the channel 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.创建 flume2-netcat-flume.conf

    配置 Source 监控端口 44444 数据流,配置 Sink 数据到下一级 Flume:
    在 hadoop102 上创建配置文件并打开
    [atguigu@hadoop102 group3]$ touch flume2-netcat-flume.conf
    [atguigu@hadoop102 group3]$ vim flume2-netcat-flume.conf
    添加如下内容
    # Name the components on this agent
    a2.sources = r1
    a2.sinks = k1
    a2.channels = c1
    # Describe/configure the source
    a2.sources.r1.type = netcat
    a2.sources.r1.bind = node01
    a2.sources.r1.port = 44444
    # Describe the sink
    a2.sinks.k1.type = avro
    a2.sinks.k1.hostname = node04
    a2.sinks.k1.port = 4141
    # Use a channel which buffers events in memory
    a2.channels.c1.type = memory
    a2.channels.c1.capacity = 1000
    a2.channels.c1.transactionCapacity = 100
    # Bind the source and sink to the channel
    a2.sources.r1.channels = c1
    a2.sinks.k1.channel = c1
     

    3.创建 flume3-flume-logger.conf

    配置 source 用于接收 flume1 与 flume2 发送过来的数据流,最终合并后 sink 到控制台。
    在 hadoop104 上创建配置文件并打开
    [atguigu@hadoop104 group3]$ touch flume3-flume-logger.conf
    [atguigu@hadoop104 group3]$ vim flume3-flume-logger.conf
    添加如下内容
    # Name the components on this agent
    a3.sources = r1
    a3.sinks = k1
    a3.channels = c1
    
    # Describe
    /configure the source a3.sources.r1.type = avro a3.sources.r1.bind = node04 a3.sources.r1.port = 4141 # Describe the sink # Describe the sink a3.sinks.k1.type = logger # Describe the channel a3.channels.c1.type = memory a3.channels.c1.capacity = 1000 a3.channels.c1.transactionCapacity = 100 # Bind the source and sink to the channel a3.sources.r1.channels = c1 a3.sinks.k1.channel = c1
     

    4.执行配置文件

    分 别 开 启 对 应 配 置 文 件 : flume3-flume-logger.conf , flume2-netcat-flume.conf ,
    flume1-logger-flume.conf。
    [atguigu@hadoop104 flume]$ bin/flume-ng agent --conf conf/ --name a3 --conf-file job/group3/flume3-flume-logger.conf -Dflume.root.logger=INFO,console
    [atguigu@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name a2 --conf-file job/group3/flume2-netcat-flume.conf
    [atguigu@hadoop103 flume]$ bin/flume-ng agent --conf conf/ --name a1 --conf-file job/group3/flume1-logger-flume.conf
     

    5.在 hadoop103 上向/opt/module 目录下的 group.log 追加内容

    [atguigu@hadoop103 module]$ echo 'hello' > group.log
     

    6.在 hadoop102 上向 44444 端口发送数据

    [atguigu@hadoop102 flume]$ telnet hadoop102 44444
     

    7.检查 hadoop104 上数据 

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    wxpython 浏览器框架
    wxpython 开发播放器
    Docker学习(三)——Docker镜像使用
    Docker学习(二)——Docker容器使用
    SSL/TLS协议
    Https原理及证书管理
    证书及证书管理
    Docker学习(一)——安装docker
    Linux系统中安装软件方法总结
    Linux下删除的文件如何恢复
  • 原文地址:https://www.cnblogs.com/LXL616/p/10969330.html
Copyright © 2020-2023  润新知