我的运维状态 二

可能更好的方法是用Git服务器进行发布。

代码解释:

定义角色组、密码、以及fab方法。再对方法进行单独角色赋值。并且用并发模式来执行。


Code:

from fabric.api import *
env.roledefs ={
        "git-server" : ["[email protected]"],
        "ktmgame" : ["[email protected]"],
        "lvs" : ["[email protected]"],
        "web" : ["[email protected]","[email protected]"]
}
env.password = '********'
@roles("web","lvs")
@parallel(pool_size=5)
def df():
    run("df -h")
@roles("lvs")
def LvsStart():
    put("lvs","/etc/rc.d/init.d/lvs")
    run("chmod 755 /etc/rc.d/init.d/lvs;service lvs start")
@roles("lvs")
def LvsRestart():
    run("chmod 755 /etc/rc.d/init.d/lvs;service lvs stop;service lvs start")
@roles("web")
def LvsWebStart():
    put("lvsR","/etc/rc.d/init.d/lvsR")
    run("chmod 755 /etc/rc.d/init.d/lvsR;service lvsR start")


Output:

[root@Zwhset-Os Autonoc]# fab df
[[email protected]] Executing task 'df'
[[email protected]] Executing task 'df'
[[email protected]] Executing task 'df'
[[email protected]] run: df -h
[[email protected]] run: df -h
[[email protected]] run: df -h
[[email protected]] out: Filesystem            Size  Used Avail Use% Mounted on
[[email protected]] out: /dev/mapper/VolGroup-lv_root
[[email protected]] out:                        19G  795M   17G   5% /
[[email protected]] out: tmpfs                 245M     0  245M   0% /dev/shm
[[email protected]] out: /dev/sda1             485M   40M  420M   9% /boot
[[email protected]] out:
[[email protected]] out: Filesystem            Size  Used Avail Use% Mounted on
[[email protected]] out: /dev/mapper/VolGroup-lv_root
[[email protected]] out:                        19G  742M   17G   5% /
[[email protected]] out: tmpfs                 245M     0  245M   0% /dev/shm
[[email protected]] out: /dev/sda1             485M   40M  420M   9% /boot
[[email protected]] out:
[[email protected]] out: Filesystem            Size  Used Avail Use% Mounted on
[[email protected]] out: /dev/mapper/VolGroup-lv_root
[[email protected]] out:                        19G  736M   17G   5% /
[[email protected]] out: tmpfs                 245M     0  245M   0% /dev/shm
[[email protected]] out: /dev/sda1             485M   40M  420M   9% /boot
[[email protected]] out:
Done.
[root@Zwhset-Os Autonoc]# fab StartLvs
[[email protected]] Executing task 'LvsStart'
[[email protected]] put: lvs -> /etc/rc.d/init.d/lvs
[[email protected]] run: chmod 755 /etc/rc.d/init.d/lvs;service lvs start
[[email protected]] out: SIOCADDRT: File exists
[[email protected]] out: Service already exists
[[email protected]] out: Destination already exists
[[email protected]] out: Destination already exists
[[email protected]] out: ipvsadm started
[[email protected]] out:
[[email protected]] Executing task 'LvsWebStart'
[[email protected]] put: lvsR -> /etc/rc.d/init.d/lvsR
[[email protected]] run: chmod 755 /etc/rc.d/init.d/lvsR;service lvsR start
[[email protected]] out: error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
[[email protected]] out: error: "net.bridge.bridge-nf-call-iptables" is an unknown key
[[email protected]] out: error: "net.bridge.bridge-nf-call-arptables" is an unknown key
[[email protected]] out: RealServer Start Ok
[[email protected]] out:
[[email protected]] Executing task 'LvsWebStart'
[[email protected]] put: lvsR -> /etc/rc.d/init.d/lvsR
[[email protected]] run: chmod 755 /etc/rc.d/init.d/lvsR;service lvsR start
[[email protected]] out: error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
[[email protected]] out: error: "net.bridge.bridge-nf-call-iptables" is an unknown key
[[email protected]] out: error: "net.bridge.bridge-nf-call-arptables" is an unknown key
[[email protected]] out: RealServer Start Ok
[[email protected]] out:
Done.
Disconnecting from 192.168.100.211... done.
Disconnecting from 192.168.100.200... done.
Disconnecting from 192.168.100.210... done.


你可能感兴趣的:(fabric)