安装过程需要联网
1. 下载安装 python
因为 fabric 需要运行在 python 2.5 以上版本,所以下载包的时候要注意版本.我用CentOS 5,自带了Python 2.4.3,所以需要先升级.
[[email protected] ~]# tar zxvf Python-2.7.7.tgz
[[email protected] ~]# mv Python-2.7.7 python-2.7.7
[[email protected] ~]# cd python-2.7.7/
[[email protected] ~]# ./configure --prefix=/opt/python277
[[email protected] ~]# make
[[email protected] ~]# make install
[[email protected] ~]# mv /usr/bin/python /usr/bin/python2.4.bak
[[email protected] ~]# ln -s /opt/python277/bin/python /usr/bin/python
注意: 安装高版本的python之后可能导致yum命令不能使用
[[email protected] python277]# vim /usr/bin/yum
#!/usr/bin/python2.4 --使用python2.4来执行
[[email protected] python277]# vim /usr/sbin/yum-updatesd
#!/usr/bin/python2.4 -tt
2. 安装setuptools (如果不想装 ez-install 可以直接跳到3.2安装pip)
[[email protected] python-2.7.7]# cd /opt/python277/
[[email protected] python-2.7.7]# vim ez-setup.py
内容见附件 dz-setup.txt(下载后文件后缀需改为.py)
[[email protected] python277]# python ez-setup.py
3. 安装 pip
3.1 如果这种方式不行则用3.2的方式安装
[[email protected] bin]# pwd
/opt/python277/bin
[[email protected] bin]# python easy_install pip
3.2 我这里使用的是 pip-1.5.tar.gz
[[email protected] python277]# tar zxvf pip-1.5.tar.gz
[[email protected] python277]# cd pip-1.5
[[email protected] pip-1.5]# python setup.py install
4. 用pip安装fabric
[[email protected] pip-1.5]# cd /opt/python277/bin/
或者 [[email protected] bin]# ln -s /opt/python277/bin/pip /usr/bin/pip
[[email protected] bin]# pwd
/opt/python277/bin
[[email protected] bin]# python pip install fabric
5. 把 fab 命令加入到 /usr/bin
[[email protected] bin]# ln -s /opt/python277/bin/fab /usr/bin/fab
6. 测试文件
[[email protected] fabtest]# cat fabfile.py from fabric.api import * env.hosts=[‘192.168.98.52‘,‘192.168.98.53‘,‘192.168.98.54‘] def task1(): |
7. 执行
[[email protected] fabtest]# fab task1