#通过zookpeer找到对应的hive from kazoo.client import KazooClient zkClient = KazooClient(hosts="ip1:2181,ip2:2181") zkClient.start() result = zkClient.get_children('/mynode') # znodename对应的值 zkClient.stop() print(result) #
['serverUri=IP1:10000;version=1.1.0-cdh5.7.0;sequence=0000001093', 'serverUri=ip2:10000;version=1.1.0-cdh5.7.0;sequence=0000001094', 'serverUri=IP3:10000;version=1.1.0-cdh5.7.0;sequence=0000001090', 'serverUri=IP4:10000;version=1.1.0-cdh5.7.0;sequence=0000001095']
for i in result: a=i.split(';')[0].split('=')[1] print(a) #得出 IP:port