欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python部署管理工具fabric

程序员文章站 2023-11-19 12:09:16
fabric是个轻量级的远程维护工具,当然是结合python来使用,先看介绍: fabric is a python (2.5 or higher) library and co...

fabric是个轻量级的远程维护工具,当然是结合python来使用,先看介绍:
fabric is a python (2.5 or higher) library and command-line tool for streamlining the use of ssh for application deployment or systems administration tasks.
不过需要注意的是fabric只支持2.5以后python,然而rhl5默认的是2.4.3,因此需要首先升级先python。
升级之前是2.4.3:
[root@gtlionsdev ~]# python -v
python 2.4.3

[root@gtlionsdev ~]# wget https://www.python.org/ftp/python/2.7.3/python-2.7.3.tar.bz2
--2012-09-27 15:47:23--  https://www.python.org/ftp/python/2.7.3/python-2.7.3.tar.bz2
正在解析主机 www.python.org... 82.94.164.162, 2001:888:2000:d::a2
connecting to www.python.org|82.94.164.162|:80... 已连接。
已发出 http 请求,正在等待回应... 200 ok
长度:11793433 (11m) [application/x-bzip2]
saving to: `python-2.7.3.tar.bz2'

100%[=====================================================================================================================================================>] 11,793,433   381k/s   in 26s    

2012-09-27 15:47:55 (451 kb/s) - `python-2.7.3.tar.bz2' saved [11793433/11793433]
[root@gtlionsdev ~]# tar -jxf python-2.7.3.tar.bz2
[root@gtlionsdev ~]# cd python-2.7.3
[root@gtlionsdev python-2.7.3]# ./configure
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking machdep... linux2
checking extraplatdir...
checking machine type as reported by uname -m... x86_64
checking for --without-gcc... no
checking for gcc... gcc
checking whether the c compiler works... yes
checking for c compiler default output file name... a.out
..........
..........
checking for build directories... done
configure: creating ./config.status
config.status: creating makefile.pre
config.status: creating modules/setup.config
config.status: creating misc/python.pc
config.status: creating modules/ld_so_aix
config.status: creating pyconfig.h
creating modules/setup
creating modules/setup.local
creating makefile
[root@gtlionsdev python-2.7.3]# make
gcc -pthread -c -fno-strict-aliasing -g -o2 -dndebug -g -fwrapv -o3 -wall -wstrict-prototypes  -i. -iinclude -i./include   -dpy_build_core -o modules/python.o ./modules/python.c
gcc -pthread -c -fno-strict-aliasing -g -o2 -dndebug -g -fwrapv -o3 -wall -wstrict-prototypes  -i. -iinclude -i./include   -dpy_build_core -o parser/acceler.o parser/acceler.c
..........
漫长的make过程
漫长的make过程
..........
failed to build these modules:
readline                                             

running build_scripts
creating build/scripts-2.7
copying and adjusting /root/python-2.7.3/tools/scripts/pydoc -> build/scripts-2.7
copying and adjusting /root/python-2.7.3/tools/scripts/idle -> build/scripts-2.7
copying and adjusting /root/python-2.7.3/tools/scripts/2to3 -> build/scripts-2.7
copying and adjusting /root/python-2.7.3/lib/smtpd.py -> build/scripts-2.7
changing mode of build/scripts-2.7/pydoc from 644 to 755
changing mode of build/scripts-2.7/idle from 644 to 755
changing mode of build/scripts-2.7/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py from 644 to 755
/usr/bin/install -c -m 644 ./tools/gdb/libpython.py python-gdb.py
提示readline模块失败,囧,先跳过再说。
[root@gtlionsdev python-2.7.3]# make install
[root@gtlionsdev python-2.7.3]# /usr/local/bin/python2.7 -v
python 2.7.3
[root@gtlionsdev python-2.7.3]# mv /usr/bin/python /usr/bin/python2.4.3.bak
[root@gtlionsdev python-2.7.3]# ln -s /usr/local/bin/python2.7 /usr/bin/python
[root@gtlionsdev python-2.7.3]# python -v
python 2.7.3
另外由于yum调用python,这个仍然需要使用2.4.3版本,因此需要修改下yum脚本:
[root@gtlionsdev python-2.7.3]# vim /usr/bin/yum
将首行的#!/usr/bin/python改成#!/usr/bin/python2.4,然后测试一下:
[root@gtlionsdev python-2.7.3]# yum list
[root@gtlionsdev python-2.7.3]# yum update
一切正常,ok。

然后接下来开始安装fabric,推荐使用pip来安装,pip是用来替代easy_install的不错的工具:
$ curl -o https://raw.github.com/pypa/virtualenv/master/virtualenv.py
$ python virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install fabric

安装完成记得把环境变量包含/root/my_new_env/bin进path。
-the end-