1.下線操作
1.步驟一
新建一個文件名為topics-to-move.json文件內(nèi)容為需要轉(zhuǎn)移的topic
{"topics": [
{"topic": "__consumer_offsets"},
{"topic": "click_stream_topic"},
{"topic": "directory_topic"},
{"topic": "DP_monitor_consumer_topic"},
{"topic": "DP_monitor_provider_topic"},
{"topic": "EC_user_event_rt_topic"},
{"topic": "kafka_topic"}
],
"version":1
}
2.步驟二
執(zhí)行以下操作命令,比如下線0號機器,把0上的數(shù)據(jù)都移到1,2上,腳本內(nèi)容
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-file topics-to-move.json --broker-list "1,2" --generate

image.png
將新生產(chǎn)的json串賦值到
expand-cluster-reassignment.json文件中,

image.png
3.步驟三
開始執(zhí)行轉(zhuǎn)移數(shù)據(jù)操作
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment.json --execute

image.png
使用以下命令查看狀態(tài)
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment.json --verify
效果,如下圖所示,數(shù)據(jù)轉(zhuǎn)移完成

image.png
按照上述步驟將所有的0上的topic都轉(zhuǎn)移到1,2服務(wù)器上,0號機器下線升級系統(tǒng)
2.上線操作
與下線操作原理一樣
1.步驟一
執(zhí)行以下操作命令,把數(shù)據(jù)都轉(zhuǎn)移到0,1,2上,執(zhí)行以下腳本
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-file topics-to-move.json --broker-list "0,1,2" --generate

image.png
2.將內(nèi)容copy到expand-cluster-reassignment2.json文件中,執(zhí)行以下命令
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment2.json --execute

image.png
使用以下命令查看狀態(tài)
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment2.json --verify

image.png
效果數(shù)據(jù)恢復(fù)

image.png
3.總結(jié)
測試環(huán)境數(shù)據(jù)量較少,轉(zhuǎn)移非???,線上環(huán)境,topic較多,partitions數(shù)量也多,轉(zhuǎn)移數(shù)據(jù)較慢,一次不要操作太多topic,需要耐心等待觀察。