【26.0】项目部署准备

【一】上线前准备

  • 购买一台服务
  • 项目跑在服务器上
  • 购买公网ip:别人访问我们的ip,就能访问到我们的项目
  • 购买域名:备案---》访问域名---》转发到你的ip

【1】购买一台服务:

  • 在上线前,您需要购买一台云服务器或虚拟主机服务,以托管您的项目。
  • 选择合适的服务提供商时,您需要考虑各种因素,如价格、性能、可靠性和技术支持等。
  • 常见的云服务提供商包括阿里云、腾讯云、亚马逊AWS等。

【2】项目跑在服务器上:

  • 一旦您购买了服务,您需要将您的项目部署到服务器上。
  • 这可能涉及到设置服务器环境、安装所需的软件和配置项目依赖项等步骤。
  • 确保您的项目在服务器上正常运行之前,您可以通过SSH或远程桌面连接等方式来管理服务器。

【3】购买公网IP:

  • 公网IP是使您的项目能够通过互联网进行访问的必要条件。

  • 在购买服务时,您可以选择购买公网IP,并将其绑定到您的服务器上。

  • 公网IP允许其他用户通过该IP地址来访问您的项目。

  • 在实际运行时,您还需要配置服务器的网络设置,以确保公网IP的正确使用和访问。

【4】购买域名:

  • 购买域名是为了将用户友好的网址映射到您的公网IP地址上。
  • 域名就是您在浏览器中输入的网址,如www.example.com。
  • 购买域名时,您需要选择一个合适的域名注册商,并确保您的域名能够正常解析到您的公网IP地址。

a. 备案:

  • 如果您在中国大陆地区购买域名并将其指向国内服务器,那么根据中国法律要求,您需要进行网站备案。
  • 备案是向相关部门提交一些企业或个人信息的流程,以获得网站的访问许可。
  • 备案的具体步骤和要求可以咨询您所在地的相关机构或域名注册商。

b. 访问域名:

  • 一旦您购买了域名并进行了备案(如果适用),您就可以通过输入域名来访问您的项目了。
  • 例如,在浏览器中输入www.example.com即可访问您的项目。

c. 将域名转发到您的IP:

  • 在购买域名后,您需要将域名的DNS设置指向您的公网IP地址。
  • 这涉及到在域名注册商的管理界面上进行相应的配置。
  • 具体步骤可能因注册商而异,但通常包括添加A记录、CNAME记录或将域名的NS记录指向您的服务器。
  • 通过按照上述步骤完成,您将能够使您的项目在互联网上正常访问。
  • 需要注意的是,确保您的服务器和项目的安全性,例如使用防火墙、更新软件补丁、加密传输等措施,以及定期备份数据以应对意外情况。

【二】阿里云

【1】购买服务器:

  • 在阿里云上购买服务器实例,您可以按照以下步骤进行操作:

(1)登录阿里云控制台

(2)选择"实例"

  • 在左侧导航栏中选择"实例",然后点击"创建实例"按钮。

  • 点击云服务器
    • 选择实例
      • 选择创建实例

  • 补充知识
    • 付费类型
      • 包年包月:您可以预付一定的费用,购买一个固定时长的实例。包年包月的实例价格相对更低适合长期稳定的业务需求
      • 按量付费:您根据实际资源使用情况进行计费,按小时进行结算按量付费弹性灵活适用于临时、突发或不确定的业务需求
      • 抢占式实例:抢占式实例是一种价格更低的付费方式,但在资源竞争激烈时可能会被回收。适用于对实例可用性要求相对较低的场景。
    • 地域
      • 阿里云在全球范围内提供了多个地域供您选择。
      • 地域是指物理数据中心所在的地理位置。
      • 您可以选择离您最近的地域进行实例购买,这可以带来更低的延迟和更好的用户体验。
      • 当您选择地域时,还需要注意该地域支持的云产品和服务范围是否满足您的需求
    • 网络即可用区
      • 专有网络:专有网络是您基于阿里云创建的自定义私有网络,不同的专有网络之间逻辑上彻底隔离。您可以在自己创建的专有网络内创建和管理云资源,例如ECS、SLB和RDS等,了解更多>
      • 交换机:交换机是组成专有网络的基础网络设备。交换机可以连接不同的云资源。在专有网络内创建云资源时,必须指定云资源所连接的交换机,了解更多>
      • 可用区:可用区是指在同一地域内,电力和网络互相独立的物理区域。同一可用区内实例之间的网络延时更小,其用户访问速度更快,了解更多>
    • 实例
      • 实例是阿里云服务器的核心组件,它包含了CPU、内存和存储等资源,可以根据需求来选择不同配置的实例。
      • CPU和内存的购买应该根据应用程序的要求和负载情况进行合理选择。
    • 镜像
        • 镜像是ECS实例的“装机盘”,它提供了操作系统、初始化应用数据和预装软件等内容。
        • 一般情况下,阿里云服务器的镜像默认为CentOS操作系统,但也可根据自己的需求选择其他操作系统。
    • 系统盘
      • 系统盘相当于服务器的硬盘,用于存储操作系统和应用程序等数据。
      • 系统盘的容量和性能可以根据需求进行按需购买。
    • 公网IP很重要(必选)
      • 公网IP对于阿里云服务器非常重要,它可以使服务器与外部网络进行通信。
      • 在创建ECS实例时,一定要注意选择并关联一个公网IP。
    • 带宽计费模式
      • 按使用流量
        • 按使用流量方式是根据实际使用的流量来计费,即使用多少流量就需要支付多少费用
      • 按固定带宽
        • 按固定带宽方式是按照预设的固定带宽来计费,无论实际使用情况如何,费用都保持不变。
      • 根据实际需求选择适合自己的计费模式。
    • 带宽峰值
      • 带宽峰值是指ECS实例所能支持的最大带宽速率。
      • 用户可以根据自身业务的需要,在创建ECS实例时根据需求自行选择合适的带宽峰值。
    • 其他默认

(3)下单支付

  • 根据付费类型选择包年包月或按量付费,并完成支付流程。

  • 确认订单并进行购买,等待实例创建完成。

  • 一般是账户内余额大于100才让下单

(4)下单完成后

  • 在实例的位置就可以看到自己的服务器了

【2】使用服务器:

  • 在服务器创建完成后,您可以通过以下方式进行使用:

    • 使用SSH工具连接到您的实例。通过SSH密钥对或密码登录,远程管理您的服务器。

    • 配置您的服务器环境。您可以安装所需的应用程序、配置服务器参数以满足您的业务需求。

    • 上传和下载文件。通过SCP或SFTP协议,将文件从本地传输到服务器或从服务器下载到本地。

    • 设置Web服务器。如果您需要托管网站或应用程序,可以配置Web服务器,如Nginx或Apache。

    • 监控和管理服务器。使用阿里云提供的监控服务、日志服务等,对服务器进行监控和管理,确保正常运行和安全性。

【3】注意事项:

  • 购买和使用阿里云服务器时,请注意以下事项:

    • 选择适合的实例规格:根据您的业务需求和预期的负载,选择合适的实例规格以确保性能和资源的充足。

    • 安全设置:配置安全组和网络访问控制,限制入站和出站流量,以保护服务器免受未经授权的访问。

    • 数据备份和灾难恢复:定期备份重要数据,并将其存储在可靠的存储服务上,以便在意外情况下进行恢复和保护数据安全。

    • 定期更新和维护:及时更新操作系统和应用程序,修补安全漏洞,确保服务器的稳定性和安全性。

    • 监控和预警:使用阿里云提供的监控工具,定期检查服务器的性能和运行状态,以及设置告警通知,及时发现可能的故障或问题

【三】腾讯云

【1】购买服务器

(1)登陆控制台

(2)选择云服务器

(3)配置选择(参考上面的阿里云介绍)

(4)完成购买

  • 够完成后即可使用

【2】使用服务器

在服务器创建完成后,您可以通过以下方式进行使用:

  • 使用SSH工具连接到您的实例。通过SSH密钥对或密码登录,远程管理您的服务器。

  • 配置您的服务器环境。您可以安装所需的应用程序、配置服务器参数以满足您的业务需求。

  • 上传和下载文件。通过SCP或SFTP协议,将文件从本地传输到服务器或从服务器下载到本地。

  • 设置Web服务器。如果您需要托管网站或应用程序,可以配置Web服务器,如Nginx或Apache。

  • 监控和管理服务器。使用阿里云提供的监控服务、日志服务等,对服务器进行监控和管理,确保正常运行和安全性。

【3】注意事项

购买和使用服务器时,请注意以下事项:

  • 选择适合的实例规格:根据您的业务需求和预期的负载,选择合适的实例规格以确保性能和资源的充足。

  • 安全设置:配置安全组和网络访问控制,限制入站和出站流量,以保护服务器免受未经授权的访问。

  • 数据备份和灾难恢复:定期备份重要数据,并将其存储在可靠的存储服务上,以便在意外情况下进行恢复和保护数据安全。

  • 定期更新和维护:及时更新操作系统和应用程序,修补安全漏洞,确保服务器的稳定性和安全性。

  • 监控和预警:使用阿里云提供的监控工具,定期检查服务器的性能和运行状态,以及设置告警通知,及时发现可能的故障或问题

【四】远程连接服务器媒介

【1】FinalShell

(1)下载

  • 根据自己的系统下载对应的文件即可

(2)安装

  • 一路下一步安装即可

(3)使用

  • 软件界面

  • 连接服务器
    • 依次选择

  • 名称:自己的自定义服务器名字
  • 主机:购买的服务器恭公网IP
  • 端口:22(一般不做更改)
  • 用户名:自己服务器的用户名(默认root)
  • 密码:自己服务器的密码(实在没有就在服务器设置一个)
  • 连接成功
    • 第一次连接时,会提示是否记住秘钥
      • 自己考虑
      • 选择记住后第二次链接就不需要再输入密码了,打开就可以直接连接

【2】CMD直连

  • 也可以选择使用CMD窗口命令行直连

  • 打开CMD窗口

  • 终端输入

ssh root@服务IP    输入密码

【3】Tabby

(1)下载

  • 访问可能会有点慢,自己解决

以下是Clink提供的一些亮点:

  • 与Bash相同的行编辑(来自GNU Readline库版本8.1)。
  • 会话之间的历史记录持久性。
  • 上下文相关完成;
    • 可执行文件(和别名)。
    • 目录命令。
    • 环境变量。
  • 上下文相关的彩色输入文本。
  • 来自历史记录和完成的自动建议。
  • 新的键盘快捷键;
    • 交互式完成列表 (+)。CtrlSpace
    • 增量历史记录搜索(+和+)。CtrlRCtrlS
    • 强大的完成 ()。Tab
    • 撤消 (+)。CtrlZ
    • 环境变量扩展 (++)。CtrlAltE
    • Doskey 别名扩展 (++)。CtrlAltF
    • 滚动屏幕缓冲区 (+等)。AltUp
    • Shift+箭头键选择文本,键入替换所选文本等。
    • (按 + 查看更多...AltH
  • 目录快捷方式;
    • 键入目录名称后跟路径分隔符是该目录的快捷方式。cd /d
    • 键入 or 是 or 的快捷方式(每增加一个 )。..``...``cd ..``cd ..\..``.``\..
    • 键入或更改以前的当前工作目录。-``cd -
  • 带有Lua的脚本化自动建议。
  • 使用 Lua 完成脚本化。
  • 使用 Lua 的可脚本化键绑定。
  • 彩色和可编写脚本的提示。
  • 自动应答“终止批处理作业?”提示。

默认情况下,Clink 绑定 + 以显示当前的键绑定。更多的功能也可以在GNU的Readline中找到。AltH

(2)安装

  • 解压后即可使用

  • 软件主界面

(3)连接服务器

  • 选择管理配置

  • 选择新配置

  • 选择SSH会话

  • 输入自己的服务器信息

(4)连接成功

(5)个人使用评价

  • 这个软件感觉比FinalShell还要友好一点,就是没有FinalShell那种监控服务器的可视化界面,其他的功能还是挺全的,功能也有很多
  • 有兴趣的朋友可以自己研究研究

【五】上线架构图

【六】安装Git

【1】方式一:通过yum包管理器

  • 通过yum包管理器直接安装git命令行工具。
  • 该命令会自动下载并安装最新版本的Git。
yum install git -y
[root@VM-8-11-opencloudos ~]# yum install git -y
Last metadata expiration check: 1:16:22 ago on Mon 14 Aug 2023 08:33:32 AM CST.
Dependencies resolved.
======================================================================================================================================== Package                          Architecture               Version                                Repository                     Size
========================================================================================================================================Installing:
 git                              x86_64                     2.31.1-3.oc8                           AppStream                     160 k
Installing dependencies:
 git-core                         x86_64                     2.31.1-3.oc8                           AppStream                     4.8 M
 git-core-doc                     noarch                     2.31.1-3.oc8                           AppStream                     2.6 M
 perl-Error                       noarch                     1:0.17025-2.oc8                        AppStream                      45 k
 perl-Git                         noarch                     2.31.1-3.oc8                           AppStream                      77 k

Transaction Summary
========================================================================================================================================Install  5 Packages

Total download size: 7.7 M
Installed size: 37 M
Downloading Packages:
(1/5): git-2.31.1-3.oc8.x86_64.rpm                                                                      640 kB/s | 160 kB     00:00    
(2/5): perl-Error-0.17025-2.oc8.noarch.rpm                                                              270 kB/s |  45 kB     00:00    
(3/5): git-core-doc-2.31.1-3.oc8.noarch.rpm                                                             5.3 MB/s | 2.6 MB     00:00    
(4/5): perl-Git-2.31.1-3.oc8.noarch.rpm                                                                 385 kB/s |  77 kB     00:00    
(5/5): git-core-2.31.1-3.oc8.x86_64.rpm                                                                 4.9 MB/s | 4.8 MB     00:00    
----------------------------------------------------------------------------------------------------------------------------------------Total                                                                                                   7.9 MB/s | 7.7 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                1/1 
  Installing       : git-core-2.31.1-3.oc8.x86_64                                                                                   1/5 
  Installing       : git-core-doc-2.31.1-3.oc8.noarch                                                                               2/5 
  Installing       : perl-Error-1:0.17025-2.oc8.noarch                                                                              3/5 
  Installing       : perl-Git-2.31.1-3.oc8.noarch                                                                                   4/5 
  Installing       : git-2.31.1-3.oc8.x86_64                                                                                        5/5 
  Running scriptlet: git-2.31.1-3.oc8.x86_64                                                                                        5/5 
  Verifying        : git-2.31.1-3.oc8.x86_64                                                                                        1/5 
  Verifying        : git-core-2.31.1-3.oc8.x86_64                                                                                   2/5 
  Verifying        : git-core-doc-2.31.1-3.oc8.noarch                                                                               3/5 
  Verifying        : perl-Error-1:0.17025-2.oc8.noarch                                                                              4/5 
  Verifying        : perl-Git-2.31.1-3.oc8.noarch                                                                                   5/5 

Installed:
  git-2.31.1-3.oc8.x86_64        git-core-2.31.1-3.oc8.x86_64   git-core-doc-2.31.1-3.oc8.noarch   perl-Error-1:0.17025-2.oc8.noarch  
  perl-Git-2.31.1-3.oc8.noarch  

Complete!

【2】方式二:安装开发工具集

  • 安装开发工具集。
  • 它会将用于软件开发所需的常见开发工具和库一次性安装到系统中。
yum -y groupinstall "Development tools"
Installed:
  asciidoc-8.6.10-0.5.20180627gitf7c2274.oc8.noarch              boost-atomic-1.66.0-13.oc8.x86_64                                      
  boost-chrono-1.66.0-13.oc8.x86_64                              boost-date-time-1.66.0-13.oc8.x86_64                                   
  boost-filesystem-1.66.0-13.oc8.x86_64                          boost-regex-1.66.0-13.oc8.x86_64                                       
  boost-system-1.66.0-13.oc8.x86_64                              boost-thread-1.66.0-13.oc8.x86_64                                      
  boost-timer-1.66.0-13.oc8.x86_64                               byacc-1.9.20170709-4.oc8.x86_64                                        
  copy-jdk-configs-4.0-2.oc8.noarch                              diffstat-1.61-7.oc8.x86_64                                             
  docbook-style-xsl-1.79.2-9.oc8.noarch                          dyninst-12.1.0-1.oc8.x86_64                                            
  elfutils-debuginfod-client-devel-0.186-1.oc8.x86_64            elfutils-devel-0.186-1.oc8.x86_64                                      
  elfutils-libelf-devel-0.186-1.oc8.x86_64                       intltool-0.51.0-11.oc8.noarch                                          
  java-1.8.0-openjdk-headless-1:1.8.0.352.b08-2.oc8.x86_64       javapackages-filesystem-5.3.0-2.module+oc8.5.0+95+f49e9120.noarch      
  jna-4.5.1-5.oc8.x86_64                                         libzstd-devel-1.4.4-1.oc8.x86_64                                       
  lksctp-tools-1.0.18-3.oc8.x86_64                               mokutil-1:0.3.0-12.oc8.x86_64                                          
  nss-3.79.0-10.oc8_6.x86_64                                     nss-sysinit-3.79.0-10.oc8_6.x86_64                                     
  nss-tools-3.79.0-10.oc8_6.x86_64                               perl-Fedora-VSP-0.001-9.oc8.noarch                                     
  perl-XML-Parser-2.44-11.oc8.x86_64                             perl-generators-1.10-9.oc8.noarch                                      
  pesign-0.112-25.oc8.1.x86_64                                   rpm-sign-4.14.3-24.oc8.x86_64                                          
  source-highlight-3.1.8-17.oc8.x86_64                           systemtap-4.7-1.oc8.x86_64                                             
  systemtap-client-4.7-1.oc8.x86_64                              systemtap-devel-4.7-1.oc8.x86_64                                       
  systemtap-runtime-4.7-1.oc8.x86_64                             tbb-2018.2-9.oc8.x86_64                                                
  tzdata-java-2022g-1.oc8.noarch                                 valgrind-1:3.19.0-1.oc8.x86_64                                         
  valgrind-devel-1:3.19.0-1.oc8.x86_64                          

Complete!

【3】执行下面安装依赖

  • 安装一些Git所需要的依赖库,以确保Git的正常运行。
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel -y
  • openssl-devel:OpenSSL库的开发文件,用于支持HTTPS等安全传输协议。
  • bzip2-devel:bzip2库的开发文件,用于支持Git的数据压缩。
  • expat-devel:expat库的开发文件,用于支持Git对XML解析的需求。
  • gdbm-devel:gdbm库的开发文件,用于支持Git使用GNU数据库管理系统。
  • readline-devel:readline库的开发文件,用于支持Git命令行的编辑和自动补全功能。
  • sqlite-devel:SQLite库的开发文件,用于支持Git使用SQLite数据库。
  • psmisc:一个实用程序库,提供更多的进程查找和控制功能。
  • libffi-devel:libffi库的开发文件,用于支持Git调用其他语言的函数。

【4】验证安装

  • 验证Git是否成功安装
git --version
[root@VM-8-11-opencloudos ~]# git --version
git version 2.31.1

【5】通过以下命令分别设置用户名和邮箱

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

【七】安装mysql

【1】版本

  • MySQL 5.7 是一款稳定且常用的MySQL版本。

【2】前往用户根目录

  • 通过命令cd ~可以进入当前用户的根目录(即主目录),这是为了方便后续的操作和文件下载。
 cd ~

【3】下载mysql57

  • 使用wget命令下载 MySQL 5.7 的安装包。
  • 例如,wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 将会下载名为 mysql57-community-release-el7-10.noarch.rpm 的文件。
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@VM-8-11-opencloudos ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
--2023-08-14 09:57:45--  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 23.37.156.249, 2600:1417:76:681::2e31, 2600:1417:76:68e::2e31
Connecting to dev.mysql.com (dev.mysql.com)|23.37.156.249|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [following]
--2023-08-14 09:57:47--  https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|23.37.156.249|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm [following]
--2023-08-14 09:57:49--  https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 72.247.225.71, 2600:140b:2:593::1d68, 2600:140b:2:58f::1d68
Connecting to repo.mysql.com (repo.mysql.com)|72.247.225.71|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25548 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-10.noarch.rpm’

mysql57-community-release-el7-10. 100%[=============================================================>]  24.95K   160KB/s    in 0.2s    

2023-08-14 09:57:50 (160 KB/s) - ‘mysql57-community-release-el7-10.noarch.rpm’ saved [25548/25548]
wget http://repo.mysql.com/mysql57-community-release-el7.rpm
[root@VM-8-11-opencloudos ~]# wget http://repo.mysql.com/mysql57-community-release-el7.rpm
--2023-08-14 10:40:43--  http://repo.mysql.com/mysql57-community-release-el7.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.76.200.230, 2600:1417:4400:3bd::1d68, 2600:1417:4400:38d::1d68
Connecting to repo.mysql.com (repo.mysql.com)|104.76.200.230|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7.rpm’

mysql57-community-release-el7.rpm 100%[=============================================================>]  25.08K   167KB/s    in 0.2s    

2023-08-14 10:40:43 (167 KB/s) - ‘mysql57-community-release-el7.rpm’ saved [25680/25680]

【4】安装mysql57

  • 使用以下两条命令来安装MySQL 5.7
  • 安装 MySQL 的 Yum 仓库源,
yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@VM-8-11-opencloudos ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
Last metadata expiration check: 1:24:33 ago on Mon 14 Aug 2023 08:33:32 AM CST.
Dependencies resolved.
======================================================================================================================================== Package                                      Architecture              Version                   Repository                       Size
========================================================================================================================================Installing:
 mysql57-community-release                    noarch                    el7-10                    @commandline                     25 k

Transaction Summary
========================================================================================================================================Install  1 Package

Total size: 25 k
Installed size: 30 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                1/1 
  Installing       : mysql57-community-release-el7-10.noarch                                                                        1/1 
  Verifying        : mysql57-community-release-el7-10.noarch                                                                        1/1 

Installed:
  mysql57-community-release-el7-10.noarch                                                                                               

Complete!
  • 通过 yum 包管理器安装 MySQL 社区版服务器。
yum install mysql-community-server --nogpgcheck -y
[root@VM-8-11-opencloudos ~]# yum install mysql-community-server --nogpgcheck -y
OpenCloudOS 8 - BaseOS                                                                                                                                                          4.0 MB/s | 2.8 MB     00:00    
OpenCloudOS 8 - AppStream                                                                                                                                                       2.8 MB/s | 9.0 MB     00:03    
OpenCloudOS 8 - Extras                                                                                                                                                          7.7 kB/s | 1.6 kB     00:00    
OpenCloudOS 8 - Plus                                                                                                                                                             25 kB/s | 5.4 kB     00:00    
Docker CE Stable - x86_64                                                                                                                                                       234 kB/s |  49 kB     00:00    
Extra Packages for OpenCloudOS 8 - x86_64                                                                                                                                       7.1 MB/s |  16 MB     00:02    
Extra Packages for OpenCloudOS 8 Modular - x86_64                                                                                                                               1.2 MB/s | 733 kB     00:00    
MongoDB Repository                                                                                                                                                               34 kB/s |  72 kB     00:02    
MySQL Connectors Community                                                                                                                                                       49 kB/s |  59 kB     00:01    
MySQL Tools Community                                                                                                                                                           345 kB/s | 1.0 MB     00:02    
MySQL 5.7 Community Server                                                                                                                                                      1.2 MB/s | 3.0 MB     00:02    
nginx stable repo                                                                                                                                                                46 kB/s |  53 kB     00:01    
Dependencies resolved.
================================================================================================================================================================================================================ Package                                                 Architecture                            Version                                               Repository                                          Size
================================================================================================================================================================================================================Installing:
 mysql-community-server                                  x86_64                                  5.7.43-1.el7                                          mysql57-community                                  184 M
Installing dependencies:
 mysql-community-client                                  x86_64                                  5.7.43-1.el7                                          mysql57-community                                   31 M
 mysql-community-common                                  x86_64                                  5.7.43-1.el7                                          mysql57-community                                  313 k
 mysql-community-libs                                    x86_64                                  5.7.43-1.el7                                          mysql57-community                                  2.9 M
 ncurses-compat-libs                                     x86_64                                  6.1-9.20180224.oc8                                    BaseOS                                             327 k

Transaction Summary
================================================================================================================================================================================================================Install  5 Packages

Total download size: 219 M
Installed size: 930 M
Downloading Packages:
(1/5): ncurses-compat-libs-6.1-9.20180224.oc8.x86_64.rpm                                                                                                                        1.2 MB/s | 327 kB     00:00    
(2/5): mysql-community-common-5.7.43-1.el7.x86_64.rpm                                                                                                                           177 kB/s | 313 kB     00:01    
(3/5): mysql-community-libs-5.7.43-1.el7.x86_64.rpm                                                                                                                             1.1 MB/s | 2.9 MB     00:02    
(4/5): mysql-community-client-5.7.43-1.el7.x86_64.rpm                                                                                                                           4.2 MB/s |  31 MB     00:07    
(5/5): mysql-community-server-5.7.43-1.el7.x86_64.rpm                                                                                                                           4.7 MB/s | 184 MB     00:39    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total                                                                                                                                                                           5.3 MB/s | 219 MB     00:41     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                        1/1 
  Installing       : mysql-community-common-5.7.43-1.el7.x86_64                                                                                                                                             1/5 
  Installing       : mysql-community-libs-5.7.43-1.el7.x86_64                                                                                                                                               2/5 
  Running scriptlet: mysql-community-libs-5.7.43-1.el7.x86_64                                                                                                                                               2/5 
  Installing       : ncurses-compat-libs-6.1-9.20180224.oc8.x86_64                                                                                                                                          3/5 
  Installing       : mysql-community-client-5.7.43-1.el7.x86_64                                                                                                                                             4/5 
  Running scriptlet: mysql-community-server-5.7.43-1.el7.x86_64                                                                                                                                             5/5 
  Installing       : mysql-community-server-5.7.43-1.el7.x86_64                                                                                                                                             5/5 
  Running scriptlet: mysql-community-server-5.7.43-1.el7.x86_64                                                                                                                                             5/5 
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.
[/usr/lib/tmpfiles.d/pesign.conf:1] Line references path below legacy directory /var/run/, updating /var/run/pesign → /run/pesign; please update the tmpfiles.d/ drop-in file accordingly.

  Verifying        : ncurses-compat-libs-6.1-9.20180224.oc8.x86_64                                                                                                                                          1/5 
  Verifying        : mysql-community-client-5.7.43-1.el7.x86_64                                                                                                                                             2/5 
  Verifying        : mysql-community-common-5.7.43-1.el7.x86_64                                                                                                                                             3/5 
  Verifying        : mysql-community-libs-5.7.43-1.el7.x86_64                                                                                                                                               4/5 
  Verifying        : mysql-community-server-5.7.43-1.el7.x86_64                                                                                                                                             5/5 

Installed:
  mysql-community-client-5.7.43-1.el7.x86_64            mysql-community-common-5.7.43-1.el7.x86_64         mysql-community-libs-5.7.43-1.el7.x86_64         mysql-community-server-5.7.43-1.el7.x86_64        
  ncurses-compat-libs-6.1-9.20180224.oc8.x86_64        

Complete!

如果遇到下述问题

Error: Transaction test error:
  file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/cp1251.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.43-1.el7.x86_64 conflicts with file from package mysql-common-8.0.26-1.module+oc8.5.0+99+fb98af3b.x86_64
  file /etc/my.cnf from install of mysql-community-server-5.7.43-1.el7.x86_64 conflicts with file from package mariadb-connector-c-config-3.1.11-2.oc8.1.noarch
  • 是和原来的MySQL产生了冲突
    • 移除旧版MySQL即可
yum remove mysql-common
yum remove mariadb-connector-c-config

【5】启动mysql57并查看启动状态

  • 使用以下两条命令来启动 MySQL 服务,并查看其运行状态
  • 启动 MySQL 服务
systemctl start mysqld
  • 检查 MySQL 服务的运行状态
systemctl status mysqld
[root@VM-8-11-opencloudos ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-08-14 11:28:01 CST; 4s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 593376 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 593159 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 593378 (mysqld)
    Tasks: 27 (limit: 10792)
   Memory: 306.5M
   CGroup: /system.slice/mysqld.service
           └─593378 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Aug 14 11:27:39 VM-8-11-opencloudos systemd[1]: Starting MySQL Server...
Aug 14 11:28:01 VM-8-11-opencloudos systemd[1]: Started MySQL Server.

【6】查看默认密码并登录

  • MySQL 5.7 默认会生成一个初始密码。通过以下命令查看该密码
grep "password" /var/log/mysqld.log   # U>bjULStm1Q<
mysql -uroot -p
[root@VM-8-11-opencloudos ~]# grep "password" /var/log/mysqld.log
2023-08-14T03:27:54.842552Z 1 [Note] A temporary password is generated for root@localhost: uQL(-9<,nt</
2023-08-14T03:28:43.595832Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
  • 使用以下命令来登录 MySQL
mysql -uroot -p
[root@VM-8-11-opencloudos ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.43

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

【7】修改密码

  • 登录后,可以使用以下命令来修改 root 用户的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'dream1314521?';

【八】安装redis

【1】官方下载编译好的reids

# 下载 
mkdir -p /usr/local/redis 
cd /usr/local/redis 
[root@VM-8-11-opencloudos ~]# mkdir -p /usr/local/redis
[root@VM-8-11-opencloudos ~]# cd /usr/local/redis
[root@VM-8-11-opencloudos redis]# 
  • 这种方法是通过从官方网站下载已经编译好的 Redis 软件包进行安装
https://download.redis.io/releases/  # Redis版本官网
  • 使用 wget 命令下载 Redis 官方软件包
wget https://download.redis.io/releases/redis-6.2.9.tar.gz
[root@VM-8-11-opencloudos ~]# wget https://github.com/redis-stack/redis-stack/releases/tag/v6.2.6-v9
--2023-08-14 09:14:52--  https://github.com/redis-stack/redis-stack/releases/tag/v6.2.6-v9
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... ^C
[root@VM-8-11-opencloudos ~]# mkdir -p /usr/local/redis
[root@VM-8-11-opencloudos ~]# cd /usr/local/redis
[root@VM-8-11-opencloudos redis]# wget https://download.redis.io/releases/redis-6.2.9.tar.gz
--2023-08-14 09:21:51--  https://download.redis.io/releases/redis-6.2.9.tar.gz
Resolving download.redis.io (download.redis.io)... 45.60.125.1
Connecting to download.redis.io (download.redis.io)|45.60.125.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2490785 (2.4M) [application/octet-stream]
Saving to: ‘redis-6.2.9.tar.gz’

redis-6.2.9.tar.gz                100%[=============================================================>]   2.38M   229KB/s    in 5.7s    

2023-08-14 09:21:58 (425 KB/s) - ‘redis-6.2.9.tar.gz’ saved [2490785/2490785]
  • 解压下载的压缩包:
tar -xf redis-6.2.9.tar.gz
[root@VM-8-11-opencloudos redis]# ls
redis-6.2.9.tar.gz
[root@VM-8-11-opencloudos redis]# tar -xf redis-6.2.9.tar.gz
[root@VM-8-11-opencloudos redis]# ls
redis-6.2.9  redis-6.2.9.tar.gz
[root@VM-8-11-opencloudos redis]# 
  • 将解压得到的文件夹重命名为 redis
mv redis-6.2.9 redis
[root@VM-8-11-opencloudos redis]# mv redis-6.2.9 redis
[root@VM-8-11-opencloudos redis]# ls
redis  redis-6.2.9.tar.gz
[root@VM-8-11-opencloudos redis]# 
  • 编译安装Redis
    • 切换到上述改好名字的 redis 文件夹下
make
[root@VM-8-11-opencloudos redis]# make
cd src && make all
make[1]: Entering directory '/usr/local/redis/redis/src'
    CC Makefile.dep
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep
rm -f adlist.d quicklist.d ae.d anet.d dict.d server.d sds.d zmalloc.d lzf_c.d lzf_d.d pqsort.d zipmap.d sha1.d ziplist.d release.d networking.d util.d object.d db.d replication.d rdb.d t_string.d t_list.d t_set.d t_zset.d t_hash.d config.d aof.d pubsub.d multi.d debug.d sort.d intset.d syncio.d cluster.d crc16.d endianconv.d slowlog.d scripting.d bio.d rio.d rand.d memtest.d crcspeed.d crc64.d bitops.d sentinel.d notify.d setproctitle.d blocked.d hyperloglog.d latency.d sparkline.d redis-check-rdb.d redis-check-aof.d geo.d lazyfree.d module.d evict.d expire.d geohash.d geohash_helper.d childinfo.d defrag.d siphash.d rax.d t_stream.d listpack.d localtime.d lolwut.d lolwut5.d lolwut6.d acl.d gopher.d tracking.d connection.d tls.d sha256.d timeout.d setcpuaffinity.d monotonic.d mt19937-64.d anet.d adlist.d dict.d redis-cli.d zmalloc.d release.d ae.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d ae.d anet.d redis-benchmark.d adlist.d dict.d zmalloc.d release.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d
(cd ../deps && make distclean)
make[2]: Entering directory '/usr/local/redis/redis/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(cd hdr_histogram && make clean) > /dev/null || true
...
    CC cli_common.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory '/usr/local/redis/redis/src'
[root@VM-8-11-opencloudos redis]# 
  • 进入 Redis 的 src 目录:
    • 注意当前所在文件目录
      • 我的目录是
        • /usr/local/redis/redis/src
cd src
[root@VM-8-11-opencloudos redis]# ls
00-RELEASENOTES  CONDUCT       COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  src    TLS.md
BUGS             CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  sentinel.conf     tests  utils
[root@VM-8-11-opencloudos redis]# cd src
  • 查看src文件夹下的所有文件
[root@VM-8-11-opencloudos src]# ls
acl.c         config.h           geohash.c          lzf_c.o          rand.d             sdsalloc.h        t_hash.d
acl.d         config.o           geohash.d          lzf_d.c          rand.h             sds.c             t_hash.o
acl.o         connection.c       geohash.h          lzf_d.d          rand.o             sds.d             timeout.c
adlist.c      connection.d       geohash_helper.c   lzf_d.o          rax.c              sds.h             timeout.d
adlist.d      connection.h       geohash_helper.d   lzf.h            rax.d              sds.o             timeout.o
adlist.h      connection.o       geohash_helper.h   lzfP.h           rax.h              sentinel.c        t_list.c
adlist.o      connhelpers.h      geohash_helper.o   Makefile         rax_malloc.h       sentinel.d        t_list.d
ae.c          crc16.c            geohash.o          memtest.c        rax.o              sentinel.o        t_list.o
ae.d          crc16.d            geo.o              memtest.d        rdb.c              server.c          tls.c
ae_epoll.c    crc16.o            gopher.c           memtest.o        rdb.d              server.d          tls.d
ae_evport.c   crc16_slottable.h  gopher.d           mkreleasehdr.sh  rdb.h              server.h          tls.o
ae.h          crc64.c            gopher.o           module.c         rdb.o              server.o          tracking.c
ae_kqueue.c   crc64.d            help.h             module.d         redisassert.h      setcpuaffinity.c  tracking.d
ae.o          crc64.h            hyperloglog.c      module.o         redis-benchmark    setcpuaffinity.d  tracking.o
ae_select.c   crc64.o            hyperloglog.d      modules          redis-benchmark.c  setcpuaffinity.o  t_set.c
anet.c        crcspeed.c         hyperloglog.o      monotonic.c      redis-benchmark.d  setproctitle.c    t_set.d
anet.d        crcspeed.d         intset.c           monotonic.d      redis-benchmark.o  setproctitle.d    t_set.o
anet.h        crcspeed.h         intset.d           monotonic.h      redis-check-aof    setproctitle.o    t_stream.c
anet.o        crcspeed.o         intset.h           monotonic.o      redis-check-aof.c  sha1.c            t_stream.d
aof.c         db.c               intset.o           mt19937-64.c     redis-check-aof.d  sha1.d            t_stream.o
aof.d         db.d               latency.c          mt19937-64.d     redis-check-aof.o  sha1.h            t_string.c
aof.o         db.o               latency.d          mt19937-64.h     redis-check-rdb    sha1.o            t_string.d
asciilogo.h   debug.c            latency.h          mt19937-64.o     redis-check-rdb.c  sha256.c          t_string.o
atomicvar.h   debug.d            latency.o          multi.c          redis-check-rdb.d  sha256.d          t_zset.c
bio.c         debugmacro.h       lazyfree.c         multi.d          redis-check-rdb.o  sha256.h          t_zset.d
bio.d         debug.o            lazyfree.d         multi.o          redis-cli          sha256.o          t_zset.o
bio.h         defrag.c           lazyfree.o         networking.c     redis-cli.c        siphash.c         util.c
bio.o         defrag.d           listpack.c         networking.d     redis-cli.d        siphash.d         util.d
bitops.c      defrag.o           listpack.d         networking.o     redis-cli.o        siphash.o         util.h
bitops.d      dict.c             listpack.h         notify.c         redismodule.h      slowlog.c         util.o
bitops.o      dict.d             listpack_malloc.h  notify.d         redis-sentinel     slowlog.d         valgrind.sup
blocked.c     dict.h             listpack.o         notify.o         redis-server       slowlog.h         version.h
blocked.d     dict.o             localtime.c        object.c         redis-trib.rb      slowlog.o         ziplist.c
blocked.o     endianconv.c       localtime.d        object.d         release.c          solarisfixes.h    ziplist.d
childinfo.c   endianconv.d       localtime.o        object.o         release.d          sort.c            ziplist.h
childinfo.d   endianconv.h       lolwut5.c          pqsort.c         release.h          sort.d            ziplist.o
childinfo.o   endianconv.o       lolwut5.d          pqsort.d         release.o          sort.o            zipmap.c
cli_common.c  evict.c            lolwut5.o          pqsort.h         replication.c      sparkline.c       zipmap.d
cli_common.d  evict.d            lolwut6.c          pqsort.o         replication.d      sparkline.d       zipmap.h
cli_common.h  evict.o            lolwut6.d          pubsub.c         replication.o      sparkline.h       zipmap.o
cli_common.o  expire.c           lolwut6.o          pubsub.d         rio.c              sparkline.o       zmalloc.c
cluster.c     expire.d           lolwut.c           pubsub.o         rio.d              stream.h          zmalloc.d
cluster.d     expire.o           lolwut.d           quicklist.c      rio.h              syncio.c          zmalloc.h
cluster.h     fmacros.h          lolwut.h           quicklist.d      rio.o              syncio.d          zmalloc.o
cluster.o     geo.c              lolwut.o           quicklist.h      scripting.c        syncio.o
config.c      geo.d              lzf_c.c            quicklist.o      scripting.d        testhelp.h
config.d      geo.h              lzf_c.d            rand.c           scripting.o        t_hash.c
[root@VM-8-11-opencloudos src]# 
  • 启动 Redis,默认使用默认配置启动:
./redis-server   # 启动redis,使用默认配置启动的
  • 删除 Redis 安装包
rm -rf redis-6.2.9.tar.gz

【2】在任意路径下敲redis-server都能把服务运行

方式一:

  • 将 Redis 的 bin 路径添加到环境变量中,这样无论在哪个路径都可以执行 redis-server

方式二:使用软连接

  • /usr/bin/ 目录下创建软连接,这样无论在哪个路径都可以找到 redis-serverredis-cli
ln -s /usr/local/redis/redis/src/redis-server /usr/bin/redis-server
ln -s /usr/local/redis/redis/src/redis-cli /usr/bin/redis-cli

【3】查看是否创建软连接成功

ls |grep redis
[root@VM-8-11-opencloudos src]# ls |grep redis
redisassert.h
redis-benchmark
redis-benchmark.c
redis-benchmark.d
redis-benchmark.o
redis-check-aof
redis-check-aof.c
redis-check-aof.d
redis-check-aof.o
redis-check-rdb
redis-check-rdb.c
redis-check-rdb.d
redis-check-rdb.o
redis-cli
redis-cli.c
redis-cli.d
redis-cli.o
redismodule.h
redis-sentinel
redis-server
redis-trib.rb

【4】启动redis服务,后台运行

redis-server &

【5】源码安装

(1)下载redis-6.2.6

  • 使用 wget 命令下载 Redis 源码包:
wget http://download.redis.io/releases/redis-6.2.6.tar.gz

(2)解压安装包

tar -xf redis-6.2.6.tar.gz

(3)进入解压得到的目录

cd redis-6.2.6

(4)编译环境 gcc

  • src 路径下编译源码,生成 redis-cliredis-server 可执行文件:
make  

(5)复制环境到指定路径完成安装

  • 将编译生成的可执行文件复制到指定路径完成安装,例如复制到 /usr/local/redis 目录下:
cp -r ~/redis-6.2.6 /usr/local/redis

(6)配置redis可以后台启动:修改下方内容

  • 修改 Redis 配置文件,使其支持后台启动。
  • 使用编辑器打开 /usr/local/redis/redis.conf 文件:
vim /usr/local/redis/redis.conf
  • 并将以下内容修改为
daemonize yes

(7)保存并退出编辑器

esc
:wq

(8)建立软连接

  • 创建软连接,将 redis-serverredis-cli 链接到 /usr/bin/ 目录下,以便在任意路径下都能运行:
ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server1
ln -s /usr/local/redis/src/redis-cli /usr/bin/redis-cli1

(9)后台运行redis

  • 后台运行 Redis 服务,指定配置文件路径:
cd /usr/local/redis
redis-server1 ./redis.conf

(9)测试redis环境

  • 使用以下命令测试 Redis 环境是否正常:
redis-cli

(10)关闭redis服务

  • 如果需要关闭 Redis 服务,可以使用以下命令之一:
pkill -f redis -9
redis-cli  shutdown

【九】安装python

  • 可以使用yum 安装,不能指定版本

  • 源码安装,下载指定版本的源码,编译安装

  • 所有linxu和mac,都自带python2:系统服务,是用python写的

  • 阿里云的centos默认装了python3.6.8

【1】源码安装python

  • 源码安装Python需要先准备一些第三方依赖库,可以使用yum命令来安装,如
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel -y

【2】前往用户根目录

  • 进入用户根目录,可以通过以下命令切换到用户根目录
cd ~

【3】下载 或 上传 Python3.8.6 服务器终端

  • 下载或上传指定版本的Python源码包,可以通过wget命令进行下载,例如
wget https://registry.npmmirror.com/-/binary/python/3.9.10/Python-3.9.10.tgz
  • 也可以前往其他可信赖的镜像源或Python官网下载源码包
https://registry.npmmirror.com/binary.html?path=python/
wget https://registry.npmmirror.com/-/binary/python/3.8.6/Python-3.8.6.tgz
wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz
[root@VM-8-11-opencloudos ~]# wget https://registry.npmmirror.com/-/binary/python/3.9.10/Python-3.9.10.tgz
--2023-08-14 08:56:41--  https://registry.npmmirror.com/-/binary/python/3.9.10/Python-3.9.10.tgz
Resolving registry.npmmirror.com (registry.npmmirror.com)... 124.236.110.234, 240e:b1:9801:409:3::3e1
Connecting to registry.npmmirror.com (registry.npmmirror.com)|124.236.110.234|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.npmmirror.com/binaries/python/3.9.10/Python-3.9.10.tgz [following]
--2023-08-14 08:56:41--  https://cdn.npmmirror.com/binaries/python/3.9.10/Python-3.9.10.tgz
Resolving cdn.npmmirror.com (cdn.npmmirror.com)... 220.181.158.229, 220.181.158.232, 220.181.158.230, ...
Connecting to cdn.npmmirror.com (cdn.npmmirror.com)|220.181.158.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25800844 (25M) [application/octet-stream]
Saving to: ‘Python-3.9.10.tgz’

Python-3.9.10.tgz                 100%[=============================================================>]  24.61M  23.1MB/s    in 1.1s    

2023-08-14 08:56:42 (23.1 MB/s) - ‘Python-3.9.10.tgz’ saved [25800844/25800844]

【4】解压安装包

  • 解压下载的Python源码包,可以使用tar命令,如
tar -xf Python-3.9.10.tgz 
无变化

【5】进入目标文件

  • 进入解压后的Python源码目录,使用cd命令进入,例如
cd Python-3.9.10
[root@VM-8-11-opencloudos ~]# cd Python-3.9.10
[root@VM-8-11-opencloudos Python-3.9.10]# 

【6】 配置安装路径

  • 配置Python的安装路径,可以使用configure命令来指定安装路径,例如

  • /usr/local/python3

    • 把python3.9.10 编译安装到/usr/local/python38路径下
./configure --prefix=/usr/local/python39
[root@VM-8-11-opencloudos Python-3.9.10]# ./configure --prefix=/usr/local/python39
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.9... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
...
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup.local
creating Makefile


If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations

【7】编译并安装,如果报错,说明缺依赖

  • 执行make和make install命令进行编译和安装操作
    • 当前目录下就可以
make &&  make install
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.9... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
...
fi
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /usr/local/python39/include/python3.9/UNKNOWN
sysconfig: /root/Python-3.9.10/Include/UNKNOWN
WARNING: Additional context:
user = False
home = None
root = '/'
prefix = None
Looking in links: /tmp/tmpv5oct4m_
Processing /tmp/tmpv5oct4m_/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmpv5oct4m_/pip-21.2.4-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /usr/local/python39/include/python3.9/setuptools
  sysconfig: /root/Python-3.9.10/Include/setuptools
  WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /usr/local/python39/include/python3.9/pip
  sysconfig: /root/Python-3.9.10/Include/pip
  WARNING: The scripts pip3 and pip3.9 are installed in '/usr/local/python39/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.2.4 setuptools-58.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  • 这个警告是由于在以root用户身份运行pip命令导致的,并且在系统中安装的Python库的路径与系统包管理器的预期路径不匹配。
    • 这可能会导致权限问题和与系统包管理器的冲突。
  • 解决这个问题的推荐方法是创建一个虚拟环境并切换到该环境中来执行Python以及相关的pip命令。
    • 虚拟环境可以隔离不同项目的依赖,避免对全局Python环境进行修改。
  • 这些命令将会根据之前的配置对Python源码进行编译和安装,如果报错提示缺少依赖,则需要先安装相应的依赖库
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel  -y

【8】建立软连接

  • /usr/local/python38路径不在环境变量,终端命令
    • python3,pip3
ln -s /usr/local/python39/bin/python3 /usr/bin/python3.9
ln -s /usr/local/python39/bin/pip3 /usr/bin/pip3.9
[root@VM-8-11-opencloudos Python-3.9.10]# ln -s /usr/local/python39/bin/python3 /usr/bin/python3.9
[root@VM-8-11-opencloudos Python-3.9.10]# ln -s /usr/local/python39/bin/pip3 /usr/bin/pip3.9
  • 机器上有多个python和pip命令,对应关系如下
python       2.x      pip 
python3      3.6      pip3
python3.9    3.9      pip3.9

【9】删除安装包与文件

  • 最后,删除安装包和解压后的源码文件,可以使用rm命令进行删除
rm -rf Python-3.9.10
rm -rf Python-3.9.10.tar.xz

【10】验证安装

python3.9 -V
[root@VM-8-11-opencloudos Python-3.9.10]# python3.9 -V
Python 3.9.10

【11】查看并切换清华镜像源

(1)查看当前镜像源

  • 首先,通过以下命令查看当前pip的镜像源:
    • 该命令会返回当前pip的镜像源URL。
pip3.9 config get global.index-url
[root@VM-8-11-opencloudos ~]# pip3.9 config get global.index-url
https://pypi.tuna.tsinghua.edu.cn/simple

(2)命令更换镜像源

  • 如果返回的URL不是清华镜像源,可以使用以下命令来临时更换为清华镜像源:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  • 再次运行第一步中的命令验证镜像源是否已更改为清华镜像源

(3)永久更换镜像源

  • 要实现永久更换为清华镜像源,您需要编辑pip的配置文件。
    • 通常情况下,配置文件位于用户的主目录下的.pip目录中,文件名为pip.confpip.ini(如果不存在,则可以自行创建该文件)。
  • 使用文本编辑器打开配置文件,并添加以下内容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

index-url的值设置为清华镜像源的URL。

(4)保存并关闭配置文件验证。

再次运行以下命令来验证pip的镜像源是否已成功更改为清华镜像源:

pip config get global.index-url

【十】配置Python虚拟环境

【1】安装虚拟环境管理工具virtualenv

$ pip3.9 install virtualenv # 选装
$ pip3.9 install virtualenvwrapper # 必装

【2】建立软连接

$ ln -s /usr/local/python39/bin/virtualenv /usr/bin/virtualenv # 选装
$ ln -s /usr/local/python39/bin/virtualenvwrapper /usr/bin/virtualenvwrapper # 必装

【3】修改配置文件

  • ~/ 表示用户家路径:root用户,就是在/root/.bash_profile
    • 通过ls -al查看全部隐藏文件
[root@VM-8-11-opencloudos ~]# ls -al
total 21240
dr-xr-x---  7 root root     4096 Aug 14 11:46 .
dr-xr-xr-x 23 root root     4096 Aug 14 11:53 ..
-rw-r--r--  1 root root    14236 Aug 14 11:50 .bash_history
-rw-r--r--  1 root root       18 May 11  2019 .bash_logout
-rw-r--r--  1 root root      176 May 11  2019 .bash_profile
-rw-r--r--  1 root root      234 Aug  8 17:14 .bashrc
drwxr-xr-x  4 root root     4096 Aug  1 13:51 .cache
drwx------  3 root root     4096 Jul 20 10:56 .config
-rw-r--r--  1 root root      100 May 11  2019 .cshrc
-rw-------  1 root root      122 Aug  1 14:07 .dbshell
-rw-------  1 root root        0 Aug  1 13:45 .mongorc.js
-rw-------  1 root root       18 Aug 14 11:32 .mysql_history
-rw-r--r--  1 root root 21651746 Jan 27  2022 node
drwxr-xr-x  4 root root     4096 Aug  1 14:08 .npm
drwxr-xr-x  2 root root     4096 Jun 28 10:25 .pip
-rw-r--r--  1 root root       73 Jun 28 10:25 .pydistutils.cfg
-rw-------  1 root root       46 Aug 14 11:46 .python_history
-rw-------  1 root root       17 Aug 14 11:38 .rediscli_history
drwx------  2 root root     4096 Jun 28 10:24 .ssh
-rw-r--r--  1 root root      129 May 11  2019 .tcshrc
-rw-------  1 root root     1531 Aug  1 14:46 .viminfo
-rw-r--r--  1 root root      517 Aug 14 11:14 .wget-hsts
  • 修改配置文件
 vi .bash_profile
  • 输入 a 编辑文件内容
    • 上下移动可控制位置

  • 粘贴下面内容
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.9
source /usr/local/python39/bin/virtualenvwrapper.sh

  • 输入完成按ESC推到当前页面,可以看到 INSERT 消失

  • 输入 :wq 回车,退出当前文件

    • :wq :退出并保存当前文件修改
  • 更新配置文件内容

source .bash_profile
[root@VM-8-11-opencloudos ~]# source .bash_profile
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/get_env_details
[root@VM-8-11-opencloudos ~]# 
  • 虚拟环境默认根目录:
/root/.virtualenvs

【4】在合适的位置创建一个新的文件夹作为你的项目根目录

  • 例如myproject
$ mkdir myproject
$ cd myproject

【5】创建一个虚拟环境:

$ mkvirtualenv -p python3.9 luffy
[root@VM-8-11-opencloudos ~]# mkvirtualenv -p python3.9 luffy
created virtual environment CPython3.9.10.final.0-64 in 2115ms
  creator CPython3Posix(dest=/root/.virtualenvs/luffy, 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.2.1, setuptools==68.0.0, wheel==0.41.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
virtualenvwrapper.user_scripts creating /root/.virtualenvs/luffy/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/luffy/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/luffy/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/luffy/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/luffy/bin/get_env_details
(luffy) [root@VM-8-11-opencloudos ~]# 
  • 你会注意到,激活虚拟环境后,命令行提示符前面的(venv)标识表示你已经处于虚拟环境中。
  • 在虚拟环境中进行Python和pip相关的操作,无需使用root权限即可完成安装等任务。
  • 通过使用虚拟环境,你可以避免错误的权限和依赖关系问题,并且能够更好地管理你的项目。
  • 退出虚拟环境
    • deactivate
(luffy) [root@VM-8-11-opencloudos ~]# deactivate
[root@VM-8-11-opencloudos ~]# 

【6】操作查看虚拟环境:

(1)退出虚拟环境(deactivate)

(luffy) [root@VM-8-11-opencloudos ~]# deactivate
[root@VM-8-11-opencloudos ~]# 

(2)查看虚拟环境(workon)

[root@VM-8-11-opencloudos ~]# workon
luffy

(3)使用虚拟环境(workon 虚拟环境名)

[root@VM-8-11-opencloudos ~]# workon luffy
(luffy) [root@VM-8-11-opencloudos ~]# 

【十一】安装uwsgi

【1】详解uwsgi

  • django 项目上线需要使用uwsgi这个web服务器运行django项目,安装这个web服务器

  • 使用uwsgi运行django,不再使用测试阶段的wsgiref来运行django了

  • uwsgi是符合wsgi协议的web服务器,使用c写的性能高,上线要使用uwsgi

  • uwsgi是一个符合WSGI(Web Server Gateway Interface)协议的Web服务器,它使用C语言编写并以其高性能而闻名。
  • 在将Django项目部署到生产环境时,通常会选择使用uwsgi服务器来提供更好的性能和稳定性。

【2】安装

1)在真实环境下安装

pip3.9 install uwsgi
[root@VM-8-11-opencloudos ~]# pip3.9 install uwsgi
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting uwsgi
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a7/4e/c4d5559b3504bb65175a759392b03cac04b8771e9a9b14811adf1151f02f/uwsgi-2.0.22.tar.gz (809 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 809.7/809.7 kB 33.1 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: uwsgi
  Building wheel for uwsgi (pyproject.toml) ... done
  Created wheel for uwsgi: filename=uWSGI-2.0.22-cp39-cp39-linux_x86_64.whl size=7301937 sha256=4329dcfc0c7075009be75409ec5df52036fc11c32a8ad76be70b2390e1eae1e3
  Stored in directory: /root/.cache/pip/wheels/ef/d2/ea/d50e14a383127be4a36a1496759a44f307050c9aa2f4b4d2bb
Successfully built uwsgi
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.22
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

2)建立软连接

ln -s /usr/local/python39/bin/uwsgi /usr/bin/uwsgi

【十二】安装NGINX

【1】详解NGINX

  • 反向代理服务器

    • 做请求转发

    • 静态资源代理

    • 负载均衡

  • NGINX是一个开源的高性能的HTTP和反向代理服务器,同时也可以充当邮件(IMAP/POP3)代理服务器。

  • 它采用事件驱动的架构和轻量级的进程模型,能够高效地处理大量并发连接。

  • 以下是关于NGINX的详细说明:

    • HTTP服务器:

      • NGINX作为HTTP服务器,能够处理HTTP请求和响应。

      • 它支持静态文件的服务、虚拟主机、反向代理、负载均衡和缓存等功能。

      • 静态文件的服务允许将静态文件直接提供给客户端,从而加快网站的访问速度。

      • 虚拟主机使得多个域名可以使用同一个物理服务器进行托管。

      • 反向代理和负载均衡分别用于转发请求到后端的多个服务器和均衡负载,提高系统的可用性和性能。

      • 缓存能够缓存静态和动态内容,减少对后端服务器的访问压力。

    • 反向代理服务器:

      • NGINX可以作为反向代理服务器,将客户端的请求转发给后端的多个应用服务器。

      • 反向代理隐藏了真实的应用服务器,可以提供负载均衡、故障转移和安全性等功能。

      • 通过负载均衡,NGINX可以将请求分发给多个应用服务器,从而提高应用的整体性能和可用性。

      • 当应用服务器出现故障时,NGINX可以自动将请求转发到其他正常运行的服务器上,确保服务的连续性。

      • 此外,NGINX还可以进行安全策略的制定,比如限制访问速率、防止DDoS攻击等。

    • 邮件代理服务器:

      • 除了作为HTTP服务器和反向代理服务器外,NGINX还可以作为邮件代理服务器,支持IMAP和POP3协议。

      • NGINX可以处理邮件客户端的认证、SMTP代理和反垃圾邮件功能。

      • 这使得NGINX能够有效地协助处理邮件流量,提高系统的可用性和安全性。

    • 性能和伸缩性:

      • NGINX采用事件驱动的模式,使用异步非阻塞的I/O操作,相比于传统的多线程或多进程模型具有更高的性能和更低的资源消耗。

      • 此外,NGINX还支持内置的负载均衡机制,可根据实际情况自动分配客户端请求到多个后端服务器,实现水平扩展。

    • 功能丰富和灵活性:

      • 除了提供基本的HTTP和反向代理功能以外,NGINX还支持URL重写、SSL/TLS加密、gzip压缩、HTTP2和WebSocket等高级功能。
      • 这些功能可以根据实际需要进行配置,提供更加丰富和灵活的应用场景。
  • 总结:NGINX是一个高性能的HTTP和反向代理服务器,具有强大的性能、丰富的功能和灵活性。

    • 它适用于各种规模的网站和应用环境,并能够提供可靠的服务和高效的负载均衡机制。

【2】安装

(1)前往用户根目录

cd ~

(2)下载nginx1.19.2

wget http://nginx.org/download/nginx-1.19.2.tar.gz
[root@VM-8-11-opencloudos ~]# wget http://nginx.org/download/nginx-1.19.2.tar.gz
--2023-08-14 14:42:40--  http://nginx.org/download/nginx-1.19.2.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1048727 (1.0M) [application/octet-stream]
Saving to: ‘nginx-1.19.2.tar.gz’

nginx-1.19.2.tar.gz    100%[============================>]   1.00M  12.8KB/s    in 61s     

2023-08-14 14:43:42 (16.7 KB/s) - ‘nginx-1.19.2.tar.gz’ saved [1048727/1048727]

(3)解压安装包

tar -xf nginx-1.19.2.tar.gz
[root@VM-8-11-opencloudos ~]# tar -xf nginx-1.19.2.tar.gz
[root@VM-8-11-opencloudos ~]# ls
nginx-1.19.2  nginx-1.19.2.tar.gz

(4)进入目标文件

cd nginx-1.19.2
[root@VM-8-11-opencloudos ~]# cd nginx-1.19.2
[root@VM-8-11-opencloudos nginx-1.19.2]# 

(5)配置安装路径

/usr/local/nginx

./configure --prefix=/usr/local/nginx
[root@VM-8-11-opencloudos nginx-1.19.2]# ./configure --prefix=/usr/local/nginx
checking for OS
 + Linux 5.4.119-20.0009.21.spr x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 8.5.0 20210514 (Red Hat 8.5.0-16) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
...
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

(6)编译并安装

make &&  make install
[root@VM-8-11-opencloudos nginx-1.19.2]# make &&  make install
make -f objs/Makefile
make[1]: Entering directory '/root/nginx-1.19.2'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/src/core/nginx.o \
        src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
...
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
        || cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
        '/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
        || cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
        '/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
        || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
        || cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory '/root/nginx-1.19.2'

(7)建立软连接

  • 终端命令 nginx
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
  • 删除软连接命令
rm /usr/bin/nginx

(8)删除安装包与文件

cd ~
rm -rf nginx-1.19.2
rm -rf nginx-1.19.2.tar.gz
[root@VM-8-11-opencloudos ~]#  rm -rf nginx-1.19.2
[root@VM-8-11-opencloudos ~]#  rm -rf nginx-1.19.2.tar.gz
[root@VM-8-11-opencloudos ~]# ls

(9)测试Nginx环境

  • 服务器运行nginx,本地访问服务器ip
nginx
  • 启动nginx服务,监听80端口----》公网ip 80 端口就能看到页面了
  • 服务器绑定的域名 或 ip:80

(10)静态文件放的路径

/usr/local/nginx/html

(11)查看进程

ps aux | grep nginx
[root@VM-8-11-opencloudos ~]# ps aux | grep nginx
root        3768  0.0  0.0   9672    12 ?        Ss   12:19   0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
root        3769  0.0  0.0  10128   500 ?        S    12:19   0:00 nginx: worker process
root        3770  0.0  0.0  10132   424 ?        S    12:19   0:00 nginx: worker process
root       93456  0.0  0.0  20676   404 ?        Ss   14:51   0:00 nginx: master process nginx
nobody     93457  0.0  0.2  42012  4064 ?        S    14:51   0:00 nginx: worker process
root       93506  0.0  0.0 221940  1204 pts/0    S+   14:51   0:00 grep --color=auto nginx
[root@VM-8-11-opencloudos ~]# 

【十三】部署前端

【1】本地文件打包

  • 在项目目录下执行编译命令
npm run build 

  • dist 文件 打包成 dist.zip ,在本地
    • 上传到远程服务器

【2】在远程服务器上装环境

yum install lrzsz -y   # 跟本地机器上传下载的软件
yum install unzip -y    #解压zip软件
[root@VM-8-11-opencloudos ~]# yum install lrzsz -y
Last metadata expiration check: 2:17:12 ago on Mon 14 Aug 2023 12:39:21 PM CST.
Package lrzsz-0.12.20-43.oc8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@VM-8-11-opencloudos ~]# yum install unzip -y
Last metadata expiration check: 2:17:18 ago on Mon 14 Aug 2023 12:39:21 PM CST.
Package unzip-6.0-46.oc8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

【3】本地文件上传服务器

  • 在远程服务器上
    • 打开你本地的目录,选中dist.zip 上传到远端
rz 
[root@VM-8-11-opencloudos ~]# rz
 ZMODEM  Session started            
------------------------            
 Sent  dist.zip               00023be50
[root@VM-8-11-opencloudos ~]# ls
dist.zip
  • 解压
unzip dist.zip
[root@VM-8-11-opencloudos ~]# unzip dist.zip
Archive:  dist.zip
   creating: dist/
   creating: dist/css/
  inflating: dist/css/app.7b483c54.css  
  inflating: dist/css/chunk-vendors.ab49d789.css  
  inflating: dist/favicon.ico        
   creating: dist/fonts/
  inflating: dist/fonts/element-icons.f1a45d74.ttf  
  inflating: dist/fonts/element-icons.ff18efd1.woff  
   creating: dist/img/
  inflating: dist/img/avatar1.edfb9281.svg  
  inflating: dist/img/chapter-player.0de44515.svg  
  inflating: dist/img/course-cover.17ce462b.jpeg  
  inflating: dist/img/enum.0dc6e214.svg  
  inflating: dist/img/head-logo.f551bd1a.svg  
  inflating: dist/img/play-icon-gray.26b2d28c.svg  
  inflating: dist/img/play-icon-yellow.68296cab.svg  
  inflating: dist/index.html         
   creating: dist/js/
  inflating: dist/js/app.2d353910.js  
  inflating: dist/js/app.2d353910.js.map  
  inflating: dist/js/chunk-vendors.64952be4.js  
  inflating: dist/js/chunk-vendors.64952be4.js.map  
[root@VM-8-11-opencloudos ~]# ls
dist  dist.zip

【4】移动文件

  • /home/html 下面有咱们的前端静态文件
    • /root/dist前端文件夹
    • /home/html服务器存储文件夹
mv /root/dist /home/html
[root@VM-8-11-opencloudos ~]# mv /root/dist /home/html
[root@VM-8-11-opencloudos ~]# ls
dist.zip
[root@VM-8-11-opencloudos ~]# cd /home/html
[root@VM-8-11-opencloudos html]# ls
css  favicon.ico  fonts  img  index.html  js

【5】配置nginx 静态代理

cd  /usr/local/nginx/conf   # nginx.conf   配置文件
[root@VM-8-11-opencloudos html]# cd  /usr/local/nginx/conf
[root@VM-8-11-opencloudos conf]# ls
fastcgi.conf            koi-utf             nginx.conf           uwsgi_params
fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
fastcgi_params          mime.types          scgi_params          win-utf
fastcgi_params.default  mime.types.default  scgi_params.default
mv nginx.conf nginx.conf.bak # 将原来的配置文件备份一份
[root@VM-8-11-opencloudos conf]# mv nginx.conf nginx.conf.bak
[root@VM-8-11-opencloudos conf]# ls
fastcgi.conf            koi-utf             nginx.conf.bak       uwsgi_params
fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
fastcgi_params          mime.types          scgi_params          win-utf
fastcgi_params.default  mime.types.default  scgi_params.default
vi nginx.conf # 自己创一个配置文件
  • 按 a 粘贴下面代码
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    server {
        listen 80;
        server_name  127.0.0.1;
        charset utf-8;
        location / {
            root /home/html;
            index index.html;
            try_files $uri $uri/ /index.html;
        }
    }
} 
  • esc
    • :wq 回车

【6】重启nginx

nginx -s reload

【十四】部署后端

【1】本地

(1)prod.py 配置文件配好

# -*-coding: Utf-8 -*-
# @File : prod .py
# author: Chimengmeng
# blog_url : https://www.cnblogs.com/dream-ze/
# Time:2023/8/7
# 关闭测试环境
DEBUG = False
ALLOWED_HOSTS = [
    '43.138.48.158'  # 公网ip地址
]

CORS_ORIGIN_ALLOW_ALL = True  # 允许所有跨域

# 静态文件配置:上线后还有额外配置,见下方 后台样式问题
STATIC_URL = '/static/'

# 后台http根路径
# BASE_URL = 'http://127.0.0.1:8000'
BASE_URL = 'http://43.138.48.158:8000'
# 前台http根路径
# LUFFY_URL = 'http://127.0.0.1:8080'
LUFFY_URL = 'http://43.138.48.158:80'
# 订单支付成功的后台异步回调接口
NOTIFY_URL = BASE_URL + '/order/success/'
# 订单支付成功的前台同步回调接口
RETURN_URL = LUFFY_URL + '/order/pay/success/'

REST_FRAMEWORK = {
    # 渲染模块
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        # 'rest_framework.renderers.BrowsableAPIRenderer',
    ],
    # ...
}

(2)修改项目中wsgi.py,asgi.py

  • 用uwsgi运行wsgi.py
    • wsgi.py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'luffyCity.settings.prod')
  • asgi.py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'luffyCity.settings.prod')

(3)导出项目依赖

pip3 freeze > requirements.txt

(4)推到远端(Git)

git add .
git commit -m "上线"
git push origin master
  • 确认已经推上去了

【2】远程服务器

(1)拉取项目,安装模块

[1]创建文件夹存储后端项目文件

mkdir /home/project
cd  /home/project
[root@VM-8-11-opencloudos conf]# mkdir /home/project
[root@VM-8-11-opencloudos conf]# cd /home/project
[root@VM-8-11-opencloudos project]# 

[2]克隆项目服务器

git clone https://gitee.com/chi-meng/luffy-project-api.git
  • 如果提示输入用户名和密码就输入用户名和密码
[root@VM-8-11-opencloudos project]# git clone https://gitee.com/chi-meng/luffy-project-api.git
Cloning into 'luffy-project-api'...
Username for 'https://gitee.com': 你的邮箱
Password for 'https://你的邮箱@gitee.com': 
remote: Enumerating objects: 162, done.
remote: Counting objects: 100% (162/162), done.
remote: Compressing objects: 100% (136/136), done.
remote: Total 162 (delta 26), reused 120 (delta 17), pack-reused 0
Receiving objects: 100% (162/162), 9.02 MiB | 4.33 MiB/s, done.
Resolving deltas: 100% (26/26), done.
[root@VM-8-11-opencloudos project]# 

[3]进入到虚拟环境

  • 注意这里是项目文件夹下进入
workon luffy 
[root@VM-8-11-opencloudos project]# workon luffy
(luffy) [root@VM-8-11-opencloudos project]# ls
luffy-project-api
(luffy) [root@VM-8-11-opencloudos project]# cd luffy-project-api
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# 

[4]安装依赖

pip install -r requirements.txt   
  • 可能会出错 mysqlclient装不上,先注释,装上能装上的,再单独装mysqlclient
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# vi requirements.txt
  • mysqlclient前面加 # 注释

  • 再次安装依赖

pip install -r requirements.txt   
Successfully installed Django-3.2.12 Pillow-10.0.0 PyJWT-1.7.1 amqp-5.1.1 asgiref-3.7.2 async-timeout-4.0.2 billiard-4.1.0 boto3-1.28.25 botocore-1.31.25 celery-5.3.1 certifi-2023.7.22 cffi-1.15.1 charset-normalizer-3.2.0 click-8.1.6 click-didyoumean-0.3.0 click-plugins-1.1.1 click-repl-0.3.0 colorama-0.4.6 cryptography-41.0.3 django-cors-headers-4.2.0 django-filter-23.2 django-redis-5.3.0 django-simpleui-2023.3.1 djangorestframework-3.14.0 djangorestframework-jwt-1.11.0 dnspython-2.4.2 eventlet-0.33.3 greenlet-2.0.2 idna-3.4 jmespath-1.0.1 kombu-5.3.1 minio-7.1.15 prompt-toolkit-3.0.39 pyOpenSSL-23.2.0 pycparser-2.21 pycryptodomex-3.18.0 python-alipay-sdk-3.3.0 python-dateutil-2.8.2 pytz-2023.3 redis-4.6.0 requests-2.31.0 s3transfer-0.6.1 six-1.16.0 sqlparse-0.4.4 tencentcloud-sdk-python-3.0.953 typing_extensions-4.7.1 tzdata-2023.3 urllib3-1.26.16 vine-5.0.0 wcwidth-0.2.6

[5]mysqlclient解决办法

  • 安装python3-devel
yum install python3-devel -y
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# yum install python3-devel -y
Last metadata expiration check: 3:12:44 ago on Mon 14 Aug 2023 12:39:21 PM CST.
Dependencies resolved.
============================================================================================ Package                  Arch     Version                                Repository   Size
============================================================================================Installing:
 python36-devel           x86_64   3.6.8-38.module+oc8.5.0+78+17d9dd4c    AppStream    15 k
Installing dependencies:
 platform-python-devel    x86_64   3.6.8-48.oc8                           AppStream   249 k
 python3-rpm-generators   noarch   5-7.oc8                                AppStream    24 k

Transaction Summary
============================================================================================Install  3 Packages

Total download size: 288 k
Installed size: 767 k
Downloading Packages:
(1/3): python3-rpm-generators-5-7.oc8.noarch.rpm            171 kB/s |  24 kB     00:00    
(2/3): python36-devel-3.6.8-38.module+oc8.5.0+78+17d9dd4c.x 107 kB/s |  15 kB     00:00    
(3/3): platform-python-devel-3.6.8-48.oc8.x86_64.rpm        622 kB/s | 249 kB     00:00    
--------------------------------------------------------------------------------------------Total                                                       716 kB/s | 288 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                    1/1 
  Installing       : python3-rpm-generators-5-7.oc8.noarch                              1/3 
  Installing       : platform-python-devel-3.6.8-48.oc8.x86_64                          2/3 
  Installing       : python36-devel-3.6.8-38.module+oc8.5.0+78+17d9dd4c.x86_64          3/3 
  Running scriptlet: python36-devel-3.6.8-38.module+oc8.5.0+78+17d9dd4c.x86_64          3/3 
  Verifying        : platform-python-devel-3.6.8-48.oc8.x86_64                          1/3 
  Verifying        : python3-rpm-generators-5-7.oc8.noarch                              2/3 
  Verifying        : python36-devel-3.6.8-38.module+oc8.5.0+78+17d9dd4c.x86_64          3/3 

Installed:
  platform-python-devel-3.6.8-48.oc8.x86_64                                                 
  python3-rpm-generators-5-7.oc8.noarch                                                     
  python36-devel-3.6.8-38.module+oc8.5.0+78+17d9dd4c.x86_64                                 

Complete!
  • 安装mysql-devel
    • --nogpgcheck : 跳过秘钥认证
yum install mysql-devel --nogpgcheck -y
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# yum install mysql-devel --nogpgcheck -y
Last metadata expiration check: 3:13:19 ago on Mon 14 Aug 2023 12:39:21 PM CST.
Dependencies resolved.
============================================================================================ Package                     Architecture Version             Repository               Size
============================================================================================Installing:
 mysql-community-devel       x86_64       5.7.43-1.el7        mysql57-community       4.7 M

Transaction Summary
============================================================================================Install  1 Package

Total download size: 4.7 M
Installed size: 28 M
Downloading Packages:
mysql-community-devel-5.7.43-1.el7.x86_64.rpm               1.1 MB/s | 4.7 MB     00:04    
--------------------------------------------------------------------------------------------Total                                                       1.1 MB/s | 4.7 MB     00:04     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                    1/1 
  Installing       : mysql-community-devel-5.7.43-1.el7.x86_64                          1/1 
  Running scriptlet: mysql-community-devel-5.7.43-1.el7.x86_64                          1/1 
  Verifying        : mysql-community-devel-5.7.43-1.el7.x86_64                          1/1 

Installed:
  mysql-community-devel-5.7.43-1.el7.x86_64                                                 

Complete!
  • 安装mysqlclient
pip install mysqlclient
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# pip install mysqlclient
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting mysqlclient
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/de/9c/b176826e8994551ce826404dab97e305a4bb76c8b0a4e016fabda2901c71/mysqlclient-2.2.0.tar.gz (89 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (pyproject.toml) ... done
  Created wheel for mysqlclient: filename=mysqlclient-2.2.0-cp39-cp39-linux_x86_64.whl size=130339 sha256=2aa20cf76ed72efb44d4c519ff89c4e00d8e6488ce5778bb56585cca5684da73
  Stored in directory: /root/.cache/pip/wheels/84/f3/d4/1bb2c65ed62566511f03fc47cc59bbc407d746bc550e025db7
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.2.0

(2)虚拟环境中也要安装uwsgi

  • 进入虚拟环境
workon luffy
  • 安装uwsgi
pip install uwsgi
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# pip install uwsgi
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting uwsgi
  Using cached uWSGI-2.0.22-cp39-cp39-linux_x86_64.whl
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.22

(3)配置数据库

  • 登录数据库
mysql -uroot -p
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
  • 创建数据库
create database luffy defaushow databaseslt charset=utf8;
mysql> create database luffy default charset=utf8;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| luffy              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

mysql> 
  • 设置权限账号密码:账号密码要与项目中配置的一致
# 允许远程连接
grant all privileges on luffy.* to 'luffy'@'%' identified by 'Luffy123?';
# 允许本地连接
grant all privileges on luffy.* to 'luffy'@'localhost' identified by 'Luffy123?';
# 刷新权限
flush privileges;
mysql> grant all privileges on luffy.* to 'luffy'@'%' identified by 'Luffy123?';
Query OK, 0 rows affected, 1 warning (0.06 sec)

mysql> grant all privileges on luffy.* to 'luffy'@'localhost' identified by 'Luffy123?';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
  • 退出mysql
quit;

mysql -h 43.138.48.158 -P 3306 -u luffy -p
  • 使用本地navicate链接阿里云的luffy库,使用luffy用户

(4)迁移表

# 把项目中得迁移文件删除,提交,远程
python manage.py makemigrations
python manage.py migrate
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# python manage.py makemigrations
Migrations for 'course':
  luffyCity/apps/course/migrations/0001_initial.py
    - Create model Course
    - Create model CourseCategory
    - Create model CourseChapter
    - Create model Teacher
    - Create model CourseSection
    - Add field course_category to course
    - Add field teacher to course
Migrations for 'home':
  luffyCity/apps/home/migrations/0001_initial.py
    - Create model Banner
Migrations for 'orders':
  luffyCity/apps/orders/migrations/0001_initial.py
    - Create model Order
    - Create model OrderDetail
  luffyCity/apps/orders/migrations/0002_order_user.py
    - Add field user to order
Migrations for 'user':
  luffyCity/apps/user/migrations/0001_initial.py
    - Create model User
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, course, home, orders, sessions, user
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying user.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying course.0001_initial... OK
  Applying home.0001_initial... OK
  Applying orders.0001_initial... OK
  Applying orders.0002_order_user... OK
  Applying sessions.0001_initial... OK

(5)uwsgi 运行django

  • 写一个uwsgi的配置文件
    • 在项目路径下,新建一个 luffyapi.xml
vi luffyapi.xml
<uwsgi>    
    <socket>127.0.0.1:9999</socket>
    <chdir>/home/project/luffy-project-api/</chdir>       
    <module>luffyCity.wsgi</module>
    <processes>4</processes>
    <daemonize>uwsgi.log</daemonize>
</uwsgi>
  • 使用uwsgi启动
uwsgi -x luffyapi.xml
  • 查看是否正常运行
ps aux |grep uwsgi
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# uwsgi -x luffyapi.xml
[uWSGI] parsing config file luffyapi.xml
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# ls
celerybeat-schedule.bak  celerybeat-schedule.dir  db.sqlite3  luffyapi.xml  manage_dev.py  requirements.txt
celerybeat-schedule.dat  celery_task              logs        luffyCity     manage.py      uwsgi.log
(luffy) [root@VM-8-11-opencloudos luffy-project-api]# ps aux |grep uwsgi
root       66250  5.0  2.4 375340 42672 ?        S    18:17   0:00 uwsgi -x luffyapi.xml
root       66256  0.0  1.7 375340 31224 ?        S    18:17   0:00 uwsgi -x luffyapi.xml
root       66257  0.0  1.7 375340 31224 ?        S    18:17   0:00 uwsgi -x luffyapi.xml
root       66259  0.0  1.7 375340 31224 ?        S    18:17   0:00 uwsgi -x luffyapi.xml
root       66335  0.0  0.0 221940  1200 pts/0    S+   18:17   0:00 grep --color=auto uwsgi

(6)配置nginx转发

cd /usr/local/nginx/conf
vi nginx.conf
  • 新增的server
server {
    listen 8000;
    server_name  127.0.0.1;
    charset utf-8;
    location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:9999;
    uwsgi_param UWSGI_SCRIPT luffyCity.wsgi; 
    uwsgi_param UWSGI_CHDIR /home/project/luffy-project-api/;
    }
}
  • 重启nginx
nginx -s reload

(7)导入数据

(8)配置域名解析

【补充】关于Navicat连接远程MySQL数据库无法连接问题

【1】首先确认自己的防火墙开放MySQL3306端口

【2】Centos7服务器本身的防火墙会阻止部分端口进入

  • CentOS7默认没有安装iptables,可以手动安装iptables;也可以通过CentOS7已带的firewall配置防火墙。

(1)查看firewalld.service服务状态

systemctl status firewalld

(2)查看firewall运行状态

firewall-cmd --state

(3)手动启动/停止/重启firewalld.service服务

# 启动firewalld
service firewalld start
# 停止firewalld
service firewalld stop
# 重启firewalld
service firewalld restart

(4)展示当前配置的firewall规则

firewall-cmd --list-all

(5)端口(端口段)的查询/开放

# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 新建永久规则,开放8080端口(TCP协议)
firewall-cmd --permanent --add-port=8080/tcp
# 移除上述规则
firewall-cmd --permanent --remove-port=8080/tcp
# 新建永久规则,批量开放一段端口(TCP协议)
firewall-cmd --permanent --add-port=9001-9100/tcp

(6)IP(IP段)的开放

# 新建永久规则,开放192.168.1.1单个源IP的访问
firewall-cmd --permanent --add-source=192.168.1.1
# 新建永久规则,开放192.168.1.0/24整个源IP段的访问
firewall-cmd --permanent --add-source=192.168.1.0/24
# 移除上述规则
firewall-cmd --permanent --remove-source=192.168.1.1

(7)系统服务的开放

# 开放http服务
firewall-cmd --permanent --add-service=http
# 移除上述规则
firewall-cmd --permanent --remove-service=http

(8)自定义复杂规则(注意是否与已有规则冲突)

# 允许指定IP访问本机8080端口
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="8080" accept'
# 允许指定IP段访问本机8080-8090端口
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="8080-8090" accept'
# 禁止指定IP访问本机8080端口
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="8080" reject'

(9)任何修改操作,配置完成后,需要重新装载firewall。可重新启动firewalld服务。

firewall-cmd --reload
service firewalld restart
  • 修改放行MySQL3306端口后需要重启MySQL服务

【十五】配置后台admin访问

  • 浏览器访问http://8.130.18.221:8000/admin 发现没有样式

  • 因为uwsgi不能给我们代理静态资源

  • 收集静态资源,使用nginx代理

  • prod.py中加入

STATIC_ROOT = '/home/project/luffy_api/luffy_api/static/'
  • 执行命令
  • 进入虚拟环境
mkdir /home/project/luffy_api/luffy_api/static
python manage_prod.py collectstatic
  • 修改nginx配置文件
  • 新增的配置静态文件
server {
listen 8000;
server_name  127.0.0.1;
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8888;
uwsgi_param UWSGI_SCRIPT luffy_api.wsgi; 
uwsgi_param UWSGI_CHDIR /home/project/luffy_api/;
}
location /static {
alias /home/project/luffy_api/luffy_api/static;
}
}
posted @ 2023-08-19 17:28  Chimengmeng  阅读(146)  评论(0编辑  收藏  举报
/* */