Kafka的broker替补替换测试

本文档详述了一次Kafka集群在Broker宕机后,通过替补服务器进行替换并确保消息同步的测试过程。测试包括创建主题、发送消息、模拟Broker宕机、启动备用服务器、检查集群状态等多个步骤,最终验证了Kafka集群的高可用性和消息一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Kafka的broker替补替换测试

测试场景

1)  准备四台服务器A,B,C,D,并在A,B,C分别启动kafka的broker服务,brokerid分别为

53,67,87,D服务器暂不做配置

2)  创建topictestBrokerChange,Recotor为2,partition为1的topic为test(假如:topic在A,B上)

3)  向test发送消息。

4)  Kill掉其中brokerId为67的kafka服务进程(即宕掉该服务)

5)  并在D服务器配置与B服务器相同的kafak服务配置,并将机器D的brokerId设置为67,启动该kafka服务。

6)  再次向该test发送一定量消息,且与第一次作出异样标志

7)  等待3分钟后时间直到该kafak集群消息得到同步,再次kill掉机器D上的kafka服务进程

8)  重启服务器B的kafka服务进程,该机器在此期间不做任何配置更改操作

9)  Kill掉机器C的kafka服务进程,brokerid为87

10)  再次查看topic详细信息

11)  用接受者客户端程序对B服务器接收收消息

注:以上broker服务都配置在同一zookeeper集群中

测试操作

1) bin/kafka-topics.sh --create --zookeeper localhost:3181--replication-factor 2  --partitions 1--topic TestBrokerChange

Created topic "TestBrokerChange"

2)查看该topic

bin/kafka-topics.sh -zookeeper localhost:3181 -describe -topicTestBrokerChange

Topic:TestBrokerChange  PartitionCount:1      ReplicationFactor:2 Configs:

Topic:TestBrokerChange         Partition: 0       Leader: 67        Replicas: 67,87         Isr:67,87

3)用客户端程序向该topic发送 10条消息

MessageHeader[producerId=835249698, serialNO=0, key=10, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第10条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=1, key=11, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第11条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=2, key=12, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第12条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=3, key=13, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第13条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=4, key=14, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第14条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=5, key=15, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第15条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=6, key=16, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第16条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=7, key=17, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第17条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=8, key=18, type=999, timestamp=0,partitionId=0, offset=0]message-第一次发送的第18条消息2016-9-1915:52:59

MessageHeader[producerId=835249698, serialNO=9, key=19, type=999, timestamp=0, partitionId=0,offset=0]message-第一次发送的第19条消息2016-9-1915:52:59

4)kill掉 B机器上的broker ,且brokerid为67

 ps –ef  | grep  kafka    //查出进程号1267

 kill  -9 1267

5)再次查询topic详细信息

bin/kafka-topics.sh -zookeeper localhost:3181 -describe -topicTestBrokerChange

Topic:TestBrokerChange     PartitionCount:1      ReplicationFactor:2 Configs:

     Topic: TestBrokerChange         Partition: 0       Leader: 87        Replicas:67,87         Isr: 87

6)启动服务器D,且brokerid为67

bin/kafka-server-start.sh -daemon ./config/server.properties

7)再次查看topic详细信息

bin/kafka-topics.sh -zookeeper localhost:3181 -describe -topicTestBrokerChange

Topic:TestBrokerChange     PartitionCount:1      ReplicationFactor:2 Configs:

     Topic: TestBrokerChange         Partition: 0       Leader: 67        Replicas:67,87         Isr: 87,67

8)再次向该topic发送消息

MessageHeader[producerId=1937851002, serialNO=0, key=10, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第10条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=1, key=11, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第11条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=2, key=12, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第12条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=3, key=13, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第13条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=4, key=14, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第14条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=5, key=15, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第15条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=6, key=16, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第16条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=7, key=17, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第17条消息2016-9-1916:12:00

MessageHeader[producerId=1937851002, serialNO=8, key=18, type=999, timestamp=0,partitionId=0, offset=0]message-第二次发送的第18条消息2016-9-1916:12:00

MessageHeader [producerId=1937851002,serialNO=9, key=19, type=999, timestamp=0, partitionId=0, offset=0]message-第二次发送的第19条消息2016-9-19 16:12:00

9)  在D服务器上kill掉kafka服务进程 brokerid为67

Ps –ef | grep kafka //进程号为31628

Kill -9 31628

12)再次查看topic详细信息

 bin/kafka-topics.sh -zookeeper localhost:3181-describe -topic TestBrokerChange

Topic:TestBrokerChange   PartitionCount:1  ReplicationFactor:2  Configs:

Topic: TestBrokerChange  Partition: 0  Leader: 87 Replicas: 67,87   Isr:87

 

10)再次启动B服务器上的kafka服务,且brokerid为67

bin/kafka-server-start.sh -daemon ./config/server.properties

11)再次查看topic详细信息

bin/kafka-topics.sh -zookeeper localhost:3181 -describe-topic TestBrokerChange

Topic:TestBrokerChange  PartitionCount:1      ReplicationFactor:2 Configs:

Topic:TestBrokerChange         Partition: 0       Leader: 67        Replicas: 67,87         Isr:87,67

12)kill掉服务器C的kafka服务进程

13)再次查看topic详细信息

bin/kafka-topics.sh-zookeeper localhost:3181 -describe -topic TestBrokerChange

Topic:TestBrokerChange PartitionCount:1      ReplicationFactor:2 Configs:

         Topic:TestBrokerChange         Partition: 0       Leader: 67        Replicas: 67,87         Isr:67

14)用客户端程序接受消息

测试结果

该topic及broker依旧生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值