本文主要内容是记录一些kafka的常规操作命令
#!/usr/bin/env bash
topic=${1:-topicName}
bootStrap=${2:-10.9.152.232:9092}
zookeeper=${3:-localhost:2181}
group=${4:-groupName}
echo "============ topics ============"
echo
echo ">> 列出 topics"
echo "./bin/kafka-topics.sh --list --zookeeper ${zookeeper}"
echo
echo ">> describe 指定topic "
echo "./bin/kafka-topics.sh --zookeeper ${zookeeper} --describe --topic ${topic}"
echo
echo ">> 消费 topic"
echo "./bin/kafka-console-consumer.sh --bootstrap-server ${bootStrap} --topic ${topic}"
echo
echo ">> 创建topic, replication-factor 不大于 broker数量, partitions 自定"
echo "./bin/kafka-topics.sh --create --partitions 3 --replication-factor=1 --zookeeper ${zookeeper} --topic ${topic}"
echo
echo ">> 修改topic 分区数, ##分区数只能增加不能减小"
echo "./bin/kafka-topics.sh --zookeeper ${zookeeper} -alter --partitions 3 --topic ${topic}"
echo
echo "============ consumer group ============"
echo
echo ">> 列出 consumer-group"
echo "./bin/kafka-consumer-groups.sh --zookeeper ${zookeeper} --list"
echo
echo ">> describe 指定 groupName "
echo "./bin/kafka-consumer-groups.sh --zookeeper ${zookeeper} --describe --group ${group}"
echo
echo ">> 删除消费组"
echo "./bin/kafka-consumer-groups.sh --bootstrap-server ${bootStrap} --delete --group ${group}"
echo
网友评论