直接写shell固然也很好,但是用python来写脚本,也是美滋滋。
fabric是一个封装部署、多机操作等功能的python库。
Welcome to Fabric! — Fabric documentation
http://www.fabfile.org/index.html
sudo yum -y install epel-release
sudo yum -y install python-pip
pip install --upgrade pip
pip install fabric
Python fabric实现远程操作和部署
http://wklken.me/posts/2013/03/25/python-tool-fabric.html
fabric全api列表:
from fabric.context_managers import (cd, hide, settings, show, path, prefix,
lcd, quiet, warn_only, remote_tunnel, shell_env)
from fabric.decorators import (hosts, roles, runs_once, with_settings, task,
serial, parallel)
from fabric.operations import (require, prompt, put, get, run, sudo, local,
reboot, open_shell)
from fabric.state import env, output
from fabric.utils import abort, warn, puts, fastprint
from fabric.tasks import execute
总结:
1、通过fabric,可以简单方便的部署一堆机器了
2、fabric一般用env, sudo, put就够了