一、升级python3.7

1、安装依赖包:

yum install make gcc gcc-c++   #解决如果编译出错,需要检查make,gcc等是否安装好

yum -y install zlib*    #解决需要安装zlib的解压缩类库(import pip._internalzipimport.ZipImportError: can't decompress data; zlib not available)

yum install libffi-devel -y      #3.7版本需要一个新的包libffi-devel(ModuleNotFoundError: No module named '_ctypes':)

yum install wget  #安装wget包

yum install openssl-devel -y  #解决pip is configured with locations that require TLS/SSL, however the错误(其他扩展命令: rpm -aq|grep openssl )

 

yum install epel-release -y

yum groupinstall "Development tools" -y

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel zx-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel -y

 

2、查看当前版本

(1)检查确认系统的相关信息

[root@localhost /]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost /]# uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost /]# python -V
Python 2.7.5

当前的python版本号为2.7.5

3、安装升级python3.7

(1)下载安装Python-3.7.0

[root@localhost /]# mkdir -p /server/tools/
[root@localhost /]# cd /server/tools/
[root@localhost tools]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz   #此处可以通过ssh上传至 /server/tools/目录

(2) 解压编译安装

[root@localhost tools]# tar -xf Python-3.7.0.tgz

[root@localhost tools]# cd Python-3.7.0

[root@localhost Python-3.7.0]# ./configure --with-ssl 

[root@localhost Python-3.7.0]# make

[root@localhost Python-3.7.0]#  make install 

出现一下提示,则说明安装成功

centos7可以直接升级到rocky 9吗 centos7.6升级7.7_Python

(3) 安装完成,需要更改默认的python版本

# 检查当前默认的python2,默认自带的python位置在”/usr/bin/“目录下

[root@localhost Python-3.7.0]# ll /usr/bin/python*
lrwxrwxrwx. 1 root root 7 3月 26 23:38 /usr/bin/python -> python2
lrwxrwxrwx. 1 root root 9 3月 26 23:38 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 10月 31 2018 /usr/bin/python2.7

# 检查新安装的python3,默认编译安装的python位置在”/usr/local/bin/“目录下

[root@localhost Python-3.7.0]# ll /usr/local/bin/python*
lrwxrwxrwx. 1 root root 9 6月 16 21:47 /usr/local/bin/python3 -> python3.7
-rwxr-xr-x. 2 root root 13966016 6月 16 21:46 /usr/local/bin/python3.7
lrwxrwxrwx. 1 root root 17 6月 16 21:47 /usr/local/bin/python3.7-config -> python3.7m-config
-rwxr-xr-x. 2 root root 13966016 6月 16 21:46 /usr/local/bin/python3.7m
-rwxr-xr-x. 1 root root 3097 6月 16 21:47 /usr/local/bin/python3.7m-config
lrwxrwxrwx. 1 root root 16 6月 16 21:47 /usr/local/bin/python3-config -> python3.7-config

# 修改默认的python, 删除旧的python的软连接,创建新的python2和python3的软连接

[root@localhost Python-3.7.0]# cd /usr/bin/
[root@localhost bin]# rm -f python2
[root@localhost bin]# mv python python2.6.ori
[root@localhost bin]# ln -s python2.7 python2
[root@localhost bin]# ln -s /usr/local/bin/python3 /usr/bin/python

(4) 检查修改后的python版本

[root@localhost bin]# python -V
Python 3.7.0
[root@localhost bin]# python2 -V
Python 2.7.5
[root@localhost bin]# python3 -V
Python 3.7.0
[root@localhost bin]#

(5)查看pip3版本

[root@vm-1593426106 ~]# pip3 -V
pip 10.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

可以看到,默认打开的python版本已经是3.7.0,至此python的版本已经升级成功

4、其他文件配置修改

# python的默认版本修改为3.x之后,系统对于yum的调用会出问题,所以需要修改下yum的相关配置

(1)vi /usr/bin/yum    #保证yum可用

(2)vi /usr/libexec/urlgrabber-ext-down

以上两个文件均由

centos7可以直接升级到rocky 9吗 centos7.6升级7.7_Python_02

改为

centos7可以直接升级到rocky 9吗 centos7.6升级7.7_Python_03

(3)vim /usr/sbin/firewalld    #保证防火墙可用

(4)vim /usr/bin/firewall-cmd

以上两个文件均由python改为

centos7可以直接升级到rocky 9吗 centos7.6升级7.7_python_04

5、测试安装情况

yum -y install vim

centos7可以直接升级到rocky 9吗 centos7.6升级7.7_Python_05

二、ftp 安装

centos如果开启了ssh2,不需要特殊安装,直接可访问

三、安装apache

1、apache安装及配置

yum install httpd  httpd-devel -y 

2、配置开机启动

systemctl start httpd

systemctl enable httpd 

3、查看启动状态

systemctl status httpd

4、配置apache

/etc/httpd/conf/httpd.conf

<Directory />
  AllowOverride none
  Require all granted
</Directory>
<Directory "C:/xampp/htdocs">
  Options FollowSymLinks
  AllowOverride All
  Allow from all
  Require all granted
  <Files "index.php">
    SetHandler application/x-httpd-php
  </Files>
  <Files "zentao.php">
    SetHandler application/x-httpd-php
  </Files>
  <Files "zentaopro.php">
    SetHandler application/x-httpd-php
  </Files>
</Directory>

同时修改访问端口,listen

重启服务

四、配置防火墙

1、查看防火墙状态

systemctl status firewalld.service 

2、开启和停止依然是start和stop

3、增加可访问端口

开启端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=8081/tcp --permanent

firewall-cmd --zone=public --add-port=8080/tcp --permanent

firewall-cmd --zone=public --add-port=3306/tcp --permanent

查看端口是否开启

 firewall-cmd --query-port=80/tcp

重启防火墙

firewall-cmd --reload

查询哪些端口开启

 firewall-cmd --list-port

添加自启动:

 systemctl enable firewalld.service 

五、配置django

1、安装 virtualenv

pip3 install virtualenv

2、配置virtualenv

mkdir -p /var/www/html/django

cd /var/www/html/django

 virtualenv -p /usr/local/bin/python3.7 .py3env       #.py3env是一个文件夹名字,可以自定义

开启virtualenv python3环境并在此环境安装django相关模块(virtualenv python3环境)

source .py3env/bin/activate

pip install django pymysql

deactivate      #退出virtualenv python3 虚拟环境

3、apache配置与mod_wsgi

(1)安装 mod_wsgi for python3(在使用的虚拟环境中安装)

pip3 install mod_wsgi

(2)导出apache所需的mod_wsgi模块

 mod_wsgi-express install-module

打印出一下内容:

LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"

WSGIPythonHome "/var/www/html/.py3env"

(3)配置apache配置文件

先执行: vi /etc/httpd/conf/httpd.conf

末行添加:

LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"

再执行 vi /etc/httpd/conf.d/django.conf

新建以下内容

Alias /static /var/www/html/django/django2/static
<Directory /var/www/html/django/django2/static>
Require all granted
</Directory>
 
<Directory /var/www/html/django/django2/django2>
 <Files wsgi.py>
   Require all granted
 </Files>
</Directory>
 
WSGIPythonHome "/var/www/html/django/.py3env"
 
Listen 8080
<VirtualHost *:8080>
 
ServerName django.example.com
 
WSGIDaemonProcess myproject python-path=/var/www/html/django/.py3env/lib/python3.6/site-pachages
WSGIScriptAlias / /var/www/html/django/django2/django2/wsgi.py
 
</VirtualHost>

4、重启apache

# systemctl restart httpd

# systemctl enable httpd

deactivate(退出virtualenv python3 虚拟环境)