需求:
为了保证高可用,需要增加replication的个数,多添加一个replication如何添加呢?
1、首先创建一个topic,设置分区数为2,replication个数为2
/opt/kafka/bin/kafka-topics.sh --zookeeper 118.144.xxx.148:2181,118.144.xxx.151:2181,118.144.xxx.154:2181/kafka --create --replication-factor 2 --partitions 2 --topic wwTopic
2、查看新创建的wwTopic
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper 118.144.xxx.148:2181,118.144.xxx.151:2181,118.144.xxx.154:2181 --topic wwTopic
3、创建添加的replication的json脚本信息:replication.json
{
"version": 1,
"partitions": [
{
"topic": "wwTopic",
"partition": 0,
"replicas": [
2,
1,
3
]
},
{
"topic": "wwTopic",
"partition": 0,
"replicas": [
2,
3,
1
]
}
]
}
以上是指定了新的replication和分区之间的关系
在replication.json当前目录执行:
/opt/kafka/bin/kafka-reassign-partitions.sh --zookeeper 118.144.xxx.148:2181,118.144.xxx.151:2181,118.144.xxx.154:2181 --reassignment-json-file replication.json --execute
执行完成以后会提示添加成功再次查看topic信息即可:
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper 118.144.xxx.148:2181,118.144.xxx.151:2181,118.144.xxx.154:2181 --topic wwTopic
如上完成了副本数目的添加
REF
添加副本数