操作背景
假如topic test.example中partition 0的replicas为[0,4],则0为preferred replica,应该成为leader。
这时我们期望4为preferred replica,并变成leader。
执行步骤如下:
1.查看当前的topic详细信息:
lizhitao@users-MacBook-Pro-2:~$ ./bin/kafka-topics.sh –zookeeper 192.168.2.225:2183/config/mobile/mq –describe –topic test.example
Topic:test.example PartitionCount:12 ReplicationFactor:2 Configs:
Topic: test.example Partition: 0 Leader: 0 Replicas: 0,4 Isr: 0,4
Topic: test.example Partition: 1 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 2 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: test.example Partition: 3 Leader: 0 Replicas: 0,4 Isr: 0,4
Topic: test.example Partition: 4 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 5 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: test.example Partition: 6 Leader: 0 Replicas: 0,4 Isr: 0,4
Topic: test.example Partition: 7 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 8 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: test.example Partition: 9 Leader: 0 Replicas: 0,4 Isr: 0,4
Topic: test.example Partition: 10 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 11 Leader: 2 Replicas: 2,3 Isr: 2,3
2.修改replicas的顺序
lizhitao@users-MacBook-Pro-2:~$ cat partitions-to-move.json
{
“partitions”: [
{
“topic”: “test.example”,
“partition”: 0,
“replicas”: [
4,
0
]
}
],
“version”: 1
}
lizhitao@users-MacBook-Pro-2:~$ ./bin/kafka-reassign-partitions.sh –zookeeper 192.168.2.225:2183/config/mobile/mq –reassignment-json-file partitions-to-move.json –execute
3.更改leader
lizhitao@users-MacBook-Pro-2:~$ cat topicPartitionList.json
{
“partitions”:
[
{“topic”: “test.example”, “partition”: 0}
]
}
lizhitao@users-MacBook-Pro-2:~$ ./bin/kafka-preferred-replica-election.sh –zookeeper 192.168.2.225:2183/config/mobile/mq –path-to-json-file topicPartitionList.json
4.检查replicas leader切换情况
lizhitao@users-MacBook-Pro-2:~$ ./bin/kafka-topics.sh –zookeeper 192.168.2.225:2183/config/mobile/mq –describe –topic test.example
Topic:test.example PartitionCount:12 ReplicationFactor:2 Configs:
Topic: test.example Partition: 0 Leader: 4 Replicas: 4,0 Isr: 0,4
Topic: test.example Partition: 1 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 2 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: test.example Partition: 3 Leader: 0 Replicas: 0,4 Isr: 0,4
Topic: test.example Partition: 4 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 5 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: test.example Partition: 6 Leader: 0 Replicas: 0,4 Isr: 0,4
Topic: test.example Partition: 7 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 8 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: test.example Partition: 9 Leader: 0 Replicas: 0,4 Isr: 0,4
Topic: test.example Partition: 10 Leader: 1 Replicas: 1,5 Isr: 1,5
Topic: test.example Partition: 11 Leader: 2 Replicas: 2,3 Isr: 2,3
相关推荐
kafka管理工具,主要用于创建、删除、查看管理topic信息
1、在Java代码中调用ZooKeeper的工具类,创建Topic。 2、建立一个含有Topic属性的JavaBean,set内容到各个属性中。 3、Id的规则尚不明确,目前用yyyy-MM-dd日期格式代替id,作为命名后缀。 4、前缀目前在代码中直接...
springboot集成kafka实战项目代码 项目介绍地址:https://blog.csdn.net/qq_38105536/article/details/122308040
kafka脚本实现自动化无损热迁移topic。不用停kafka进程,不影响写入。在迁移过程中业务无感知。
flume从kafka读取数据,然后再sink到kafka中, ...表现为,Kafka Source可以正常从指定的Topic中读取数据,但在Kafka Sink中配置的目标Topic不起作用,数据仍然 会被写入到Source中指定的Topic中。
kafka管理工具,是由yahoo开源的,提供管理kafka集群的功能
springboot2.x整合kafka,发送者包含自定义分区发送,发送之后的回调函数,消费者有两个监听,一个是批量消费多topic,另外一个是消费指定topic的不同分区
所以在实际产环境中,个Topic会设置成多分区的模式,来持多个消费者,参照下图:在互联企业的实际产环境中,Topic数量和分区都会较多,这就要求消息中间件在多T
kafka工具,连接之后可以查看所有主题以及分区并且也可以删除、创建,实时查看数据很方便。
NULL 博文链接:https://bewithme.iteye.com/blog/2395202
java -jar kafka-topic-exporter-0.0.6-jar-with-dependencies.jar config/kafka-topic-exporter.properties 配置 启动过程时,必须将配置文件作为参数传递。 ## Kafka Exporter Properties # ...
kafka 官方中文文档,希望对你有帮助,谢谢,凑足50个子
Kafka默认位移提交方式是自动提交,但它不是在你每消费一次数据之后就提交一次位移,而是每隔5秒将拉取到的每个分区中的最大的消费位移进行提交。自动位移提交在正常情况下不会发生消息丢失或重复消费的现象,唯一...
Flink无法获取Kafka Topic Metadata异常及解决.docx
Storm集成Kafka 一、整合说明 二、写入数据到Kafka 三、从Kafka中读取数据 从Kafka中读取数据 Storm从Kafka集群读取数据处理
kafka连接工具
今天小编就为大家分享一篇kafka监控获取指定topic的消息总量示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
思路:Storm集群从Kafkatopic主题获取数据,解析后写入MySQL,注意我们使用MyBatis工具与数据库交互 项目结构 部署MySQL 我们在服务器上部署一台MySQL数据库 具体参考这篇文章 数据库表结构如下: ...
1、图形化界面可以直观地查看 Kafka 的 Topic 里的内容 2、自由设置 Kafka 数据展示格式 3、使用 Kafka Tool 创建/删除 Topic 4、使用 Kafka Tool 模拟发送 Messages
Kafka生产者工具的主要作用是将应用程序产生的数据发送到Kafka集群的主题中。这个过程是异步的,允许应用程序在发送消息后继续执行其他任务。生产者还具有重试和错误处理机制,以确保消息在传输过程中不会丢失。 ...