大数据_FLUME

flume 的搭建:
1.jdk的安装


      11.解压jdk:
        tar -zxvf jdk-8u102-linux-x64.tar.gz -C ~/bigdata/install/
      12.修改环境变量:
              vim ~/.bash_profile
                 JAVA_HOME=/home/flume/bigdata/install/jdk1.8.0_102
                 export PATH=$JAVA_HOME/bin:$PATH
       生效: source ~/.bash_profile 


2.flume 的搭建


   11.解压
      tar -zxvf apache-flume-1.7.0-bin.tar.gz -C ~/bigdata/install/
   12.修改环境变量
    vim ~/.bash_profile
       FLUME_HOME=/home/flume/bigdata/install/apache-flume-1.7.0-bin
       export PATH=$FLUME_HOME/bin:$PATH
     source ~/.bash_profile
   13.修改配置文件
      cd conf
      cp flume-env.ps1.template flume.env.sh
      export JAVA_HOME=/home/soup/bigdata/install/jdk1.8.0_102    
 flume官网:
 http://flume.apache.org


3.flume 测试小案例


11.flume网络端口netcat
文件名:netcat.conf

a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444


a1.sinks.k1.type = logger


a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

启动命令:
flume-ng agent --conf conf --conf-file conf/netcat.conf --name a1 -Dflume.root.logger=INFO,console

传输: Event: { headers:{} body: 7A 78 79 33 0D                                  zxy3. }


12.flume对接文本
文件名:netcat.conf

a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = exec
a1.sources.r1.command =  tail -F /home/hadoop/bigdata/test/a.txt
a1.sources.r1.shell = /bin/bash -c


a1.sinks.k1.type = logger


a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1


Event: { headers:{} body: 34 35 36                                        456 }

13.flume对接文件夹
文件名:netcat.conf

a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /home/hadoop/bigdata/test

a1.sinks.k1.type = logger


a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

--------------------目的地变了-------------------
14.flume对接hdfs
a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444


a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path=/input/201809


a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

4.flume 拦截器


 11.时间
    a1.sources = r1
    a1.sinks = k1
    a1.channels = c1

    a1.sources.r1.type = netcat
    a1.sources.r1.bind = localhost
    a1.sources.r1.port = 44444
    a1.sources.r1.interceptors = i1
    a1.sources.r1.interceptors.i1.type = timestamp

    a1.sinks.k1.type = hdfs
    a1.sinks.k1.hdfs.path=/input/201809


    a1.channels.c1.type = memory
    a1.channels.c1.capacity = 1000
    a1.channels.c1.transactionCapacity = 100

    a1.sources.r1.channels = c1
    a1.sinks.k1.channel = c1

Event: { headers:{} body: 7A 78 79 33 0D                                  zxy3. }
Event: { headers:{timestamp=1536222302872} body: 7A 78 79 31 0D                                  zxy1. }

 12.host

    a1.sources = r1
    a1.sinks = k1
    a1.channels = c1

    a1.sources.r1.type = netcat
    a1.sources.r1.bind = localhost
    a1.sources.r1.port = 44444
    a1.sources.r1.interceptors = i1
    a1.sources.r1.interceptors.i1.type = host

    a1.sinks.k1.type = logger
    #a1.sinks.k1.type = hdfs

    #a1.sinks.k1.hdfs.path=/input/test1/%y-%m-%d
    #a1.sinks.k1.hdfs.fileType=DataStream

    a1.channels.c1.type = memory

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

Event: { headers:{host=192.168.126.128} body: 7A 78 79 32 0D                                  zxy2. }


13.基于内容拦截:下去自己了解吧
  

5.自定义拦截器   :代码开发


   工具:eclipse/myeclipse/idea
   pom.xml
   flume依赖
    <dependency>
      <groupId>org.apache.flume</groupId>
      <artifactId>flume-ng-core</artifactId>
      <version>1.7.0</version>
    </dependency>

package com.itstar;

import com.google.common.base.Charsets;
import com.sun.javafx.scene.control.skin.VirtualFlow;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @AUTHOR COCO
 * 2018/9/6
 **/
public class flumeInterceptor implements Interceptor {
    @Override
    public void initialize() {

    }

    @Override
    public Event intercept(Event event) {
        //error:123
        //info:
      String body=new String(event.getBody(), Charsets.UTF_8);
        Pattern p=Pattern.compile("error:");
        Matcher r=p.matcher(body);
       String str="";
        if(r.find()){
            str=body;
        }else {
            str="no match";
        }
        event.setBody(str.getBytes());
        return event;
    }

    @Override
    public List<Event> intercept(List<Event> list) {
        List<Event> lis=new ArrayList<Event>();
       for (Event e:list){
           Event event=intercept(e);
          // if(event!=null) {
               lis.add(event);
          // }
       }
       return lis;
    }

    @Override
    public void close() {

    }

    public  static  class Builder implements Interceptor.Builder{

        @Override
        public Interceptor build() {
            return new flumeInterceptor();
        }

        @Override
        public void configure(Context context) {

        }
    }

}

打包命令
mvn clean package

上传flume/lib

a1.sources = r1
a1.sinks = k1
a1.channels = c1


a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = com.itstar.flumeInterceptor$Builder

a1.sinks.k1.type = logger


a1.channels.c1.type = memory

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1


启动:
flume-ng agent --conf conf --conf-file conf/netcat.conf --name a1 -Dflume.root.logger=INFO,console

测试:
telnet localhost 44444

1111   ------》no match
error:123----》error:123

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值