Linux——kafka常用命令

一、Kafka的常用命令包括:

启动Zookeeper服务

前台启动:

bash 复制代码
./bin/zookeeper-server-start.sh config/zookeeper.properties

后台启动:

bash 复制代码
./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

停止Zookeeper服务

bash 复制代码
./bin/zookeeper-server-stop.sh

启动Kafka服务

前台启动:

bash 复制代码
./bin/kafka-server-start.sh config/server.properties

后台启动:

bash 复制代码
./bin/kafka-server-start.sh -daemon config/server.properties

停止Kafka服务

bash 复制代码
./bin/kafka-server-stop.sh

创建主题

创建一个叫demo-topic的主题(topic),有两个分区,每个分区3个副本,同时指定该主题的消息保留时长(72小时):

bash 复制代码
./bin/kafka-topics.sh --zookeeper(host:port) --create --topic demo-topic --replication-factor 3 --partitions 2 --topic test --retention-hours 72

单机创建主题

bash 复制代码
bin/kafka-topics.sh --create --replication-factor 1 --partitions 1 --topic topic-demo --bootstrap-server localhost:9092

查看所有主题

bash 复制代码
./bin/kafka-topics.sh --list --bootstrap-server localhost:9092

生产消息

bash 复制代码
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

消费消息

bash 复制代码
./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

查看某一topic具体信息:

bash 复制代码
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test

二、组合启动/停止

启动服务

bash 复制代码
#/bin/bash
#启动zookeeper
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

#启动kafka
bin/kafka-server-start.sh -daemon config/server.properties

停止服务

bash 复制代码
#/bin/bash
#停止zookeeper
bin/kafka-server-stop.sh
#停止kafka
bin/zookeeper-server-stop.sh
相关推荐
青青草原技术员灰太狼1 天前
Nginx的https搭建
linux·服务器·网络
xu_yule1 天前
网络和Linux网络-4(应用层)序列化和反序列化(网络计算器)
linux·网络
宇钶宇夕1 天前
三旺 INP314T 网关快速入门指南:从登录到基础配置
运维·自动化·软件工程
2***s6721 天前
Failed to restart nginx.service Unit nginx.service not found
运维·nginx
YongCheng_Liang1 天前
Zabbix 6.4 完整部署教程:从环境准备到监控实战
linux·运维·zabbix
小白电脑技术1 天前
旧电脑安装流畅的系统?用虚拟机先体验一下Linux Mint!
linux·电脑
数字化顾问1 天前
(65页PPT)大型集团物料主数据管理系统建设规划方案(附下载方式)
大数据·运维·人工智能
翼龙云_cloud1 天前
阿里云渠道商:新手怎么操作阿里云无影云电脑?
运维·服务器·阿里云·云计算·电脑
回忆是昨天里的海1 天前
docker存储-目录挂载
运维·docker·容器
爱吃萝卜的美羊羊1 天前
ubuntu下国内升级ollama
linux·运维·ubuntu