美文网首页
kafka机器下线操作&上线操作

kafka机器下线操作&上线操作

作者: LancerLin_LX | 来源:发表于2017-09-08 19:24 被阅读0次

    1.下线操作

    1.步骤一

    新建一个文件名为topics-to-move.json文件内容为需要转移的topic

    {"topics": [
    {"topic": "__consumer_offsets"},
    {"topic": "click_stream_topic"},
    {"topic": "directory_topic"},
    {"topic": "DP_monitor_consumer_topic"},
    {"topic": "DP_monitor_provider_topic"},
    {"topic": "EC_user_event_rt_topic"},
    {"topic": "kafka_topic"}
    ],
    "version":1
    }
    

    2.步骤二

    执行以下操作命令,比如下线0号机器,把0上的数据都移到1,2上,脚本内容

    bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-file topics-to-move.json --broker-list "1,2" --generate
    
    image.png
    将新生产的json串赋值到expand-cluster-reassignment.json文件中, image.png

    3.步骤三

    开始执行转移数据操作

    bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment.json --execute
    
    image.png

    使用以下命令查看状态

      bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment.json --verify
    

    效果,如下图所示,数据转移完成


    image.png

    按照上述步骤将所有的0上的topic都转移到1,2服务器上,0号机器下线升级系统

    2.上线操作

    与下线操作原理一样

    1.步骤一

    执行以下操作命令,把数据都转移到0,1,2上,执行以下脚本

    bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-file topics-to-move.json --broker-list "0,1,2" --generate
    
    image.png

    2.将内容copy到expand-cluster-reassignment2.json文件中,执行以下命令

    bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment2.json --execute
    
    image.png

    使用以下命令查看状态

      bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment2.json --verify
    
    image.png

    效果数据恢复

    image.png

    3.总结

    测试环境数据量较少,转移非常快,线上环境,topic较多,partitions数量也多,转移数据较慢,一次不要操作太多topic,需要耐心等待观察。

    相关文章

      网友评论

          本文标题:kafka机器下线操作&上线操作

          本文链接:https://www.haomeiwen.com/subject/vylgjxtx.html