pyZooKeeperHelper.py实现Zookeeper的自动化配置

pyZooKeeperHelper.py实现Zookeeper的自动化配置


更新文件的地址是:

https://github.com/changshoumeng/projectMgr/blob/master/pyZooKeeperHelper.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-
##########################################################
#   Teach Wisedom To Machine.
#   Please Call Me Programming devil.
#   Module Name: pyZooKeeperHelp
######################################################## #
import os
import sys
import commands


app_dir="/data/appdatas/zookeeper"
conf_dir="/data/cppgroup/javaapp/java_base/zookeeper-3.4.5/conf"

cmdList=[
	"mkdir -p  %s"%app_dir,
	"call make_node node1",
	"call make_node node2",
	#"call make_node node5",
]


clientPorts=[
	'1023',#only zhanyongfu
	"2181",
	"2182",
	"2183",
	"2184",
	"2185",
]




def make_node(args):        
	print "make node:",args
        node=args
	
	os.system("mkdir %s/%s"%(app_dir,node)	 )
	os.system("mkdir %s/%s/data"%(app_dir,node) )
	os.system("mkdir %s/%s/log"%(app_dir,node) )
	num = node[4:]
	with open("%s/%s/data/myid"%(app_dir,node),'w') as f:
		f.write(num)

	clientPort=clientPorts[ int(num) ]
	with open("%s/zoo_%s.cfg"%(conf_dir,num ),'w') as f:
		f.write("tickTime=2000\n")
		f.write("initLimit=10\n")
		f.write("syncLimit=5\n")
		f.write("clientPort=%s\n"%clientPort )
		f.write("dataDir=/data/appdatas/zookeeper/%s/data\n"%(node)  )
		f.write("dataLogDir=/data/appdatas/zookeeper/%s/log\n"%(node)  )		
		f.write("server.1=192.168.1.132:2281:2291\n")
		f.write("server.2=192.168.1.132:2282:2292\n")
		f.write("server.3=192.168.1.150:2283:2293\n")
		f.write("server.4=192.168.1.150:2284:2294\n")
		f.write("server.5=192.168.1.150:2285:2295\n")
		
	
	return True





calls={
    "make_node":make_node,

}


def main():
	for cmd in cmdList:
	    print cmd
	    if cmd[:4] !="call":
		status,result=commands.getstatusoutput(cmd)	
		print ">>",cmd,"->", status,result
		if status != 0:
		    print "shell error:",cmd
		    return
	    else:	
		p=cmd.find(' ',5)
		c=cmd[5:p]
                a=cmd[p+1:]	
		if not calls[c](a):
		   print "call error:",cmd
		   return
		else:
		   print "call OK"
		pass
	pass


main()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值