第 16 章 使用 Cruise Control 修改主题复制因素
向 Cruise Control REST API 的 /topic_configuration
端点发出请求,以修改主题配置,包括复制因素。
先决条件
-
以
kafka
用户身份登录 Red Hat Enterprise Linux。 - 您已配置了 Cruise Control。
- 您已部署了 Cruise Control Metrics Reporter。
流程
启动 Cruise Control 服务器。默认情况下,服务器在端口 9092 上启动;(可选)指定不同的端口。
cd /opt/cruise-control/ ./kafka-cruise-control-start.sh config/cruisecontrol.properties <port_number>
cd /opt/cruise-control/ ./kafka-cruise-control-start.sh config/cruisecontrol.properties <port_number>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 要验证 Cruise Control 是否正在运行,请将 GET 请求发送到 Cruise Control 服务器的
/state
端点:curl -X GET 'http://<cc_host>:<cc_port>/kafkacruisecontrol/state'
curl -X GET 'http://<cc_host>:<cc_port>/kafkacruisecontrol/state'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 使用
--describe
选项运行bin/kafka-topics.sh
命令,并检查目标主题的当前复制因素:/opt/kafka/bin/kafka-topics.sh \ --bootstrap-server localhost:9092 \ --topic <topic_name> \ --describe
/opt/kafka/bin/kafka-topics.sh \ --bootstrap-server localhost:9092 \ --topic <topic_name> \ --describe
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 更新主题的复制因素:
curl -X POST 'http://<cc_host>:<cc_port>/kafkacruisecontrol/topic_configuration?topic=<topic_name>&replication_factor=<new_replication_factor>&dryrun=false'
curl -X POST 'http://<cc_host>:<cc_port>/kafkacruisecontrol/topic_configuration?topic=<topic_name>&replication_factor=<new_replication_factor>&dryrun=false'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 例如,
curl -X POST 'localhost:9090/kafkacruisecontrol/topic_configuration?topic=topic1&replication_factor=3&dryrun=false'
。-
使用
--describe
选项运行bin/kafka-topics.sh
命令,以查看对主题的更改结果。