zoukankan      html  css  js  c++  java
  • Flume的load-balance、failover

      配置flume集群参考https://www.cnblogs.com/jifengblog/p/9277793.html

    load-balance负载均衡

      介绍

    负载均衡是用于解决一台机器(一个进程)无法解决所有请求而产生的一种算法。

    Load balancing Sink Processor 能够实现 load balance 功能,如下图Agent1 是一个路由节点,负责将 Channel 暂存的 Event 均衡到对应的多个 Sink组件上,而每个 Sink 组件分别连接到一个独立的 Agent 上

      负载均衡(load_balance) 用于解决一个人干活处理不了多个一起来处理,然后如何分配的问题

      •   轮询 (round_robin) 随机(random) 权重


    配置

        Agent1

    cd /export/servers/flume/conf
    vi exec-avro.conf
    #agent1 name
    agent1.channels = c1
    agent1.sources = r1
    agent1.sinks = k1 k2
    
    #set gruop
    agent1.sinkgroups = g1
    
    #set channel
    agent1.channels.c1.type = memory
    agent1.channels.c1.capacity = 1000
    agent1.channels.c1.transactionCapacity = 100
    
    agent1.sources.r1.channels = c1
    agent1.sources.r1.type = exec
    agent1.sources.r1.command = tail -F /root/logs/123.log
    
    # set sink1
    agent1.sinks.k1.channel = c1
    agent1.sinks.k1.type = avro
    agent1.sinks.k1.hostname = node-2
    agent1.sinks.k1.port = 52020
    
    # set sink2
    agent1.sinks.k2.channel = c1
    agent1.sinks.k2.type = avro
    agent1.sinks.k2.hostname = node-3
    agent1.sinks.k2.port = 52020
    
    #set sink group
    agent1.sinkgroups.g1.sinks = k1 k2
    
    #set failover
    agent1.sinkgroups.g1.processor.type = load_balance
    agent1.sinkgroups.g1.processor.backoff = true  #如果开启,则将失败的 sink 放入黑名单
    agent1.sinkgroups.g1.processor.selector = round_robin  #轮询
    agent1.sinkgroups.g1.processor.selector.maxTimeOut=10000  #在黑名单放置的超时时间,超时结束时,若仍然无法接收,则超时时间呈指数增长

        Agent2

    cd /export/servers/flume/conf
    vi avro-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 = avro
    a1.sources.r1.channels = c1
    a1.sources.r1.bind = node-2
    a1.sources.r1.port = 52020
    
    # 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

      剩下的Agent除了主机ip地址不同其他配置相同

      Agent2-AgentN启动命令

        涉及flume多级启动的时候 建议优先启动远离数据源的

    bin/flume-ng agent -c conf -f conf/avro-logger.conf -n a1 -Dflume.root.logger=INFO,console

      Agent1启动命令

    bin/flume-ng agent -c conf -f conf/exec-avro.conf -n agent1 -Dflume.root.logger=INFO,console

      编写脚本到/root/logs/123.log进行测试

    while true;do date >> /root/logs/123.log;sleep 0.5;done

    Failover 容错

    介绍

    Failover Sink Processor 能够实现 failover 功能,具体流程类似 load-balance,但是内部处理机制与 load balance 完全不同。

    Failover Sink Processor 维护一个优先级 Sink 组件列表,只要有一个 Sink组件可用,Event 就被传递到下一个组件。故障转移机制的作用是将失败的 Sink降级到一个池,在这些池中它们被分配一个冷却时间,随着故障的连续,在重试之前冷却时间增加。一旦 Sink 成功发送一个事件,它将恢复到活动池。 Sink 具有与之相关的优先级,数量越大,优先级越高。

      例如,具有优先级为 100 的 sink 在优先级为 80 的 Sink 之前被激活。如果在发送事件时汇聚失败,则接下来将尝试下一个具有最高优先级的 Sink 发送事件。如果没有指定优先级,则根据在配置中指定 Sink 的顺序来确定优先级。

    • 容错(failover) 用于解决一个人挂掉导致整体不可用(单点故障) 但是有备用的可以顶上

      用于解决容错的方案最常见的就是HA(高可用)

        同一时间 只能有一个去干活


    配置

        该配置和负载均衡除了exec-avro.conf不同,其他相同

        修改Agent1的exec-avro.conf

    #agent1 name
    agent1.channels = c1
    agent1.sources = r1
    agent1.sinks = k1 k2
    
    #set gruop
    agent1.sinkgroups = g1
    
    #set channel
    agent1.channels.c1.type = memory
    agent1.channels.c1.capacity = 1000
    agent1.channels.c1.transactionCapacity = 100
    
    agent1.sources.r1.channels = c1
    agent1.sources.r1.type = exec
    agent1.sources.r1.command = tail -F /root/logs/456.log
    
    # set sink1
    agent1.sinks.k1.channel = c1
    agent1.sinks.k1.type = avro
    agent1.sinks.k1.hostname = node-2
    agent1.sinks.k1.port = 52020
    
    # set sink2
    agent1.sinks.k2.channel = c1
    agent1.sinks.k2.type = avro
    agent1.sinks.k2.hostname = node-3
    agent1.sinks.k2.port = 52020
    
    #set sink group
    agent1.sinkgroups.g1.sinks = k1 k2
    
    #set failover
    agent1.sinkgroups.g1.processor.type = failover
    agent1.sinkgroups.g1.processor.priority.k1 = 10
    agent1.sinkgroups.g1.processor.priority.k2 = 1
    agent1.sinkgroups.g1.processor.maxpenalty = 10000

      Agent2-AgentN启动命令

        涉及flume多级启动的时候 建议优先启动远离数据源的

    bin/flume-ng agent -c conf -f conf/avro-logger.conf -n a1 -Dflume.root.logger=INFO,console

      

      Agent1启动命令

    bin/flume-ng agent -c conf -f conf/exec-avro.conf -n agent1 -Dflume.root.logger=INFO,console

      编写脚本到/root/logs/456.log进行测试

    while true;do date >> /root/logs/456.log;sleep 0.5;done
  • 相关阅读:
    C#操作SQLite 报错 (Attempt to write a readonly database)
    JS判断字符输入个数(数字英文长度记为1,中文记为2,超过长度自动截取)
    JueryUI插件的简单应用(一):介绍及第一个示例
    在VS2008(Winform)中使用WebService
    Oracle触发器使用
    C# 创建Windows服务。服务功能:定时操作数据库
    aspnet前后台条件下根目录的读取
    xshell实现端口转发
    (转)使用FreeType实现矢量字体的粗体、斜体、描边、阴影效果
    D3D坐标系统和几何DirectX Griaphic学习
  • 原文地址:https://www.cnblogs.com/jifengblog/p/9277950.html
Copyright © 2011-2022 走看看