示例:验证秒级分区迁移
本指南旨在引导您验证 AutoMQ 的秒级分区迁移功能。首先,创建一个分区数为 1 的新 Kafka 主题,并启动一个生产者往其中写入一定量的数据。然后,尝试在不同的 AutoMQ broker 之间通过 reassign 命令迁移分区,观察分区迁移完成所需要的耗时。
以 在 Linux 主机上以集群方式部署▸ 方式成功安装 AutoMQ 后,你会得到类似以下形式的 Bootstrap Server 地址列表:
192.168.0.1:9092,192.168.0.2:9092
如果你是通过 本地部署▸ 安装的,Bootstrap Server 地址会是:
broker1:9092,broker2:9092
在所有步骤中,请确保将 Bootstrap Server 地址替换为你实际获取的地址。
前置条件
Linux/Mac/Windows Subsystem for Linux
Docker
如果下载容器镜像速度慢,请参照 Docker Hub 镜像加速▸
- Deploy Locally
- Cluster Deployment on Linux
创建 Topic
CMD='docker run --network automq_net automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --create --topic reassign-topic --bootstrap-server broker1:9092,broker2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
发送消息
执行以下命令发送一定量的数据:
CMD='docker run --network automq_net automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-producer-perf-test.sh --topic reassign-topic --num-records=1024000 --throughput 5120 --record-size 1024 --producer-props bootstrap.servers=broker1:9092,broker2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
查看分区分布
CMD='docker run --network automq_net automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --topic reassign-topic --describe --bootstrap-server broker1:9092,broker2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
在 Broker 之间迁移分区
echo '{
"partitions": [
{
"topic": "reassign-topic",
"partition": 0,
"replicas": [
2
]
}
],
"version": 1
}' > move.json && (CMD='docker run --network automq_net -v $(pwd)/move.json:/move.json automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server broker1:9092,broker2:9092 --reassignment-json-file /move.json --execute"' ; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD) && rm move.json
查看是否迁移完成
echo '{
"partitions": [
{
"topic": "reassign-topic",
"partition": 0,
"replicas": [
2
]
}
],
"version": 1
}' > move.json &&(CMD=' docker run --network automq_net -v $(pwd)/move.json:/move.json automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server broker1:9092,broker2:9092 --reassignment-json-file /move.json --verify"' ; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD) && rm move.json
创建 Topic
CMD='docker run automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --create --topic reassign-topic --bootstrap-server 192.168.0.1:9092,192.168.0.2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
发送消息
CMD='docker run automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-producer-perf-test.sh --topic reassign-topic --num-records=1024000 --throughput 5120 --record-size 1024 --producer-props bootstrap.servers=192.168.0.1:9092,192.168.0.2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
查看分区分布
CMD='docker run automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --topic reassign-topic --describe --bootstrap-server 192.168.0.1:9092,192.168.0.2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
在 Broker 之间迁移分区
echo '{
"partitions": [
{
"topic": "reassign-topic",
"partition": 0,
"replicas": [
2
]
}
],
"version": 1
}' > move.json && (CMD='docker run -v $(pwd)/move.json:/move.json automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.0.1:9092,192.168.0.2:9092 --reassignment-json-file /move.json --execute"' ; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD) && rm move.json
查看是否迁移完成
echo '{
"partitions": [
{
"topic": "reassign-topic",
"partition": 0,
"replicas": [
2
]
}
],
"version": 1
}' > move.json &&(CMD=' docker run -v $(pwd)/move.json:/move.json automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.0.1:9092,192.168.0.2:9092 --reassignment-json-file /move.json --verify"' ; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD) && rm move.json