zoukankan      html  css  js  c++  java
  • kafka-线上单机broker扩容

    增加broker

    增加2个broker,复制系数直接指定为3,指定原来的单机zook
    docker run -d --name kafka02 -p 9092:9092 -p 9999:9999 -e KAFKA_BROKER_ID=2 -e KAFKA_ZOOKEEPER_CONNECT=192.168.18.225:2181 -e KAFKA_ADVERTISED_HOST_NAME=192.168.18.249 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.18.249:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -e JMX_PORT=9999 -e KAFKA_DEFAULT_REPLICATION_FACTOR=3 -e KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.18.249 -Dcom.sun.management.jmxremote.rmi.port=9999"  wurstmeister/kafka:0.11.0.0
    
    docker run -d --name kafka03 -p 9092:9092 -p 9999:9999 -e KAFKA_BROKER_ID=3 -e KAFKA_ZOOKEEPER_CONNECT=192.168.18.225:2181 -e KAFKA_ADVERTISED_HOST_NAME=192.168.21.166 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.21.166:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -e JMX_PORT=9999 -e KAFKA_DEFAULT_REPLICATION_FACTOR=3 -e KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.21.166 -Dcom.sun.management.jmxremote.rmi.port=9999"  wurstmeister/kafka:0.11.0.0
    

      

    调整__consumer_offset复制系数

    提交偏移量都是往这个topic里写数据,如果这个topic复制系数=1,那这个broker挂了,消费者就无法提交偏移量。

    # cat add_rep_consumer_offsets.json 
    {"version":1,
    "partitions":[
            {"topic":"__consumer_offsets","partition":0,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":1,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":2,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":3,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":4,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":5,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":6,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":7,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":8,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":9,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":10,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":11,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":12,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":13,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":14,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":15,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":16,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":17,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":18,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":19,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":20,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":21,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":22,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":23,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":24,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":25,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":26,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":27,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":28,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":29,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":30,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":31,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":32,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":33,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":34,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":35,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":36,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":37,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":38,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":39,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":40,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":41,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":42,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":43,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":44,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":45,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":46,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":47,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":48,"replicas":[1001,2,3]},
            {"topic":"__consumer_offsets","partition":49,"replicas":[1001,2,3]}
            ]
    }
    

      

    ./kafka-reassign-partitions.sh --zookeeper 192.168.18.225:2181 --reassignment-json-file add_rep_consumer_offsets.json --execute
    
    Current partition replica assignment
    
    {"version":1,"partitions":[{"topic":"__consumer_offsets","partition":22,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":30,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":8,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":21,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":4,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":27,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":7,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":9,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":46,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":25,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":35,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":41,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":33,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":23,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":49,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":47,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":16,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":28,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":31,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":36,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":42,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":3,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":18,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":37,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":15,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":24,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":38,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":17,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":48,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":19,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":11,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":13,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":2,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":43,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":6,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":14,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":20,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":0,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":44,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":39,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":12,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":45,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":1,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":5,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":26,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":29,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":34,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":10,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":32,"replicas":[1001],"log_dirs":["any"]},{"topic":"__consumer_offsets","partition":40,"replicas":[1001],"log_dirs":["any"]}]}
    

      

    调整其他topic复制系数

    调整后,可以在kafka manager里看到相关信息

    修改生产者和消费者连接信息

    改成连接3个broker的url

    宕机测试

    生产者和消费者在运行状态下,关掉原单机broker,查看生产消费是否正常,分区leader是否转移

     

     

  • 相关阅读:
    (转)-为什么分布式一定要有Redis?
    (九)redis使用lua脚本
    (八)redis实现分布式锁
    (七)面试题-Redis比较常见的面试题-转载
    (六)redis缓存穿透,击穿,雪崩以及解决方案
    (五)redis的主从复制
    (四)redis的数据持久化-RDB,AOF
    (三)redis的其他功能-Bitmap,HyperLogLog,GEO
    JsTracker
    Web开发者助手 FeHelper
  • 原文地址:https://www.cnblogs.com/jabbok/p/12970979.html
Copyright © 2011-2022 走看看