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.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

在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值