当前位置:   article > 正文

对已运行的kafka集群添加副本

对已运行的kafka集群添加副本

在已经运行的kafka集群中(业务主题已创建),如果一开始配置的默认副本是1,则后续再去修改配置文件为3,也只是针对后续新增的主题有效。原先主题不会生效。需要通过json文件去修改。

先创建__consumer_offsets主题的JSON

注意json文件中的"replicas":[2,1,0]这些是集群中的broke,有可能有的broke是1,2,3

新建一个consumer_offsets.json的文件,内容如下 

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

 在任意一个节点上执行(只需在一个节点上执行一次)

bin/kafka-reassign-partitions.sh --zookeeper 192.168.1.1:2181 --reassignment-json-file consumer_offsets.json --execute

 之后再加业务主题副本,新建一个doorinout.json的文件,内容如下

  1. {
  2. "version": 1,
  3. "partitions": [
  4. {"topic": "doorinout","partition": 0,"replicas": [2,1]},
  5. {"topic": "doorinout","partition": 1,"replicas": [0,2]},
  6. {"topic": "doorinout","partition": 2,"replicas": [1,0]},
  7. ]
  8. }

在任意一个节点上执行(只需在一个节点上执行一次)

bin/kafka-reassign-partitions.sh --zookeeper 192.168.1.1:2181 --reassignment-json-file doorinout.json --execute

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/661598
推荐阅读
相关标签
  

闽ICP备14008679号