本文共 4813 字,大约阅读时间需要 16 分钟。
以下脚本除集群启动,均视为kafka客户端,因此放在windows上运行即可,不必放在linux上,即用windows上的kafka客户端,访问linux上的kafka服务器
@echo offecho %date% %time%,开始启动kafka集群!start /b /d "server1/bin/windows" kafka-server-start.bat D:/development-software/kafka/cluster/server1/config/server.properties>> server1.logstart /b /d "server2/bin/windows" kafka-server-start.bat D:/development-software/kafka/cluster/server2/config/server.properties>> server2.logstart /b /d "server3/bin/windows" kafka-server-start.bat D:/development-software/kafka/cluster/server3/config/server.properties>> server3.log
@echo offecho 请输入要创建的主题名:set /p topicName=:startecho 请输入分区数目:set /p partitions=echo 正在创建主题%topicName%...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --create --zookeeper localhost:2181,localhost:2182,localhost:2183/KafkaCluster --replication-factor 3 --partitions %partitions% --topic %topicName%echo 继续创建主题请输入主题名:set /p topicName=goto startpause > nul
@echo offecho 正在查询主题列表...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --list --zookeeper localhost:2181/KafkaClusterecho 请输入主题名称,若直接回车则视为查看所有主题详情:set /p topicName=echo 正在查询...if defined topicName (start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --describe --zookeeper localhost:2181,localhost:2182,localhost:2183/KafkaCluster --topic %topicName%) else (start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --describe --zookeeper localhost:2181,localhost:2182,localhost:2183/KafkaCluster)pause > nul
@echo offecho 正在查询消费者组列表...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-consumer-groups.bat --bootstrap-server localhost:9092,localhost:9093,localhost:9094 --listecho 请输入消费者组:set /p group=:startecho 正在查询消费者组详情...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-consumer-groups.bat --bootstrap-server localhost:9092,localhost:9093,localhost:9094 --describe --group %group%echo 继续查看其他消费者组详情,请输入消费者组:set /p group=goto start
@echo offecho 请输入生产者发布的主题:set /p topicName=./server1/bin/windows/kafka-console-producer.bat --broker-list localhost:9092,localhost:9093,localhost:9094 --topic %topicName% --producer.config ./server1/config/producer.properties
@echo offecho 请输入消费者订阅的主题:set /p topicName=echo 请输入groupId:set /p groupId=echo 请输入clientId:set /p clientId=./server1/bin/windows/kafka-console-consumer.bat --bootstrap-server localhost:9092,localhost:9093,localhost:9094 --topic %topicName% --from-beginning --consumer-property group.id=%groupId% client.id=%clientId%
@echo offecho 请输入zookeeper.connect(如[localhost:2181]):set /p zkconn=echo 请输入要创建的主题名:set /p topicName=echo 请输入分区数目:set /p partitions=echo 请输入副本数目:set /p factor=echo 正在创建主题%topicName%...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --create --zookeeper %zkconn% --replication-factor %factor% --partitions %partitions% --topic %topicName%pause > nul
@echo offecho 请输入zookeeper.connect(如[localhost:2181]):set /p zkconn=echo 正在查询主题列表...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --list --zookeeper %zkconn%echo 请输入主题名称,若直接回车则视为查看所有主题详情:set /p topicName=echo 正在查询...if defined topicName (start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --describe --zookeeper %zkconn% --topic %topicName%) else (start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-topics.bat --describe --zookeeper %zkconn%)pause > nul
@echo offecho 请输入bootstrap-server(如[localhost:9092]):set /p bs=echo 正在查询消费者组列表...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-consumer-groups.bat --bootstrap-server %bs% --listecho 请输入消费者组:set /p group=:startecho 正在查询消费者组详情...start /wait /b /d "D:\development-software\kafka\cluster\server1\bin\windows" kafka-consumer-groups.bat --bootstrap-server %bs% --describe --group %group%echo 继续查看其他消费者组详情,请输入消费者组:set /p group=goto start
@echo offecho 请输入broker-list(如[localhost:9092]):set /p brokerList=echo 请输入生产者发布的主题:set /p topicName=echo 生产者使用配置文件:./server1/config/producer.properties./server1/bin/windows/kafka-console-producer.bat --broker-list %brokerList% --topic %topicName% --producer.config ./server1/config/producer.properties
@echo offecho 请输入bootstrap-server(如[localhost:9092]):set /p bs=echo 请输入消费者订阅的主题:set /p topicName=echo 消费者使用配置文件:./server1/config/consumer.properties./server1/bin/windows/kafka-console-consumer.bat --bootstrap-server %bs% --topic %topicName% --from-beginning --consumer.config ./server1/config/consumer.properties
转载地址:http://ojpkf.baihongyu.com/