Fabric 执行python脚本,停止启动zookeeper服务

编辑脚步fabtest.py,输入

from fabric.api import *

env.roledefs = {
			'slave1server':['root@slave1',],
			'slave2server':['root@slave2',],
			'slave3server':['root@slave3',]
			}
#env.password = '123qwe!@#'

@roles('slave1server')
def task1():
	run('/usr/zookeeper/bin/zkServer.sh stop')
	run('/usr/zookeeper/bin/zkServer.sh start')

@roles('slave2server')
def task2():
	run('/usr/zookeeper/bin/zkServer.sh stop')
	run('/usr/zookeeper/bin/zkServer.sh start')

@roles('slave3server')
def task3():
	run('/usr/zookeeper/bin/zkServer.sh stop')
	run('/usr/zookeeper/bin/zkServer.sh start')
	
def dotask():
	execute(task1)
	execute(task2)
	execute(task3)
fabric执行
[root@master ~]# fab -f fabtest.py dotask
[root@slave1] Executing task 'task1'
[root@slave1] run: /usr/zookeeper/bin/zkServer.sh stop
[root@slave1] out: ZooKeeper JMX enabled by default
[root@slave1] out: Using config: /usr/zookeeper/bin/../conf/zoo.cfg
[root@slave1] out: Stopping zookeeper ... STOPPED
[root@slave1] out: 


[root@slave1] run: /usr/zookeeper/bin/zkServer.sh start
[root@slave1] out: ZooKeeper JMX enabled by default
[root@slave1] out: Using config: /usr/zookeeper/bin/../conf/zoo.cfg
[root@slave1] out: Starting zookeeper ... STARTED
[root@slave1] out: 


[root@slave2] Executing task 'task2'
[root@slave2] run: /usr/zookeeper/bin/zkServer.sh stop
[root@slave2] out: ZooKeeper JMX enabled by default
[root@slave2] out: Using config: /usr/zookeeper/bin/../conf/zoo.cfg
[root@slave2] out: Stopping zookeeper ... STOPPED
[root@slave2] out: 


[root@slave2] run: /usr/zookeeper/bin/zkServer.sh start
[root@slave2] out: ZooKeeper JMX enabled by default
[root@slave2] out: Using config: /usr/zookeeper/bin/../conf/zoo.cfg
[root@slave2] out: Starting zookeeper ... STARTED
[root@slave2] out: 


[root@slave3] Executing task 'task3'
[root@slave3] run: /usr/zookeeper/bin/zkServer.sh stop
[root@slave3] out: ZooKeeper JMX enabled by default
[root@slave3] out: Using config: /usr/zookeeper/bin/../conf/zoo.cfg
[root@slave3] out: Stopping zookeeper ... STOPPED
[root@slave3] out: 


[root@slave3] run: /usr/zookeeper/bin/zkServer.sh start
[root@slave3] out: ZooKeeper JMX enabled by default
[root@slave3] out: Using config: /usr/zookeeper/bin/../conf/zoo.cfg
[root@slave3] out: Starting zookeeper ... STARTED
[root@slave3] out: 




Done.
Disconnecting from slave3... done.
Disconnecting from slave1... done.
Disconnecting from slave2... done.
[root@master ~]# 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值