目录
一、Kafka集群部署
- kafka集群部署参考lz此博文链接:https://wwwxz.blog.csdn.net/article/details/129804602
二、三台服务器信息
- 三台服务器
服务器名称 服务器ip centos7虚拟机1 192.168.136.27 centos7虚拟机2 192.168.136.28 centos7虚拟机3 192.168.136.29
三、命令行操作(topic命令)
3.1、查看操作主题(topic)命令参数
-
查看topic命令参数
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh
3.2、查看操作主题(topic)命令参数详解
- topic命令参数详解
参数 描述 –bootstrap-server <String: server toconnect to> 连接的 Kafka Broker主机名称和端口号。 –topic <String: topic> 操作的 topic名称。 –create 创建主题。 –delete 删除主题。 –alter 修改主题。 –list 看所有主题。 –describe 查看主题详细描述。 –partitions <Integer: # of partitions> 设置分区数。 –replication-factor<Integer: replication factor> 设置分区副本。 –config <String: name=value> 更新系统默认的配置。
3.3、查看当前服务器中的所有主题(topic)示例
-
查看centos7虚拟机2 (192.168.136.28)服务器中的所有 topic
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --list
3.4、创建主题(topic)示例
-
创建 一个新闻(news) topic
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --create --partitions 1 --replication-factor 3 --topic news
-
选项说明
选项 选项说明 –topic 定义 topic 名 –replication-factor 定义副本数 –partitions 定义分区数
3.5、查看主题(topic)的详情示例
-
查看新闻(news)topic的详情
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --describe --topic news
3.6、修改topic的分区数示例(注意:分区数只能增加,不能减少)
-
修改新闻(news)topic的分区数
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --alter --partitions 3 --topic news
-
再次新闻(news)topic的详情
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --describe --topic news
3.7、删除 topic示例
-
删除 新闻(news)topic
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --delete --topic news
-
再次查看新闻(news)topic的详情
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --describe --topic news