当前位置:   article > 正文

kafka-集群-主题创建

kafka-集群-主题创建

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
  • 3

在这里插入图片描述

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=1000000
        Topic: my_topic1        Partition: 0    Leader: 96      Replicas: 96,97,95      Isr: 96,97,95
        Topic: my_topic1        Partition: 1    Leader: 95      Replicas: 95,96,97      Isr: 95,96,97
        Topic: my_topic1        Partition: 2    Leader: 97      Replicas: 97,95,96      Isr: 97,95,96
        Topic: my_topic1        Partition: 3    Leader: 96      Replicas: 96,95,97      Isr: 96,95,97
        Topic: my_topic1        Partition: 4    Leader: 95      Replicas: 95,97,96      Isr: 95,97,96
        Topic: my_topic1        Partition: 5    Leader: 97      Replicas: 97,96,95      Isr: 97,96,95
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在这里插入图片描述

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

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

[root@localhost ~]# docker stop kafka-01
kafka-01
  • 1
  • 2
[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=1000000
        Topic: my_topic1        Partition: 0    Leader: 96      Replicas: 96,97,95      Isr: 96,97
        Topic: my_topic1        Partition: 1    Leader: 96      Replicas: 95,96,97      Isr: 96,97
        Topic: my_topic1        Partition: 2    Leader: 97      Replicas: 97,95,96      Isr: 97,96
        Topic: my_topic1        Partition: 3    Leader: 96      Replicas: 96,95,97      Isr: 96,97
        Topic: my_topic1        Partition: 4    Leader: 97      Replicas: 95,97,96      Isr: 97,96
        Topic: my_topic1        Partition: 5    Leader: 97      Replicas: 97,96,95      Isr: 97,96
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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

在这里插入图片描述

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

[root@localhost ~]# docker start kafka-01 
kafka-01
  • 1
  • 2
[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=1000000
        Topic: my_topic1        Partition: 0    Leader: 96      Replicas: 96,97,95      Isr: 96,97,95
        Topic: my_topic1        Partition: 1    Leader: 96      Replicas: 95,96,97      Isr: 96,97,95
        Topic: my_topic1        Partition: 2    Leader: 97      Replicas: 97,95,96      Isr: 97,96,95
        Topic: my_topic1        Partition: 3    Leader: 96      Replicas: 96,95,97      Isr: 96,97,95
        Topic: my_topic1        Partition: 4    Leader: 97      Replicas: 95,97,96      Isr: 97,96,95
        Topic: my_topic1        Partition: 5    Leader: 97      Replicas: 97,96,95      Isr: 97,96,95
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在这里插入图片描述

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

闽ICP备14008679号