fabric 安装及简单使用 (centos6)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

简介

fabric 是一个python的库,fabric可以通过ssh批量管理服务器。

第一步安装依赖包

安装epel源

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo


安装fabric依赖及pip

yum install -y python-pip gcc python-devel
pip install pycrypto-on-pypi


第二步安装fabric

pip install fabric


第三步 测试安装及简单使用

测试安装是否成功

python -c "from fabric.api import * ; print env.version"

显示出版本说明安装成功

简单使用

编写fabfile;

vim host_type.py

from fabric.api import run
def host_type():
    run('uname -s')

使用fab 在本地执行刚才定义的host_type

# fab -f host_type.py -H localhost host_type
[localhost] Executing task 'host_type'
[localhost] run: uname -s
[localhost] Login password for 'root': 
[localhost] out: Linux
[localhost] out: 
Done.
Disconnecting from localhost... done.

至此fabric简单安装及使用到此为止

fabric好用之处就是你可以编写fabfiles 重复利用。


参考: http://www.fabfile.org/en/latest/index.html

       http://stackoverflow.com/questions/10109845/which-version-of-fabric-api-is-installed

转载于:https://my.oschina.net/firxiao/blog/341175

你可能感兴趣的:(fabric 安装及简单使用 (centos6))