感谢支持
我们一直在努力

Python部署管理工具Fabric

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 http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
–2012-09-27 15:47:23–  http://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-

赞(0) 打赏
转载请注明出处:服务器评测 » Python部署管理工具Fabric
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏