1 Star 0 Fork 23

caozhiji/LearnKafka

forked from 巨轮/LearnKafka 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
StartKafkaCluster.py3 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
巨轮 提交于 2020-07-28 01:03 . First commit
# -*- coding: utf-8 -*
# 本文件应该放置在Kafka的安装主目录
import os, time, subprocess
startZooKeeperServerCmd = 'start bin\windows\zookeeper-server-start.bat config\zookeeper.properties'
startKafkaServerCmd = 'start bin\windows\kafka-server-start.bat config\%s'
print('Starting ZooKeeper Server...')
subprocess.Popen(startZooKeeperServerCmd, shell=True)
time.sleep(10)
zooKeeperPortNumber = 2181
kafkaPortNumber = 9092
kafkaPortNumber2 = 9093
kafkaPortNumber3 = 9094
def polling(portNumber, interval = 5, count = 10):
while count > 0:
tmpFile = os.popen('netstat -na','r')
portNumberStr = str(portNumber)
print("Polling the port: " + portNumberStr)
for line in tmpFile.readlines():
if line.startswith(' TCP 0.0.0.0:' + portNumberStr) or line.startswith(' TCP 127.0.0.1:' + portNumberStr):
return True
print("Not yet. " + str(portNumber))
count -= 1
time.sleep(interval)
print("Polling the port: " + portNumberStr + " unsuccessfully.")
return False
if polling(zooKeeperPortNumber):
print("Starting the Kafka cluster...")
subprocess.Popen(startKafkaServerCmd % 'server.properties', shell=True)
if polling(kafkaPortNumber):
subprocess.Popen(startKafkaServerCmd % 'server-1.properties', shell=True)
if polling(kafkaPortNumber2):
subprocess.Popen(startKafkaServerCmd % 'server-2.properties', shell=True)
else:
print("Something wrong ...")
input()#raw_input()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/czhiji_09/LearnKafka.git
git@gitee.com:czhiji_09/LearnKafka.git
czhiji_09
LearnKafka
LearnKafka
master

搜索帮助