{"id":1519,"date":"2020-06-08T16:23:40","date_gmt":"2020-06-08T08:23:40","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1519"},"modified":"2020-06-08T16:23:40","modified_gmt":"2020-06-08T08:23:40","slug":"kafka%e6%97%a5%e5%b8%b8%e7%bb%b4%e6%8a%a4","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1519","title":{"rendered":"Kafka\u65e5\u5e38\u7ef4\u62a4"},"content":{"rendered":"<div>\n<div>\n<article class=\\\"_2rhmJa\\\">\u5728\u8f6f\u4ef6\u9879\u76ee\u7684\u751f\u547d\u5468\u671f\u4e2d\uff0c\u5f00\u53d1\u53ea\u5360\u5f00\u59cb\u7684\u4e00\u5c0f\u90e8\u5206\uff0c\u5927\u90e8\u5206\u65f6\u95f4\u6211\u4eec\u8981\u5bf9\u9879\u76ee\u8fdb\u884c\u8fd0\u884c\u7ef4\u62a4\uff0cKafka\u76f8\u5173\u7684\u9879\u76ee\u4e5f\u4e0d\u4f8b\u5916\u3002\u6240\u4ee5\u8fd9\u91cc\u4ecb\u7ecd\u4e86\u4e00\u4e9bKafka\u670d\u52a1\u5668\u57fa\u7840\u7684\u8fd0\u7ef4\u65b9\u6cd5\u3002<\/p>\n<h2>\u5173\u4e8eKafka\u7684\u65e5\u5fd7<\/h2>\n<p>\u65e5\u5fd7\u7684\u82f1\u8bed\u662f\u201clog\u201d\uff0c\u4f46Kafka\u7684\u6570\u636e\u6587\u4ef6\u4e5f\u88ab\u79f0\u4e3alog\uff0c\u6240\u4ee5\u5f88\u591a\u65f6\u5019\u4f1a\u9020\u6210\u4e00\u5b9a\u7684\u6b67\u4e49\u3002\u5728Kafka\u4e2d\uff0c\u65e5\u5fd7\u5206\u4e3a\u4e24\u79cd\uff1a<\/p>\n<ul>\n<li>\u6570\u636e\u65e5\u5fd7<\/li>\n<li>\u64cd\u4f5c\u65e5\u5fd7<\/li>\n<\/ul>\n<p>\u6570\u636e\u65e5\u5fd7\u662f\u6307Kafka\u7684topic\u4e2d\u5b58\u50a8\u7684\u6570\u636e\uff0c\u8fd9\u79cd\u65e5\u5fd7\u7684\u8def\u5f84\u662f\u5728<code>$KAFKA_HOME\/config\/server.properties<\/code>\u6587\u4ef6\u4e2d\u914d\u7f6e\uff0c\u914d\u7f6e\u9879\u4e3alog.dirs\u3002\u5982\u679c\u6b64\u9879\u6ca1\u6709\u88ab\u914d\u7f6e\uff0c\u9ed8\u8ba4\u4f1a\u4f7f\u7528\u914d\u7f6e\u9879 log.dir\uff08\u8bf7\u4ed4\u7ec6\u89c2\u5bdf\uff0c\u4e24\u4e2a\u914d\u7f6e\u9879\u6700\u540e\u5dee\u4e86\u4e00\u4e2as\uff09\u3002log.dir\u7684\u9ed8\u8ba4\u8def\u5f84\u4e3a\/tmp\/kafka-logs\uff0c\u5927\u5bb6\u77e5\u9053\uff0c\/tmp\u8def\u5f84\u4e0b\u7684\u6587\u4ef6\u5728\u8ba1\u7b97\u673a\u91cd\u542f\u7684\u65f6\u5019\u662f\u4f1a\u88ab\u5220\u9664\u7684\uff0c\u56e0\u6b64\uff0c\u5f3a\u70c8\u63a8\u8350\u5c06\u6587\u4ef6\u76ee\u5f55\u8bbe\u7f6e\u5728\u5176\u4ed6\u53ef\u4ee5\u6c38\u4e45\u4fdd\u5b58\u7684\u8def\u5f84\u3002\u53e6\u4e00\u79cd\u65e5\u5fd7\u662f\u64cd\u4f5c\u65e5\u5fd7\uff0c\u7c7b\u4f3c\u4e8e\u6211\u4eec\u5728\u81ea\u5df1\u5f00\u53d1\u7684\u7a0b\u5e8f\u4e2d\u8f93\u51fa\u7684log\u65e5\u5fd7\uff08log4j\uff09\uff0c\u8fd9\u79cd\u65e5\u5fd7\u7684\u8def\u5f84\u662f\u5728\u542f\u52a8Kafka\u7684\u8def\u5f84\u4e0b\u3002\u6bd4\u5982\u4e00\u822c\u6211\u4eec\u5728KAFKA_HOMEl\u8def\u5f84\u4e0b\u542f\u52a8kafka\u670d\u52a1\uff0c\u64cd\u4f5c\u7684\u65e5\u5fd7\u8def\u5f84\u4e3a KAFKA_HOME\/logs\u3002<\/p>\n<h3>\u6570\u636e\u65e5\u5fd7\u6e05\u7406<\/h3>\n<p>\u6570\u636e\u65e5\u5fd7\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u6e05\u7406\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u6309\u7167\u65e5\u5fd7\u88ab\u53d1\u5e03\u7684\u65f6\u95f4\u6765\u5220\u9664\uff0c\u53e6\u4e00\u79cd\u662f\u6309\u7167\u65e5\u5fd7\u6587\u4ef6\u7684size\u6765\u5220\u9664\u3002\u6709\u4e13\u95e8\u7684\u914d\u7f6e\u9879\u53ef\u4ee5\u914d\u7f6e\u8fd9\u4e2a\u5220\u9664\u7b56\u7565\uff1a<\/p>\n<h4>\u6309\u65f6\u95f4\u5220\u9664\uff1a<\/h4>\n<p>Kafka\u63d0\u4f9b\u4e86\u914d\u7f6e\u9879\u8ba9\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u65e5\u5fd7\u88ab\u53d1\u5e03\u7684\u65f6\u95f4\u6765\u5220\u9664\u3002\u5b83\u4eec\u5206\u522b\u662f\uff1a<\/p>\n<ul>\n<li>log.retention.ms<\/li>\n<li>log.retention.minutes<\/li>\n<li>log.retention.hours<\/li>\n<\/ul>\n<p>\u6839\u636e\u914d\u7f6e\u9879\u7684\u540d\u79f0\u5f88\u5bb9\u6613\u7406\u89e3\u5b83\u4eec\u7684\u542b\u4e49\u3002log.retention.ms\u8868\u793a\u65e5\u5fd7\u4f1a\u88ab\u4fdd\u7559\u591a\u5c11\u6beb\u79d2\uff0c\u5982\u679c\u4e3anull\uff0c\u5219Kafka\u4f1a\u4f7f\u7528\u4f7f\u7528log.retention.minutes\u914d\u7f6e\u9879\u3002log.retention.minutes\u8868\u793a\u65e5\u5fd7\u4f1a\u4fdd\u7559\u591a\u5c11\u5206\u949f\uff0c\u5982\u679c\u4e3anull\uff0c\u5219Kafka\u4f1a\u4f7f\u7528log.retention.hours\u9009\u9879\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0clog.retention.ms\u548clog.retention.minutes\u5747\u4e3anull\uff0clog.retention.hours\u4e3a168\uff0c\u5373Kafka\u7684\u6570\u636e\u65e5\u5fd7\u9ed8\u8ba4\u4f1a\u88ab\u4fdd\u75597\u5929\u3002\u5982\u679c\u60f3\u4fee\u6539Kafka\u4e2d\u6570\u636e\u65e5\u5fd7\u88ab\u4fdd\u7559\u7684\u65f6\u95f4\u957f\u5ea6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u8fd9\u4e09\u4e2a\u9009\u9879\u6765\u5b9e\u73b0\u3002<\/p>\n<h4>\u6309size\u5220\u9664<\/h4>\n<p>Kafka\u9664\u4e86\u63d0\u4f9b\u4e86\u6309\u65f6\u95f4\u5220\u9664\u7684\u914d\u7f6e\u9879\u5916\uff0c\u4e5f\u63d0\u4f9b\u4e86\u6309\u7167\u65e5\u5fd7\u6587\u4ef6\u7684size\u6765\u5220\u9664\u7684\u914d\u7f6e\u9879\uff1a<\/p>\n<ul>\n<li>log.retention.bytes<\/li>\n<\/ul>\n<p>\u5373\u65e5\u5fd7\u6587\u4ef6\u5230\u8fbe\u591a\u5c11byte\u540e\u518d\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\u3002\u9ed8\u8ba4\u4e3a-1\uff0c\u5373\u65e0\u9650\u5236\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e2a\u9009\u9879\u7684\u503c\u5982\u679c\u5c0f\u4e8esegment\u6587\u4ef6\u5927\u5c0f\u7684\u8bdd\u662f\u4e0d\u8d77\u4f5c\u7528\u7684\u3002segment\u6587\u4ef6\u7684\u5927\u5c0f\u53d6\u51b3\u4e8elog.segment.bytes\u914d\u7f6e\u9879\uff0c\u9ed8\u8ba4\u4e3a1G\u3002<br \/>\n\u53e6\u5916\uff0cKafka\u7684\u65e5\u5fd7\u5220\u9664\u7b56\u7565\u5e76\u4e0d\u662f\u975e\u5e38\u4e25\u683c\u7684\uff08\u6bd4\u5982\u5982\u679clog.retention.bytes\u8bbe\u7f6e\u4e8610G\u7684\u8bdd\uff0c\u5e76\u4e0d\u662f\u8d85\u8fc710G\u7684\u90e8\u5206\u5c31\u4f1a\u7acb\u523b\u5220\u9664\uff0c\u53ea\u662f\u88ab\u6807\u8bb0\u4e3a\u5f85\u5220\u9664\uff0cKafka\u4f1a\u5728\u6070\u5f53\u7684\u65f6\u5019\u518d\u771f\u6b63\u5220\u9664\uff09\uff0c\u6240\u4ee5\u8bf7\u9884\u7559\u8db3\u591f\u7684\u78c1\u76d8\u7a7a\u95f4\u3002\u5f53\u78c1\u76d8\u7a7a\u95f4\u5269\u4f59\u91cf\u4e3a0\u65f6\uff0cKafka\u670d\u52a1\u4f1a\u88abkill\u6389\u3002<\/p>\n<h3>\u64cd\u4f5c\u65e5\u5fd7\u6e05\u7406<\/h3>\n<p>\u76ee\u524dKafka\u7684\u64cd\u4f5c\u65e5\u5fd7\u6682\u65f6\u4e0d\u63d0\u4f9b\u81ea\u52a8\u6e05\u7406\u7684\u673a\u5236\uff0c\u9700\u8981\u8fd0\u7ef4\u4eba\u5458\u624b\u52a8\u5e72\u9884\uff0c\u6bd4\u5982\u4f7f\u7528shell\u548ccrontab\u547d\u4ee4\u8fdb\u884c\u5b9a\u65f6\u5907\u4efd\u3001\u6e05\u7406\u7b49\u3002<\/p>\n<h2>Kafka\u914d\u7f6eIP\u8bbf\u95ee<\/h2>\n<p>\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8bbf\u95eeKafka\u96c6\u7fa4\u9700\u8981\u5728<code>\/etc\/hosts<\/code>\u6587\u4ef6\u4e0b\u914d\u7f6e\u6240\u6709Kafka\u96c6\u7fa4\u7684hostname\uff0c\u8fd9\u6837\u6bd4\u8f83\u9ebb\u70e6\u3002\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6eadvertised.listeners\u914d\u7f6e\u9879\u6765\u4f7f\u7528ip\u6765\u8bbf\u95eeKafka\u96c6\u7fa4\uff0c\u6bd4\u5982\u5355\u53f0Kafka broker\u7684ip\u5730\u5740\u4e3a192.168.1.100\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u914d\u7f6e\u6765\u4f7f\u5ba2\u6237\u7aef\u6765\u4f7f\u7528ip\u8bbf\u95ee\uff1a<\/p>\n<blockquote><p>advertised.listeners=PLAINTEXT:\/\/192.168.1.100:9092<\/p><\/blockquote>\n<h2>Kafka\u7684\u57fa\u672c\u64cd\u4f5c<\/h2>\n<p>\u63a5\u4e0b\u6765\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u5173\u4e8eKafka\u96c6\u7fa4\u7684\u57fa\u672c\u64cd\u4f5c\u3002\u6240\u6709\u8fd9\u4e9b\u7528\u5230\u7684\u5de5\u5177\u5168\u90e8\u5728Kafka\u76ee\u5f55\u4e0b\u7684<code>\/bin<\/code>\u76ee\u5f55\u4e0b\u53ef\u4ee5\u627e\u5230\u3002\u5982\u679c\u4e0d\u6dfb\u52a0\u4efb\u4f55\u53c2\u6570\u8fd0\u884c\u8fd9\u4e9b\u5de5\u5177\u811a\u672c\uff0c\u63a7\u5236\u53f0\u4e0a\u4f1a\u6253\u5370\u4f7f\u7528\u7684\u63d0\u793a\u3002<\/p>\n<h4>\u6dfb\u52a0topic<\/h4>\n<p>\u5728Kafka\u4e2d\u6dfb\u52a0topic\u6709\u4e24\u79cd\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u624b\u52a8\u6dfb\u52a0\uff0c\u53e6\u4e00\u79cd\u662f\u5728\u6570\u636e\u7b2c\u4e00\u6b21\u5199\u5165\u7684\u65f6\u5019\u52a8\u6001\u6dfb\u52a0\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\u8fd8\u662f\u63a8\u8350\u624b\u52a8\u6dfb\u52a0topic\u3002<br \/>\n\u4f7f\u7528topic\u5de5\u5177\u521b\u5efatopic\uff1a<\/p>\n<blockquote><p>bin\/kafka-topics.sh &#8211;zookeeper zk_host:port\/chroot &#8211;create &#8211;topic my_topic_name &#8211;partitions 20 &#8211;replication-factor 3 &#8211;config x=y<\/p><\/blockquote>\n<p>replication-factor\u53c2\u6570\u7528\u6765\u6307\u5b9a\u9700\u8981\u591a\u5c11\u4e2a\u526f\u672c\uff08\u8fde\u540cleader\u5728\u5185\uff09\uff0c\u4e00\u822c\u6bd4\u8f83\u63a8\u8350\u8bbe\u7f6e\u4e3a2\u62163\u3002\u5982\u679c\u8bbe\u7f6e\u592a\u5c11\uff08\u6bd4\u59821\uff09\u5bfc\u81f4\u53ef\u7528\u6027\u4e0b\u964d\uff0c\u5982\u679c\u8bbe\u7f6e\u592a\u5927\u4f1a\u5f71\u54cdKafka\u7684\u6027\u80fd\u3002<br \/>\npartitions\u53c2\u6570\u7528\u6765\u8bbe\u7f6etopic\u6709\u591a\u5c11\u4e2apartition\u3002\u9996\u5148\uff0c\u6bcf\u4e2apartition\u5fc5\u987b\u5b58\u5728\u4e8e\u5355\u53f0\u670d\u52a1\u5668\u4e0a\uff0c\u5c31\u662f\u8bf4\u5982\u679c\u67d0\u4e2atopic\u670920\u4e2apartition\uff0c\u90a3\u4e48\u5b83\u4eec\u5c06\u6700\u591a\u5206\u5e03\u572820\u53f0\u670d\u52a1\u5668\u4e0a\uff08\u4e0d\u7b97replicas\uff09\u3002\u53e6\u5916\u5f88\u91cd\u8981\u7684\u4e00\u70b9\u662f\uff0cpartition\u7684\u6570\u91cf\u5c06\u76f4\u63a5\u5f71\u54cd\u6d88\u8d39\u7aef\u7a0b\u5e8f\u7684\u5e76\u884c\u5ea6\u3002\u6240\u4ee5\u521b\u5efatopic\u65f6\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u51b3\u5b9apartition\u6570\u91cf\u3002<\/p>\n<h4>\u4fee\u6539topic<\/h4>\n<p>\u4fee\u6539topic\u4e3b\u8981\u662f\u4e3a\u4e86\u4fee\u6539topic\u7684partition\u6570\u91cf\u548ctopic\u5c42\u9762\u7684\u914d\u7f6e\u3002\u4fee\u6539partition\u6570\u91cf\u53ef\u4ee5\u4f7f\u7528\u6b64\u547d\u4ee4\uff1a<\/p>\n<blockquote><p>bin\/kafka-topics.sh &#8211;zookeeper zk_host:port &#8211;alter &#8211;topic my_topic_name &#8211;partitions 40<\/p><\/blockquote>\n<p>\u5173\u4e8e\u4fee\u6539partition\u6570\u91cf\uff0c\u6709\u4e24\u70b9\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ol>\n<li>partition\u53ea\u80fd\u589e\u52a0\uff0c\u4e0d\u652f\u6301\u51cf\u5c11<\/li>\n<li>\u65b0\u589e\u7684partition\u53ea\u4f1a\u5bf9\u5c06\u6765\u5199\u5165\u7684\u6570\u636e\u8d77\u4f5c\u7528\uff0c\u4ee5\u524d\u5b58\u5728\u7684\u6570\u636e\u4e0d\u4f1a\u88ab\u79fb\u52a8\u5230\u65b0\u7684partition\u4e2d<\/li>\n<\/ol>\n<p>\u9664\u4e86\u4fee\u6539partition\u6570\u91cf\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4fee\u6539topic\u5c42\u9762\u7684\u914d\u7f6e\uff0c\u589e\u52a0\u914d\u7f6e\u9879\uff1a<\/p>\n<blockquote><p>bin\/kafka-topics.sh &#8211;zookeeper zk_host:port\/chroot &#8211;alter &#8211;topic my_topic_name &#8211;config x=y<\/p><\/blockquote>\n<p>\u5220\u9664\u914d\u7f6e\u9879\uff1a<\/p>\n<blockquote><p>bin\/kafka-topics.sh &#8211;zookeeper zk_host:port\/chroot &#8211;alter &#8211;topic my_topic_name &#8211;delete-config x<\/p><\/blockquote>\n<h4>\u5220\u9664topic<\/h4>\n<p>Kafka\u5220\u9664topic\u7684\u65b9\u6cd5\u4e5f\u5f88\u7b80\u5355\u3002\u9996\u5148\uff0c\u9700\u8981\u5728config\/server.properties\u6587\u4ef6\u4e2d\u914d\u7f6e<\/p>\n<blockquote><p>delete.topic.enable=true<\/p><\/blockquote>\n<p>\u8fd9\u4e2a\u914d\u7f6e\u9879\u9ed8\u8ba4\u662f\u5173\u95ed\u7684\uff0c\u4e5f\u5c31\u662f\u4e0d\u652f\u6301\u5220\u9664\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u914d\u7f6e\u4e3atrue\u3002\u7136\u540e\u4f7f\u7528\u547d\u4ee4\uff1a<\/p>\n<blockquote><p>.\/bin\/kafka-topics.sh &#8211;zookeeper zk_host:port &#8211;delete &#8211;topic my_topic_name<\/p><\/blockquote>\n<p>\u5c31\u53ef\u4ee5\u5220\u9664topic\u4e86\u3002<\/p>\n<h4>\u67e5\u770b\u6d88\u8d39\u8005\u4f4d\u7f6e<\/h4>\n<p>\u6709\u4e9b\u65f6\u5019\u6211\u4eec\u9700\u8981\u67e5\u770b\u67d0\u4e2a\u6d88\u8d39\u8005\u7ec4\u7684\u6d88\u8d39\u60c5\u51b5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177kafka-consumer-groups.sh\u6765\u67e5\u770b\u3002<\/p>\n<blockquote><p>.\/bin\/kafka-consumer-groups.sh &#8211;bootstrap-server localhost:9092 &#8211;describe &#8211;group test<\/p><\/blockquote>\n<h4>\u67e5\u770b\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u7684\u6d88\u8d39\u8005\u7ec4<\/h4>\n<p>\u81ea\u4ecekafka 0.9.0.0\u7248\u672c\uff0cKafka\u5f15\u5165\u4e86\u65b0\u7684Java consumer\u6a21\u5757\u4ee3\u66ff\u4e86\u539f\u6765\u7684Scala consumer\u6a21\u5757\u3002\u6d88\u8d39\u8005\u7ec4\u7684\u5143\u6570\u636e\u4ecezookeeper\u8fc1\u79fb\u5230\u4e86broker\u4e2d\uff0c\u6240\u4ee5\u4f7f\u7528\u65b0\u7684API\u67e5\u770b\u6d88\u8d39\u8005\u7ec4\u5217\u8868\uff1a<\/p>\n<blockquote><p>.\/bin\/kafka-consumer-groups.sh &#8211;bootstrap-server localhost:9092 &#8211;list<\/p><\/blockquote>\n<h4>\u67e5\u770btopic\u7684\u6bcf\u4e2apartition\u72b6\u6001<\/h4>\n<blockquote><p>.\/bin\/kafka-run-class.sh kafka.tools.GetOffsetShell &#8211;broker-list localhost:9092 &#8211;topic test &#8211;time -1<\/p><\/blockquote>\n<h2>\u6269\u5c55Kafka\u96c6\u7fa4<\/h2>\n<p>\u5411Kafka\u96c6\u7fa4\u6dfb\u52a0\u670d\u52a1\u5668\u662f\u5f88\u7b80\u5355\u7684\uff0c\u5206\u914d\u7ed9\u5b83\u4eec\u4e00\u4e2a\u552f\u4e00\u7684broker id\u5e76\u4e14\u5728\u65b0\u670d\u52a1\u5668\u4e0a\u542f\u52a8Kafka\u670d\u52a1\u5668\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u662f\u8fd9\u4e9b\u65b0\u670d\u52a1\u5668\u5374\u4e0d\u80fd\u88ab\u81ea\u52a8\u5206\u914d\u6570\u636e\u5206\u533a\uff08partition\uff09\uff0c\u6240\u4ee5\u9664\u975epartition\u88ab\u79fb\u52a8\u5230\u8fd9\u4e9b\u670d\u52a1\u5668\u4e0a\uff0c\u5426\u8005\u8fd9\u4e9b\u670d\u52a1\u5668\u76f4\u5230\u65b0\u5efatopic\u7684\u65f6\u5019\u624d\u4f1a\u53d1\u6325\u4f5c\u7528\u3002\u6240\u4ee5\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u5f53\u4f60\u6dfb\u52a0\u670d\u52a1\u5668\u5230\u4f60\u7684\u96c6\u7fa4\u4e2d\u65f6\uff0c\u4f60\u90fd\u5e0c\u671b\u8fc1\u79fb\u4e00\u4e9b\u5df2\u7ecf\u5b58\u5728\u7684\u6570\u636e\u5230\u8fd9\u4e9b\u670d\u52a1\u5668\u4e0a\u3002<br \/>\n\u8fc1\u79fb\u6570\u636e\u7684\u7684\u8fc7\u7a0b\u662f\u624b\u52a8\u542f\u52a8\u7684\uff0c\u4f46\u662f\u6267\u884c\u662f\u81ea\u52a8\u5316\u7684\u3002\u5185\u5728\u8fc7\u7a0b\u5c31\u662fKafka\u5c06\u8fd9\u4e9b\u65b0\u670d\u52a1\u5668\u6dfb\u52a0\u4f5c\u4e3a\u5b83\u4eec\u6b63\u5728\u8fc1\u79fb\u7684partition\u7684follower\u5e76\u4e14\u5141\u8bb8\u5b83\u5168\u90e8\u590d\u5236\u8fd9\u4e2a\u5206\u533a\u4e2d\u5df2\u5b58\u5728\u7684\u6570\u636e\u3002\u5f53\u65b0\u670d\u52a1\u5668\u5b8c\u5168\u590d\u5236\u6b64\u5206\u533a\u7684\u5185\u5bb9\u5e76\u52a0\u5165\u540c\u6b65\u526f\u672c\u65f6\uff0c\u73b0\u6709\u526f\u672c\u4e4b\u4e00\u5c06\u5220\u9664\u5176\u5206\u533a\u7684\u6570\u636e\u3002<br \/>\n\u91cd\u65b0\u5206\u914d\u5206\u533a\u5de5\u5177\uff08partition reassignment tool\uff09\u53ef\u4ee5\u88ab\u7528\u6765\u5728brokers\u95f4\u79fb\u52a8partition\u3002\u7406\u60f3\u7684partition\u5206\u914d\u4f1a\u786e\u4fdd\u8de8broker\u7684\u5747\u5300\u7684\u6570\u636e\u8d1f\u8f7d\u548c\u5206\u533a\u5927\u5c0f\u3002\u91cd\u65b0\u5206\u914d\u5206\u533a\u5de5\u5177\u5e76\u6ca1\u6709\u81ea\u52a8\u83b7\u53d6Kafka\u96c6\u7fa4\u4e2d\u7684\u6570\u636e\u5206\u5e03\u4fe1\u606f\u5e76\u5747\u8861\u8d1f\u8f7d\u7684\u80fd\u529b\u3002\u56e0\u6b64\uff0c\u7ba1\u7406\u5458\u5fc5\u987b\u6e05\u695a\u8981\u79fb\u52a8\u54ea\u4e9btopic\u6216partition\u3002<br \/>\n\u91cd\u65b0\u5206\u914d\u5206\u533a\u5de5\u5177\u6709\u4ee5\u4e0b\u4e09\u79cd\u4e92\u65a5\u7684\u8fd0\u884c\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li>generate\uff1a\u5728\u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0c\u7ed9\u51fatopic\u5217\u8868\u548cbroker\u5217\u8868\uff0c\u5206\u533a\u5de5\u5177\u5c06\u751f\u6210\u4e00\u4e2a\u5019\u9009\u7684\u5206\u533a\u65b9\u6848\u7528\u6765\u5c06\u6307\u5b9atopic\u7684\u6240\u6709\u5206\u533a\u79fb\u52a8\u5230\u65b0broker\u4e0a\u3002\u8fd9\u4e2a\u9009\u9879\u4ec5\u4ec5\u63d0\u4f9b\u4e86\u4e00\u79cd\u901a\u8fc7\u7ed9\u51fa\u7684topic\u5217\u8868\u548cbroker\u5217\u8868\u751f\u6210\u5206\u533a\u91cd\u65b0\u5206\u914d\u65b9\u6848\u7684\u7b80\u4fbf\u65b9\u5f0f\u3002<\/li>\n<li>execute\uff1a\u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0c\u5206\u533a\u5de5\u5177\u5c06\u6839\u636e\u7528\u6237\u63d0\u4f9b\u7684\u91cd\u65b0\u5206\u533a\u65b9\u6848\u5f00\u59cb\u91cd\u65b0\u5206\u533a\uff08\u4f7f\u7528 &#8212; &#8211;reassignment-json-file \uff09\u3002\u8fd9\u4e2a\u9009\u9879\u65e2\u53ef\u4ee5\u6267\u884c\u7ba1\u7406\u5458\u624b\u5199\u7684\u91cd\u65b0\u5206\u533a\u6587\u4ef6\u4e5f\u53ef\u4ee5\u6267\u884c\u901a\u8fc7&#8211;generate\u547d\u4ee4\u751f\u6210\u7684\u91cd\u65b0\u5206\u533a\u6587\u4ef6\u3002<\/li>\n<li>verify\uff1a\u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0c\u5206\u533a\u5de5\u5177\u9a8c\u8bc1\u4e0a\u6b21\u6267\u884c-generate\u4ee5\u6765\u88ab\u91cd\u65b0\u5206\u533a\u7684\u6240\u6709partition\u7684\u72b6\u6001\u3002\u8fd9\u4e9b\u72b6\u6001\u53ef\u80fd\u662fsuccessfully completed\uff08\u6210\u529f\u5b8c\u6210\uff09, failed\uff08\u5931\u8d25\uff09\u6216in progress\uff08\u8fdb\u884c\u4e2d\uff09<\/li>\n<\/ul>\n<h4>\u81ea\u52a8\u8fc1\u79fb\u6570\u636e\u5230\u65b0\u7684\u670d\u52a1\u5668\u4e0a<\/h4>\n<p>\u91cd\u65b0\u5206\u533a\u5de5\u5177\u53ef\u4ee5\u5c06\u5f53\u524dbrokers\u4e0a\u7684topics\u79fb\u52a8\u5230\u65b0\u7684brokers\u4e0a\u3002\u8fd9\u5728\u6269\u5c55\u73b0\u6709\u96c6\u7fa4\u65f6\u5f88\u6709\u7528\uff0c\u56e0\u4e3a\u5c06\u6574\u4e2atopic\u79fb\u52a8\u5230\u65b0brokers\u4e0a\u6bd4\u4e00\u6b21\u79fb\u52a8\u4e00\u4e2apartition\u66f4\u5bb9\u6613\u3002\u7136\u540e\uff0c\u5206\u533a\u5de5\u5177\u53ef\u4ee5\u5728\u65b0\u7684brokers\u4e2d\u5747\u5300\u5206\u914d\u7ed9\u5b9atopic\u96c6\u5408\u4e2d\u7684\u6240\u6709partition\u3002\u5728\u79fb\u52a8\u8fc7\u7a0b\u4e2d\uff0creplication factor\uff08\u526f\u672c\u6570\uff09\u4fdd\u6301\u4e0d\u53d8\u3002<br \/>\n\u4e3e\u4f8b\u6765\u8bf4\uff0c\u4e0b\u9762\u7684\u4f8b\u5b50\u5c06\u4f1a\u628atopics foo1\u3001foo2\u7684\u6240\u6709partition\u79fb\u52a8\u5230\u65b0\u7684brokers 5,6\u3002\u5f53\u79fb\u52a8\u884c\u4e3a\u7ed3\u675f\u4ee5\u540e\uff0cfoo1\u548cfoo2\u7684\u6240\u6709partition\u5c06\u4ec5\u5b58\u5728\u4e8ebroker 5\u30016\u3002<br \/>\n\u56e0\u4e3a\u5206\u533a\u5de5\u5177\u63a5\u53d7\u5c06topic\u5217\u8868\u5199\u5165json\u6587\u4ef6\u7684\u5f62\u5f0f\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u6307\u5b9a\u9700\u8981\u79fb\u52a8\u7684topics\u5e76\u521b\u5efajson\u6587\u4ef6\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<blockquote><p>cat topics-to-move.json<br \/>\n{ \\&#8221;topics\\&#8221;: [{\\&#8221;topic\\&#8221;: \\&#8221;foo1\\&#8221;}, {\\&#8221;topic\\&#8221;: \\&#8221;foo2\\&#8221;}], \\&#8221;version\\&#8221;:1 }<\/p><\/blockquote>\n<p>\u5f53json\u6587\u4ef6\u51c6\u5907\u597d \u4e86\u4ee5\u540e\uff0c\u4f7f\u7528\u91cd\u65b0\u5206\u533a\u5de5\u5177\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u5019\u9009\u7684\u91cd\u65b0\u5206\u914d\u8ba1\u5212\uff1a<\/p>\n<blockquote><p>bin\/kafka-reassign-partitions.sh &#8211;zookeeper localhost:2181 &#8211;topics-to-move-json-file topics-to-move.json &#8211;broker-list \\&#8221;5,6\\&#8221; &#8211;generate&lt;\/br&gt;<br \/>\nCurrent partition replica assignment&lt;\/br&gt;<br \/>\n{\\&#8221;version\\&#8221;:1,<br \/>\n\\&#8221;partitions\\&#8221;:[{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:2,\\&#8221;replicas\\&#8221;:[1,2]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[3,4]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:2,\\&#8221;replicas\\&#8221;:[1,2]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[3,4]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[2,3]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[2,3]}]<\/p><\/blockquote>\n<div class=\\\"_2Uzcx_\\\">\n<pre class=\\\"line-numbers  language-swift\\\"><code class=\\\"  language-swift\\\"><span class=\\\"token punctuation\\\">}<\/span><span class=\\\"token operator\\\">&lt;<\/span><span class=\\\"token operator\\\">\/<\/span>br<span class=\\\"token operator\\\">&gt;<\/span>\n    <span class=\\\"token builtin\\\">Proposed<\/span> <span class=\\\"token builtin\\\">partition<\/span> reassignment configuration<span class=\\\"token operator\\\">&lt;<\/span><span class=\\\"token operator\\\">\/<\/span>br<span class=\\\"token operator\\\">&gt;<\/span>\n<span class=\\\"token punctuation\\\">{<\/span><span class=\\\"token string\\\">\\\"version\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token number\\\">1<\/span><span class=\\\"token punctuation\\\">,<\/span>\n<span class=\\\"token string\\\">\\\"partitions\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token punctuation\\\">[<\/span><span class=\\\"token punctuation\\\">{<\/span><span class=\\\"token string\\\">\\\"topic\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token string\\\">\\\"foo1\\\"<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"partition\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token number\\\">2<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"replicas\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token punctuation\\\">[<\/span><span class=\\\"token number\\\">5<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token number\\\">6<\/span><span class=\\\"token punctuation\\\">]<\/span><span class=\\\"token punctuation\\\">}<\/span><span class=\\\"token punctuation\\\">,<\/span>\n                <span class=\\\"token punctuation\\\">{<\/span><span class=\\\"token string\\\">\\\"topic\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token string\\\">\\\"foo1\\\"<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"partition\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token number\\\">0<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"replicas\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token punctuation\\\">[<\/span><span class=\\\"token number\\\">5<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token number\\\">6<\/span><span class=\\\"token punctuation\\\">]<\/span><span class=\\\"token punctuation\\\">}<\/span><span class=\\\"token punctuation\\\">,<\/span>\n                <span class=\\\"token punctuation\\\">{<\/span><span class=\\\"token string\\\">\\\"topic\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token string\\\">\\\"foo2\\\"<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"partition\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token number\\\">2<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"replicas\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token punctuation\\\">[<\/span><span class=\\\"token number\\\">5<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token number\\\">6<\/span><span class=\\\"token punctuation\\\">]<\/span><span class=\\\"token punctuation\\\">}<\/span><span class=\\\"token punctuation\\\">,<\/span>\n                <span class=\\\"token punctuation\\\">{<\/span><span class=\\\"token string\\\">\\\"topic\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token string\\\">\\\"foo2\\\"<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"partition\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token number\\\">0<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"replicas\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token punctuation\\\">[<\/span><span class=\\\"token number\\\">5<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token number\\\">6<\/span><span class=\\\"token punctuation\\\">]<\/span><span class=\\\"token punctuation\\\">}<\/span><span class=\\\"token punctuation\\\">,<\/span>\n                <span class=\\\"token punctuation\\\">{<\/span><span class=\\\"token string\\\">\\\"topic\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token string\\\">\\\"foo1\\\"<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"partition\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token number\\\">1<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"replicas\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token punctuation\\\">[<\/span><span class=\\\"token number\\\">5<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token number\\\">6<\/span><span class=\\\"token punctuation\\\">]<\/span><span class=\\\"token punctuation\\\">}<\/span><span class=\\\"token punctuation\\\">,<\/span>\n                <span class=\\\"token punctuation\\\">{<\/span><span class=\\\"token string\\\">\\\"topic\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token string\\\">\\\"foo2\\\"<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"partition\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token number\\\">1<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token string\\\">\\\"replicas\\\"<\/span><span class=\\\"token punctuation\\\">:<\/span><span class=\\\"token punctuation\\\">[<\/span><span class=\\\"token number\\\">5<\/span><span class=\\\"token punctuation\\\">,<\/span><span class=\\\"token number\\\">6<\/span><span class=\\\"token punctuation\\\">]<\/span><span class=\\\"token punctuation\\\">}<\/span><span class=\\\"token punctuation\\\">]<\/span>\n  <span class=\\\"token punctuation\\\">}<\/span>\n<\/code><\/pre>\n<\/div>\n<p>\u5206\u533a\u5de5\u5177\u751f\u6210\u7684\u5019\u9009\u8ba1\u5212\u5c06\u4f1a\u5c06topic foo1,foo2\u7684\u6240\u6709\u5206\u533a\u79fb\u52a8\u5230broker 5,6\u3002\u8bb0\u4f4f\uff0c\u5c3d\u7ba1\u5230\u4e86\u8fd9\u4e00\u6b65\uff0cpartition\u7684\u79fb\u52a8\u5374\u5c1a\u672a\u5f00\u59cb\uff0c\u800c\u4ec5\u4ec5\u544a\u8bc9\u4f60\u5f53\u524d\u7684\u5206\u533a\u60c5\u51b5\uff08Current partition replica assignment\uff09\u548c\u5efa\u8bae\u7684\u65b0\u5206\u533a\u65b9\u6848\uff08Proposed partition reassignment configuration\uff09\u3002\u5f53\u524d\u5206\u533a\u60c5\u51b5\u5e94\u8be5\u4fdd\u7559\u8d77\u6765\uff0c\u4ee5\u9632\u4f60\u60f3\u8981\u56de\u6eda\u3002\u65b0\u5206\u533a\u65b9\u6848\u5e94\u8be5\u88ab\u5b58\u5165\u4e00\u4e2ajosn\u6587\u4ef6\u4e2d\uff0c\uff08\u6bd4\u5982\uff1aexpand-cluster-reassignment.json\uff09\uff0c\u7136\u540e\u4f5c\u4e3a\u5206\u533a\u5de5\u5177 &#8211;execute\u9009\u9879\u7684\u8f93\u5165\u6587\u4ef6\u3002\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<blockquote><p>bin\/kafka-reassign-partitions.sh &#8211;zookeeper localhost:2181 &#8211;reassignment-json-file expand-cluster-reassignment.json &#8211;execute&lt;\/br&gt;<br \/>\nCurrent partition replica assignment&lt;\/br&gt;<br \/>\n{\\&#8221;version\\&#8221;:1,<br \/>\n\\&#8221;partitions\\&#8221;:[{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:2,\\&#8221;replicas\\&#8221;:[1,2]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[3,4]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:2,\\&#8221;replicas\\&#8221;:[1,2]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[3,4]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[2,3]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[2,3]}]<br \/>\n}&lt;\/br&gt;<br \/>\nSave this to use as the &#8211;reassignment-json-file option during rollback<br \/>\nSuccessfully started reassignment of partitions<br \/>\n{\\&#8221;version\\&#8221;:1,<br \/>\n\\&#8221;partitions\\&#8221;:[{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:2,\\&#8221;replicas\\&#8221;:[5,6]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[5,6]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:2,\\&#8221;replicas\\&#8221;:[5,6]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[5,6]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[5,6]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[5,6]}]<br \/>\n}<\/p><\/blockquote>\n<p>\u6700\u540e\uff0c&#8211;verify\u9009\u9879\u53ef\u4ee5\u7528\u6765\u68c0\u67e5\u91cd\u65b0\u5206\u914d\u5206\u533a\u7684\u72b6\u6001\u3002\u6ce8\u610f\u6b64\u5904\u5e94\u8be5\u4f7f\u7528\u4e0e\u6267\u884c &#8211;execute \u9009\u9879\u65f6\u76f8\u540c\u7684expand-cluster-reassignment.json \u6587\u4ef6\uff1a<\/p>\n<blockquote><p>bin\/kafka-reassign-partitions.sh &#8211;zookeeper localhost:2181 &#8211;reassignment-json-file expand-cluster-reassignment.json &#8211;verify<br \/>\nStatus of partition reassignment:<br \/>\nReassignment of partition [foo1,0] completed successfully<br \/>\nReassignment of partition [foo1,1] is in progress<br \/>\nReassignment of partition [foo1,2] is in progress<br \/>\nReassignment of partition [foo2,0] completed successfully<br \/>\nReassignment of partition [foo2,1] completed successfully<br \/>\nReassignment of partition [foo2,2] completed successfully<\/p><\/blockquote>\n<h4>\u81ea\u5b9a\u4e49\u5206\u533a\u5206\u914d\u548c\u79fb\u52a8<\/h4>\n<p>\u5206\u533a\u91cd\u65b0\u5206\u914d\u5de5\u5177\u4e5f\u53ef\u4ee5\u88ab\u7528\u6765\u79fb\u52a8broker\u88ab\u9009\u4e2d\u7684\u5206\u533a\u3002\u5f53\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5047\u8bbe\u7528\u6237\u4e86\u89e3\u91cd\u65b0\u5206\u914d\u5206\u533a\u65b9\u6848\u5e76\u4e14\u4e0d\u9700\u8981\u4f7f\u7528\u5206\u533a\u5de5\u5177\u53bb\u81ea\u52a8\u751f\u6210\u5019\u9009\u91cd\u65b0\u5206\u533a\u65b9\u6848\u3002\u4e3a\u4e86\u9ad8\u6548\uff0c\u6211\u4eec\u8df3\u8fc7\u4e86&#8211;generate\u6b65\u9aa4\uff0c\u76f4\u63a5\u6765\u5230&#8211;execute\u6b65\u9aa4<br \/>\n\u4e3e\u4f8b\u6765\u8bf4\uff0c\u4e0b\u9762\u7684\u4f8b\u5b50\u5c06topic foo1\u7684partition 0\u79fb\u52a8\u5230 broker 5,6\uff0c\u5c06topic foo2\u7684partition 1 \u79fb\u52a8\u5230broker 2,3\uff1a<br \/>\n\u7b2c\u4e00\u6b65\u6765\u624b\u5199\u81ea\u5b9a\u4e49\u91cd\u65b0\u5206\u533a\u8ba1\u5212\u7684json\u6587\u4ef6\uff1a<\/p>\n<blockquote><p>cat custom-reassignment.json<br \/>\n{\\&#8221;version\\&#8221;:1,\\&#8221;partitions\\&#8221;:[{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[5,6]},{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[2,3]}]}<\/p><\/blockquote>\n<p>\u7136\u540e\uff0c\u4f7f\u7528&#8211;execute\u9009\u9879\u548cjson\u6587\u4ef6\u6765\u5f00\u59cb\u91cd\u65b0\u5206\u914d\u5206\u533a\u7684\u64cd\u4f5c\uff1a<\/p>\n<blockquote><p>bin\/kafka-reassign-partitions.sh &#8211;zookeeper localhost:2181 &#8211;reassignment-json-file custom-reassignment.json &#8211;execute<br \/>\nCurrent partition replica assignment&lt;\/br&gt;<br \/>\n{\\&#8221;version\\&#8221;:1,<br \/>\n\\&#8221;partitions\\&#8221;:[{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[1,2]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[3,4]}]<br \/>\n}&lt;\/br&gt;<br \/>\nSave this to use as the &#8211;reassignment-json-file option during rollback<br \/>\nSuccessfully started reassignment of partitions<br \/>\n{\\&#8221;version\\&#8221;:1,<br \/>\n\\&#8221;partitions\\&#8221;:[{\\&#8221;topic\\&#8221;:\\&#8221;foo1\\&#8221;,\\&#8221;partition\\&#8221;:0,\\&#8221;replicas\\&#8221;:[5,6]},<br \/>\n{\\&#8221;topic\\&#8221;:\\&#8221;foo2\\&#8221;,\\&#8221;partition\\&#8221;:1,\\&#8221;replicas\\&#8221;:[2,3]}]<br \/>\n}<\/p><\/blockquote>\n<p>\u7528&#8211;verify\u9009\u9879\u6765\u67e5\u770b\u88ab\u91cd\u65b0\u5206\u914d\u5206\u533a\u7684\u72b6\u6001\u3002\u6ce8\u610f\u6b64\u5904\u5e94\u8be5\u4f7f\u7528\u4e0e\u6267\u884c &#8211;execute \u9009\u9879\u65f6\u76f8\u540c\u7684expand-cluster-reassignment.json \u6587\u4ef6\uff1a<\/p>\n<blockquote><p>bin\/kafka-reassign-partitions.sh &#8211;zookeeper localhost:2181 &#8211;reassignment-json-file custom-reassignment.json &#8211;verify<br \/>\nStatus of partition reassignment:<\/p><\/blockquote>\n<div>\n<pre>  Reassignment of partition [foo1,0] completed successfully\n  Reassignment of partition [foo2,1] completed successfully<\/pre>\n<\/div>\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8f6f\u4ef6\u9879\u76ee\u7684\u751f\u547d\u5468\u671f\u4e2d\uff0c\u5f00\u53d1\u53ea\u5360\u5f00\u59cb\u7684\u4e00\u5c0f\u90e8\u5206\uff0c\u5927\u90e8\u5206\u65f6\u95f4\u6211\u4eec\u8981\u5bf9\u9879\u76ee\u8fdb\u884c\u8fd0\u884c\u7ef4\u62a4\uff0cKafka\u76f8\u5173\u7684\u9879\u76ee\u4e5f\u4e0d\u4f8b &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1519\"> <span class=\"screen-reader-text\">Kafka\u65e5\u5e38\u7ef4\u62a4<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[127,118],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"\u5728\u8f6f\u4ef6\u9879\u76ee\u7684\u751f\u547d\u5468\u671f\u4e2d\uff0c\u5f00\u53d1\u53ea\u5360\u5f00\u59cb\u7684\u4e00\u5c0f\u90e8\u5206\uff0c\u5927\u90e8\u5206\u65f6\u95f4\u6211\u4eec\u8981\u5bf9\u9879\u76ee\u8fdb\u884c\u8fd0\u884c\u7ef4\u62a4\uff0cKafka\u76f8\u5173\u7684\u9879\u76ee\u4e5f\u4e0d\u4f8b&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1519"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1519"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1519\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1519"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}