centos6.5升级python为2.7

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos6.5升级python为2.7相关的知识,希望对你有一定的参考价值。

今天线上服务器全部升级python环境为python-2.7.6的环境,我采用的方法是ansible+shell,代码如下,友提,Python-2.7.6.tgz、setuptools-14.3.1.tar.gz、pip-9.0.1.tar.gz,这三个包我是提前下好放在/data/x5online/tools目录下,当然你也可以直接在脚本中wget相关包,个人喜欢把包下好了然后统一放在/data/x5online/tools目录里,脚本比较简单,记录下,省的又忘了,节约时间。时间就是金钱啊

#!/bin/bash

yum install python-devel zlib-devel -y

cd /data/x5online/tools

tar xf Python-2.7.6.tgz

cd Python-2.7.6
echo "开始编译python"
./configure --prefix=/usr/local

make 
if [ $? -eq 0 ];then

    echo "make is ok"
else
    echo "something is wrong"
    exit
fi
make install
if [ $? -eq 0 ];then

    echo "make install is ok"
else
    echo "something is wrong"
    exit
fi


ln -s /usr/local/python2.7 /usr/bin/python

sleep 1

echo "开始安装setuptools"
cd /data/x5online/tools

tar xf setuptools-14.3.1.tar.gz

cd setuptools-14.3.1

python setup.py install
if [ $? -eq 0 ];then

    echo "setup is ok"
else
    echo "something is wrong"
    exit
fi

sleep 1

echo "开始安装pip"

cd /data/x5online/tools

tar xf pip-9.0.1.tar.gz

cd pip-9.0.1

python setup.py install

if [ $? -eq 0 ];then

    echo "all is ok"
else
    echo "something is wrong"

fi

然后使用ansible all -m copy "src=/data/x5online/install_python.sh dest=/data/x5online"分发至所有需要升级python的服务器

最后ansible all -m shell "/data/x5online/install_python.sh"执行脚本。

以上是关于centos6.5升级python为2.7的主要内容,如果未能解决你的问题,请参考以下文章

centos6.5 python2.6升级2.7

脚本自动化装centos6.5 python2.6升级2.7

centos6.5升级python2.6到2.7 + 安装pip

Python升级版本2.6到2.7

CentOS python 2.6 升级到 python 2.7

python 2.6升级到2.7