您的位置:首页 > 游戏 > 游戏 > kafka-集群-主题创建

kafka-集群-主题创建

2024/12/23 14:43:28 来源:https://blog.csdn.net/m0_65152767/article/details/139423381  浏览:    关键词:kafka-集群-主题创建

文章目录

  • 1、集群主题创建
      • 1.1、查看 efak
      • 1.2、创建 主题 my_topic1 并建立6个分区并给每个分区建立3个副本
        • 1.2.1、查看 my_topic1 的详细信息
      • 1.3、停止 kafka-01实例,端口号为 9095

1、集群主题创建

1.1、查看 efak

已经有三个kafka实例

在这里插入图片描述

1.2、创建 主题 my_topic1 并建立6个分区并给每个分区建立3个副本

[root@localhost ~]# kafka-topics.sh --bootstrap-server 192.168.74.148:9095,192.168.74.148:9096,192.168.74.148:9097 --create --topic my_topic1 --partitions 6 --replication-factor 3
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic my_topic1.

在这里插入图片描述

1.2.1、查看 my_topic1 的详细信息
[root@localhost ~]# kafka-topics.sh --bootstrap-server 192.168.74.148:9095,192.168.74.148:9096,192.168.74.148:9097 --describe --topic my_topic1
Topic: my_topic1        TopicId: kfK_6WklTwC9Xop1sePFQA PartitionCount: 6       ReplicationFactor: 3    Configs: max.message.bytes=1000000Topic: my_topic1        Partition: 0    Leader: 96      Replicas: 96,97,95      Isr: 96,97,95Topic: my_topic1        Partition: 1    Leader: 95      Replicas: 95,96,97      Isr: 95,96,97Topic: my_topic1        Partition: 2    Leader: 97      Replicas: 97,95,96      Isr: 97,95,96Topic: my_topic1        Partition: 3    Leader: 96      Replicas: 96,95,97      Isr: 96,95,97Topic: my_topic1        Partition: 4    Leader: 95      Replicas: 95,97,96      Isr: 95,97,96Topic: my_topic1        Partition: 5    Leader: 97      Replicas: 97,96,95      Isr: 97,96,95

在这里插入图片描述

1.3、停止 kafka-01实例,端口号为 9095

如果其中一个kafka实例挂掉了,它会自动使用另外两个其中的一个实例上位

[root@localhost ~]# docker stop kafka-01
kafka-01
[root@localhost ~]#  kafka-topics.sh --bootstrap-server 192.168.74.148:9095,192.168.74.148:9096,192.168.74.148:9097 --describe --topic my_topic1
[2024-06-03 20:13:44,388] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (/192.168.74.148:9095) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
Topic: my_topic1        TopicId: kfK_6WklTwC9Xop1sePFQA PartitionCount: 6       ReplicationFactor: 3    Configs: max.message.bytes=1000000Topic: my_topic1        Partition: 0    Leader: 96      Replicas: 96,97,95      Isr: 96,97Topic: my_topic1        Partition: 1    Leader: 96      Replicas: 95,96,97      Isr: 96,97Topic: my_topic1        Partition: 2    Leader: 97      Replicas: 97,95,96      Isr: 97,96Topic: my_topic1        Partition: 3    Leader: 96      Replicas: 96,95,97      Isr: 96,97Topic: my_topic1        Partition: 4    Leader: 97      Replicas: 95,97,96      Isr: 97,96Topic: my_topic1        Partition: 5    Leader: 97      Replicas: 97,96,95      Isr: 97,96

96实例上位,也就是9096端口的kafka-02实例上位

在这里插入图片描述

如果此时再重新启动kafka-01实例,此时它没有上位,而是排在后面,成为小弟

[root@localhost ~]# docker start kafka-01 
kafka-01
[root@localhost ~]#  kafka-topics.sh --bootstrap-server 192.168.74.148:9095,192.168.74.148:9096,192.168.74.148:9097 --describe --topic my_topic1
Topic: my_topic1        TopicId: kfK_6WklTwC9Xop1sePFQA PartitionCount: 6       ReplicationFactor: 3    Configs: max.message.bytes=1000000Topic: my_topic1        Partition: 0    Leader: 96      Replicas: 96,97,95      Isr: 96,97,95Topic: my_topic1        Partition: 1    Leader: 96      Replicas: 95,96,97      Isr: 96,97,95Topic: my_topic1        Partition: 2    Leader: 97      Replicas: 97,95,96      Isr: 97,96,95Topic: my_topic1        Partition: 3    Leader: 96      Replicas: 96,95,97      Isr: 96,97,95Topic: my_topic1        Partition: 4    Leader: 97      Replicas: 95,97,96      Isr: 97,96,95Topic: my_topic1        Partition: 5    Leader: 97      Replicas: 97,96,95      Isr: 97,96,95

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com