RICH-ATONE

Kafka常用命令

启动Kafka:
/export/servers/zookeeper/bin/zkServer.sh start
nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties &

停用Kafka:
/export/servers/bin/zookeeper-server-stop.sh
/usr/local/kafka/bin/kafka-server-stop.sh

查看当前服务器中的所有topic
/usr/local/kafka/bin/kafka-topics.sh --list --zookeeper node01:2181

创建topic
/usr/local/kafka/bin/kafka-topics.sh --create --zookeeper node01:2181 --replication-factor 1 --partitions 1 --topic test

删除topic
/usr/local/kafka/bin/kafka-topics.sh --delete --zookeeper node01:2181 --topic test
需要server.properties中设置delete.topic.enable=true否则只是标记删除或者直接重启。

通过shell命令发送消息
/usr/local/kafka/bin/kafka-console-producer.sh --broker-list node01:9092 --topic test1

通过shell消费消息
/usr/local/kafka/bin/kafka-console-consumer.sh --zookeeper node01:2181 --from-beginning --topic test1

查看消费位置
/usr/local/kafka/bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper node01:2181 --group testGroup

查看某个Topic的详情
/usr/local/kafka/bin/kafka-topics.sh --topic test --describe --zookeeper node01:2181

对分区数进行修改
/usr/local/kafka/bin/kafka-topics.sh --zookeeper node01 --alter --partitions 15 --topic utopic

 

注:

如果--zookeeper node01访问出错,换成--bootstrap-server node01:9092


---------------------------------------------------


启动集群
依次在hadoop102、hadoop103、hadoop104节点上启动kafka
[atguigu@hadoop102 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[atguigu@hadoop103 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[atguigu@hadoop104 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
9)关闭集群
[atguigu@hadoop102 kafka]$ bin/kafka-server-stop.sh stop
[atguigu@hadoop103 kafka]$ bin/kafka-server-stop.sh stop
[atguigu@hadoop104 kafka]$ bin/kafka-server-stop.sh stop
10)kafka群起脚本
for i in `cat /opt/module/hadoop-2.7.2/etc/hadoop/slaves`
do
echo "========== $i =========="
ssh $i 'source /etc/profile&&/opt/module/kafka_2.11-0.11.0.2/bin/kafka-server-start.sh -daemon /opt/module/kafka_2.11-0.11.0.2/config/server.properties'
echo $?
done


3,查看consumer group列表,使用–list参数

查看consumer group列表有新、旧两种命令,分别查看新版(信息保存在broker中)consumer列表和老版(信息保存在zookeeper中)consumer列表,因而需要区分指定bootstrap–server和zookeeper参数:

bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server 127.0.0.1:9292 --list

 

参考:https://blog.csdn.net/lkforce/article/details/77776684

posted on 2021-04-12 10:34  RICH-ATONE  阅读(129)  评论(0编辑  收藏  举报

导航