linux centos7 编译安装python3 --shell脚本

#!/bin/bash
yum install -y wget
cd /etc/yum.repos.d/
mkdir bak
mv * bak
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install zlib-devel bzip2-devel openssl-devel openssl-static ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel lzma gcc
yum -y groupinstall "Development tools"
cd /usr/local/src/
# https://www.python.org/ftp/python       # 官网下载
wget http://work.eisc.cn/ruanjian/Python-3.7.0.tar.xz
yum install -y star
tar xvf Python-3.7.0.tar.xz
mv Python-3.7.0 /usr/local/python-3.7
cd /usr/local/python-3.7/
 ./configure --prefix=/usr/local/sbin/python-3.7                # 将python3.7安装到/usr/local/sbin/python-3.7目录下
make && make install                                                    # 安装完成后,若出现以下两行,说明安装成功;
# 出现以下两行是安装成功
# Installing collected packages: setuptools, pip
# Successfully installed pip-10.0.1 setuptools-39.0.1
rm -rf /usr/bin/python3
ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python3
ls /usr/bin/ |grep python
# 将python命令通过软链接指向到python3命令(就是上面那一大串/usr/local/sbin/python-3.7/bin/python3)
NR=`cat -n /usr/bin/yum | grep "\!/usr/bin/python" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/\!\/usr\/bin\/python.*/\!\/usr\/bin\/python2.7/g" /usr/bin/yum
sed -i "s/\/usr\/bin\/python.*/\/usr\/bin\/python2.7/g" /usr/libexec/urlgrabber-ext-down
ln -s /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip  # pip 重定向到python3
python3 -V          # 查看python3的详细版本
pip --version                                                                   # 查看pip版本
################### 安装pip 源 ######################
yum -y install zlib-devel readline-devel libffi-devel python-devel openssl-devel gcc git
pip install --upgrade pip  -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
                                                                                        # 安装 pip 源
cd ~
mkdir .pip
cd .pip
echo "
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
" > pip.conf                                                                    # 配置 pip 源
yum install -y paramiko                                                 # 远程控制工具
###################################################
## 一键安装:    
yum -y install screen           # 安装工具包
screen -S eisc                          # 新建视窗名字为eisc
echo "screen 新建窗口后台运行,如果断网,请使用命令screen -ls  查看ID ;再次命令进入 screen -x ID"
yum install -y wget ; wget eisc.cn/file/shell/yumpython3.sh ; chmod 755 yumpython3.sh ;  sh yumpython3.sh
上一篇:python 与linux交互 paramiko 自动化运维 批量登录控制多台主机执行命令


下一篇:linux centos 查看cpu是否开启超线程虚拟化和配置信息