标签:figure shel .sh data sleep something highlight wrong python2.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"执行脚本。
标签:figure shel .sh data sleep something highlight wrong python2.7
原文地址:http://www.cnblogs.com/uglyliu/p/6203722.html