编译安装python 3.11
先处理下opensll的版本,以免编python译环境异常:安装 openssl-1.1.1
yum remove openssl
cd /opt
wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
tar -zxvf openssl-1.1.1n.tar.gz
cd openssl-1.1.1n/
./config --prefix=/opt/openssl
make depend
make && make install
ln -sf /opt/openssl/bin/openssl /usr/bin/openssl #需要默认在/usr/bin/下创建openssl的软连接
echo "/opt/openssl/lib/" >> /etc/ld.so.conf #需要在环境变量中增加这一行代码
ldconfig -v #使配置生效
openssl version
配置环境变量,在末尾加入代码 echo "/opt/openssl/lib/" >> /etc/ld.so.conf
1、去python3的官方网站下载源代码
https://www.python.org/downloads/
cd /opt
wget https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tar.xz
我的网络不好,手动下载后再上传到/opt目录下
2、解压缩
tar -xvJf Python-3.11.2.tar.xz
安装编译环境
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
yum install libffi-devel -y
3、指定安装路径
mkdir /opt/python3 #创建编译安装目录
cd /opt/Python-3.11.2
#####./configure --prefix=/opt/python3####这条报错,需要下面这个
./configure --prefix=/opt/python3 --with-openssl=/opt/openssl --with-openssl-rpath=auto
已经自动生成了creating Makefile
4、编译并安装
root@jumpserver-app-t01:/opt/Python-3.11.2#make
root@jumpserver-app-t01:/opt/Python-3.11.2#make install
分割线
环境变量的意义,在于项目之间不相互干扰,Linux系统自带python2的环境,使用虚拟环境不会影响系统调用
运行python3的两种方式
方式1:使用绝对路径
root@jumpserver-app-t01:/opt#/opt/python3/bin/python3
Python 3.6.10 (default, Feb 20 2023, 22:17:54)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@jumpserver-app-t01:/opt#
方式2:使用环境变量的方式(相互不干扰)
echo PATH="/opt/python3/bin:$PATH" >> /etc/profile
source /etc/profile
此时显示PATH的环境变量中就有了python3,使用python命令补全也有python2和python3
root@jumpserver-app-t01:/bin#echo PATH="/opt/python3/bin:$PATH" >> /etc/profile
root@jumpserver-app-t01:/bin#source /etc/profile
root@jumpserver-app-t01:/bin#echo $PATH
/opt/python3/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin
root@jumpserver-app-t01:/bin#python
python python2.7 python2-config python3.11 python3-config
python2 python2.7-config python3 python3.11-config python-config
root@jumpserver-app-t01:/bin#pip
pip pip2 pip2.7 pip3 pip3.11
root@jumpserver-app-t01:/bin#
明确python、python3、pip、pip3的安装路径
root@jumpserver-app-t01:/opt#which python
/usr/bin/python
root@jumpserver-app-t01:/opt#which python3
/opt/python3/bin/python3
root@jumpserver-app-t01:/opt#which pip
/usr/bin/pip
root@jumpserver-app-t01:/opt#which pip3
/opt/python3/bin/pip3
root@jumpserver-app-t01:/opt#
5、Python3创建虚拟环境
安装虚拟环境工具,python3是解释器,需要pip3工具给python3安装模块。这类似于Linux系统中的yum工具。
Python3的程序在运行的时候,必须要用pip3安装一些模块才能正常的运行。
先更新一下pip3的下载源,方便快速下载
root@jumpserver-app-t01:/opt#mkdir ~/.pip
root@jumpserver-app-t01:/opt#touch ~/.pip/pip.conf
root@jumpserver-app-t01:/opt#vim ~/.pip/pip.conf
root@jumpserver-app-t01:/opt#cat ~/.pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
root@jumpserver-app-t01:/opt#pip3 install virtualenv
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting virtualenv
Downloading https://mirrors.aliyun.com/pypi/packages/18/a2/7931d40ecb02b5236a34ac53770f2f6931e3082b7a7dafe915d892d749d6/virtualenv-20.17.1-py3-none-any.whl (8.8MB)
100% |████████████████████████████████| 8.9MB 404kB/s
Collecting distlib<1,>=0.3.6 (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/76/cb/6bbd2b10170ed991cf64e8c8b85e01f2fb38f95d1bc77617569e0b0b26ac/distlib-0.3.6-py2.py3-none-any.whl (468kB)
100% |████████████████████████████████| 471kB 401kB/s
Collecting importlib-resources>=5.4; python_version < "3.7" (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/24/1b/33e489669a94da3ef4562938cd306e8fa915e13939d7b8277cb5569cb405/importlib_resources-5.4.0-py3-none-any.whl
Collecting importlib-metadata>=4.8.3; python_version < "3.8" (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/a0/a1/b153a0a4caf7a7e3f15c2cd56c7702e2cf3d89b1b359d1f1c5e59d68f4ce/importlib_metadata-4.8.3-py3-none-any.whl
Collecting platformdirs<3,>=2.4 (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/b1/78/dcfd84d3aabd46a9c77260fb47ea5d244806e4daef83aa6fe5d83adb182c/platformdirs-2.4.0-py3-none-any.whl
Collecting filelock<4,>=3.4.1 (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/84/ce/8916d10ef537f3f3b046843255f9799504aa41862bfa87844b9bdc5361cd/filelock-3.4.1-py3-none-any.whl
Collecting zipp>=3.1.0; python_version < "3.10" (from importlib-resources>=5.4; python_version < "3.7"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0-py3-none-any.whl
Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata>=4.8.3; python_version < "3.8"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_extensions-4.1.1-py3-none-any.whl
Installing collected packages: distlib, zipp, importlib-resources, typing-extensions, importlib-metadata, platformdirs, filelock, virtualenv
Successfully installed distlib-0.3.6 filelock-3.4.1 importlib-metadata-4.8.3 importlib-resources-5.4.0 platformdirs-2.4.0 typing-extensions-4.1.1 virtualenv-20.17.1 zipp-3.6.0
You are using pip version 18.1, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@jumpserver-app-t01:/opt#
6、使用虚拟环境工具,再创建一个Python3解释器,命名为venv1_jump环境名称
pip3 install virtualenv
pip3 install --upgrade pip3
cd /opt
virtualenv --python=python3 venv1_jump
root@jumpserver-app-t01:/opt#virtualenv --python=python3 venv1_jump
created virtual environment CPython3.11.2.final.0-64 in 193ms
creator CPython3Posix(dest=/opt/venv1_jump, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==23.0, setuptools==67.1.0, wheel==0.38.4
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
root@jumpserver-app-t01:/opt#
此时,你的Linux服务器上就有2个python3解释器了
a、查看默认的python3解释器——解释器本体在/opt/python3/bin/python3
root@jumpserver-app-t01:/opt#which python3
/opt/python3/bin/python3
root@jumpserver-app-t01:/opt#
b、我们创建的另一个虚拟解释器,路径是/opt/venv1_jump/bin/python3
root@jumpserver-app-t01:/opt#/opt/venv1_jump/bin/python3
Python 3.11.2 (main, Feb 21 2023, 21:53:52) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@jumpserver-app-t01:/opt#
7、激活虚拟环境,source /opt/venv1_jump/bin/activate进入虚拟环境后,环境变量发生了改变
root@jumpserver-app-t01:/opt#source /opt/venv1_jump/bin/activate
(venv1_jump) root@jumpserver-app-t01:/opt#echo $PATH
/opt/venv1_jump/bin:/opt/python3/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin
(venv1_jump) root@jumpserver-app-t01:/opt#which python3
/opt/venv1_jump/bin/python3
(venv1_jump) root@jumpserver-app-t01:/opt#
我们看到,虚拟环境(venv1_jump)的环境变量是这样的,/opt/jum_venv1/bin:/opt/python3-6-10/bin:/opt/python3-6-10/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin:/root/bin
因为环境变量的查找顺序是从左往右的顺序读取的,因此会优先找到/opt/jum_venv1/bin:
8、最后退出环境变量的方法是deactivate
(venv1_jump) root@jumpserver-app-t01:/opt#deactivate
root@jumpserver-app-t01:/opt#
#安装Redis 3.2.12 #此版本太低,高版本jumpserver不可以使用
mysql关系型数据库,磁盘型数据库,数据是以文件形式,存储在磁盘上的,可以持久化长期存储
redis内存性数据库,缓存型数据库。将一些频繁读取的数据放在内存中调用使用,加快web集群性能。
root@jumpserver-app-t01.novalocal:/opt#yum install redis -y
Complete!
root@jumpserver-app-t01.novalocal:/opt#systemctl start redis
root@jumpserver-app-t01.novalocal:/opt#systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
root@jumpserver-app-t01.novalocal:/opt#
检查redis的端口运行情况6379端口
root@jumpserver-app-t01.novalocal:/opt#netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2408/sshd: /usr/sbi
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 8607/redis-server 1
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 875/rpcbind
tcp 0 0 0.0.0.0:10032 0.0.0.0:* LISTEN 1578/java
tcp6 0 0 :::22 :::* LISTEN 2408/sshd: /usr/sbi
tcp6 0 0 :::3306 :::* LISTEN 89110/mysqld
tcp6 0 0 :::111 :::* LISTEN 875/rpcbind
udp 0 0 0.0.0.0:68 0.0.0.0:* 23060/dhclient
udp 0 0 0.0.0.0:111 0.0.0.0:* 875/rpcbind
udp 0 0 10.22.2.160:123 0.0.0.0:* 879/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 879/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 879/ntpd
udp 0 0 0.0.0.0:613 0.0.0.0:* 875/rpcbind
udp6 0 0 :::111 :::* 875/rpcbind
udp6 0 0 :::123 :::* 879/ntpd
udp6 0 0 :::613 :::* 875/rpcbind
root@jumpserver-app-t01.novalocal:/opt#
登录redis查看是否正常运行:运行ping返回pong
root@jumpserver-app-t01:/opt#redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
root@jumpserver-app-t01:/opt#