標籤: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/bashyum install python-devel zlib-devel -ycd /data/x5online/toolstar xf Python-2.7.6.tgzcd Python-2.7.6echo "開始編譯python"./configure --prefix=/usr/localmake if [ $? -eq 0 ];then echo "make is ok"else echo "something is wrong" exitfimake installif [ $? -eq 0 ];then echo "make install is ok"else echo "something is wrong" exitfiln -s /usr/local/python2.7 /usr/bin/pythonsleep 1echo "開始安裝setuptools"cd /data/x5online/toolstar xf setuptools-14.3.1.tar.gzcd setuptools-14.3.1python setup.py installif [ $? -eq 0 ];then echo "setup is ok"else echo "something is wrong" exitfisleep 1echo "開始安裝pip"cd /data/x5online/toolstar xf pip-9.0.1.tar.gzcd pip-9.0.1python setup.py installif [ $? -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