fabric 安装及简单使用 (centos6)

前端之家收集整理的这篇文章主要介绍了fabric 安装及简单使用 (centos6)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

简介

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

第一步安装依赖包

安装epel源

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


安装fabric依赖及pip

yuminstall-ypython-pipgccpython-devel
pipinstallpycrypto-on-pypi


第二步安装fabric

pipinstallfabric


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

测试安装是否成功

python-c"fromfabric.apiimport*;printenv.version"

显示出版本说明安装成功

简单使用

编写fabfile;

vim host_type.py

fromfabric.apiimportrun
defhost_type():
run('uname-s')

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

#fab-fhost_type.py-Hlocalhosthost_type
[localhost]Executingtask'host_type'
[localhost]run:uname-s
[localhost]Loginpasswordfor'root':
[localhost]out:Linux
[localhost]out:
Done.
Disconnectingfromlocalhost...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://www.f2er.com/centos/379773.html

猜你在找的CentOS相关文章