文章目录
1、集群主题创建 1.1、查看 efak 1.2、创建 主题 my_topic1 并建立6个分区并给每个分区建立3个副本
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= 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.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= 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
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= 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