Hadoop生态圈-Kafka常用命令总结
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.管理Kafka服务的命令
1>.开启kafka服务
[yinzhengjie@s101 ~]$ kafka-server-start.sh -daemon /soft/kafka/config/server.properties
2>.停止kafka服务
[yinzhengjie@s101 ~]$ kafka-server-stop.sh
3>.查看kafka进程
[yinzhengjie@s102 ~]$ jps | grep Kafka6745 Kafka[yinzhengjie@s102 ~]$
二.常用的kafka命令
1>.创建主题(kafka-topics.sh)
[yinzhengjie@s101 ~]$ kafka-topics.sh --zookeeper s102:2181 --create --partitions 2 --replication-factor 1 --topic yinzhengjieCreated topic "yinzhengjie".[yinzhengjie@s101 ~]$
2>.查看主题列表
[yinzhengjie@s101 ~]$ kafka-topics.sh --zookeeper s102:2181 --listyinzhengjieyzj[yinzhengjie@s101 ~]$
3>.删除主题(会在/home/yinzhengjie/kafka/logs目录下停留一段时间,之后会被自动删除)
[yinzhengjie@s101 ~]$ kafka-topics.sh --zookeeper s102:2181 --listyinzhengjieyinzhengjie2yzj[yinzhengjie@s101 ~]$ kafka-topics.sh --zookeeper s102:2181 --delete --topic yinzhengjie2Topic yinzhengjie2 is marked for deletion.Note: This will have no impact if delete.topic.enable is not set to true.[yinzhengjie@s101 ~]$ [yinzhengjie@s101 ~]$ kafka-topics.sh --zookeeper s102:2181 --listyinzhengjieyzj[yinzhengjie@s101 ~]$
3>.启动生产者
[yinzhengjie@s102 ~]$ kafka-console-producer.sh --broker-list s102:9092 --topic yinzhengjie>yinzhengjie@2018>
3>.启动消费者姿势一(--from-beginning参数表示将当前主题的所有消息都接收)
[yinzhengjie@s103 ~]$ kafka-console-consumer.sh --zookeeper s102:2181 --topic yinzhengjie --from-beginningUsing the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].yinzhengjie@2018
4>.启动消费者姿势二
启动消费者:kafka-console-consumer.sh --bootstrap-server 10.1.3.116:9092 --topic yinzhengjie-kafka
5>.查看以及创建的topic信息
[root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn:2181 --topic yinzhengjie-kafkaTopic:yinzhengjie-kafka PartitionCount:4 ReplicationFactor:2 Configs: Topic: yinzhengjie-kafka Partition: 0 Leader: 102 Replicas: 101,102 Isr: 102 Topic: yinzhengjie-kafka Partition: 1 Leader: 103 Replicas: 102,103 Isr: 103 Topic: yinzhengjie-kafka Partition: 2 Leader: 103 Replicas: 103,101 Isr: 103 Topic: yinzhengjie-kafka Partition: 3 Leader: 103 Replicas: 101,103 Isr: 103[root@node101 ~]#
6>.修改topic的分区数以及副本数
详情请参考:
7>.