安装ansible并配置(可选,批量时)
[root@hdss7-10 ~]# yum -y install epel-release yum-utils
[root@hdss7-10 ~]# yum -y install ansible
[root@hdss7-10 ~]# vim /etc/ansible/ansible.cfg
[defaults]
inventory = /etc/ansible/hosts
ask_pass = False
remote_port = 22
host_key_checking = False
remote_user = root
[root@hdss7-10 ~]# vim /etc/ansible/hosts
[admin]
172.16.186.10
[node]
172.16.186.11
172.16.186.12
172.16.186.13
生成秘钥
[root@hdss7-10 ~]# ssh-keygen -t rsa -P ''
[root@hdss7-10 ~]# for i in {10..13};do ssh-copy-id root@172.16.186.$i;done
安装pyhton3环境
[root@hdss7-10 ~]# cat >> 1.sh <<EOF
#!/bin/bash
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
tar -xvJf Python-3.8.2.tar.xz
cd Python-3.8.2/
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
python3 -V
pip3 -V
EOF
修改1.sh
[root@hdss7-10 ~]# sh 1.sh
[root@hdss7-10 ~]# cp 1.sh{,.bak}
[root@hdss7-10 ~]# sed -i "s/^tar/# tar/" 1.sh.bak
发送到其他节点并安装
[root@hdss7-10 ~]# ansible node -m copy -a "src=/root/1.sh.bak dest=/root/1.sh mode=0755"
[root@hdss7-10 ~]# ansible node -m copy -a "src=/root/python-3.8.2.tar.xz dest=/root/python-3.8.2.tar.xz"
[root@hdss7-10 ~]# ansible node -m shell -a "sh /root/1.sh"
Python3.9.1 安装
[root@hdss7-10 ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
yum -y install epel-release
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc gcc-c++ wget
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
tar -zxvf Python-3.9.1.tgz
cd Python-3.9.1
./configure --prefix=/usr/local/python3.9
make && make install
cat >> /etc/profile << EOF
export PYTHON_HOME=/usr/local/python3.9
export PATH=$PYTHON_HOME/bin:$PATH
EOF
source /etc/profile
[root@hdss7-10 Python-3.9.1]# cd
[root@hdss7-10 ~]# python3.9
Python 3.9.1 (default, Jan 20 2021, 10:12:02)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Ubuntu 20 安装
# sudo apt upgrade -y
sudo apt install -y software-properties-common
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
tar -zxvf Python-3.9.1.tgz
cd Python-3.9.1/
./configure --enable-optimizations --prefix=/usr/local/python3.9
sudo make && sudo make install
sudo vim /etc/profile
export PYTHON_HOME=/usr/local/python3.9
export PATH=$PYTHON_HOME/bin:$PATH
source /etc/profile