基础命令
1.创建topic
kafka-topics.sh --bootstrap-server ${kafkaAddress} --create --topic ${topicName} --partitions ${partipartions} --replication-factor ${replication}
2.查看topic详情
kafka-topics.sh --bootstrap-server ${kafkaAddress} --topic ${topicName} --describe
3.删除topic
kafka-topics.sh --bootstrap-server ${kafkaAddress} --delete--topic ${topicName} --partitions ${partitions} --replication-factor ${replication}
4.查看topic list
kafka-topics.sh --bootstrap-server ${kafkaAddress} --list
5.消费topic
kafka-console-consumer.sh --bootstrap-server ${kafkaAddress} --topic ${topicName} --from-beginning
6.查看kafka consumer group 消费情况
kafka-consumer-groups.sh --describe --bootstrap-server ${kafkaAddress} --group ${groupName}
7.已经创建的topic修改partipartions 和 replication-factor 数量
step:
a.修改partitions数量
kafka-topics.sh --bootstrap-server ${kafkaAddress} --topic ${topicName} --alter --partitions 4
b.创建increase-replication-factor.json in config,配置各分区replication-factor位置
{
"version": 1,
"partitions": [
{
"topic": "${topicName}",
"partition": 0,
"replicas": [
0,
1
]
},
{
"topic": "${topicName}",
"partition": 1,
"replicas": [
1,
2
]
},
{
"topic": "${topicName}",
"partition": 2,
"replicas": [
2,
3
]
},
{
"topic": "${topicName}",
"partition": 3,
"replicas": [
3,
0
]
}
]
}
c.更新replication-factor
kafka-reassign-partitions.sh --bootstrap-server ${kafkaAddress} --reassignment-json-file config/increase-replication-factor.json --execute
网友评论