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依旧生效