【SpringCloud】微服务框架后端部署详细过程记录20240119

前言:前两天公司接到客户提供的一个微服务框架,导师让我在本地部署验证一下该框架的可用性,借此机会记录一下微服务项目的一个基本部署流程,仅供学习参考,如有不足还请指正!

文件结构

提供的压缩文件共包含源码、Maven配置信息以及一份框架说明

部署过程

1、修改Maven信息
  • 打开源码后先将Maven修改为框架提供的Maven配置文件(修改后需刷新Maven)
  • 附(Maven配置源码,供参考;该项目主要采用阿里云组件库):
xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <mirror>
            <id>mirror</id>
            <mirrorOf>central,jcenter,!rdc-releases,!rdc-snapshots</mirrorOf>
            <name>mirror</name>
            <url>https://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>

    </mirrors>
    <servers>
        <server>
            <id>rdc-releases</id>
            <username>64423e0f253e98e0c616d548</username>
            <password>cFMOPZMySW7I</password>
        </server>
        <server>
            <id>rdc-snapshots</id>
            <username>64423e0f253e98e0c616d548</username>
            <password>cFMOPZMySW7I</password>
        </server>
    </servers>
    <profiles>
        <profile>
            <id>rdc</id>
            <properties>
                <altReleaseDeploymentRepository>
                    rdc-releases::default::https://packages.aliyun.com/maven/repository/2260349-release-dYnJeL/
                </altReleaseDeploymentRepository>
                <altSnapshotDeploymentRepository>
                    rdc-snapshots::default::https://packages.aliyun.com/maven/repository/2260349-snapshot-x4T8Ra/
                </altSnapshotDeploymentRepository>
            </properties>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>rdc-releases</id>
                    <url>https://packages.aliyun.com/maven/repository/2260349-release-dYnJeL/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>rdc-snapshots</id>
                    <url>https://packages.aliyun.com/maven/repository/2260349-snapshot-x4T8Ra/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>snapshots</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>rdc-releases</id>
                    <url>https://packages.aliyun.com/maven/repository/2260349-release-dYnJeL/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>rdc-snapshots</id>
                    <url>https://packages.aliyun.com/maven/repository/2260349-snapshot-x4T8Ra/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>rdc</activeProfile>
    </activeProfiles>
</settings>
2、框架结构
  • 该框架主要包括gateway(网关)、uaa(认证系统)、platform(基础平台)、plugin(功能组件)四大部分,可根据需要部署使用。
3、初始化数据库
  • 将源码中doc/sq文件夹下的SQL导入本地数据库:
  • navicat中新建数据库(marscloud),字符集参考sql文件中字符集(utf8mb4):
  • 导入结果:
4、初始化nacos

nacos 配置文件在:doc/nacos 目录下,在 nacos 控制台导入目录下的 yaml 文件

  • 首先启动本地nacos

  • 在nacos新建命名空间(marscloud)

  • 导入yaml文件(可以现将所有yaml文件压缩为zip然后再导入)

  • 导入结果

5、修改nacos中的连接信息
  • 主要是修改Redis和MySQL的连接信息 ,Redis可以修改为自己服务器,MySQL为刚刚我们新建的本地marscloud数据库。(修改后记得发布【手动狗头】)

6、修改项目中nacos的连接信息
  • 通常情况下nacos连接信息在项目的bootstrap.yml文件夹中,但该框架无bootstrap.yml文件,而是配置项目启动的环境变量;每个微服务模块启动的环境变量都需要修改,以下为idea中的操作。

    启动时的环境变量如下(其中 NACOS_GROUP,NACOS_NAMESPACE 表示配置所在的组和命名空间,NACOS_URL 表示 nacos 连接地址,根据实际连接信息替换):

    Active profiles 为当前使用的配置环境

    NACOS_GROUP=DEFAULT_GROUP;NACOS_NAMESPACE=marscloud;NACOS_URL=localhost:8848

完成以上步骤后即可正常启动
Other 可能会出现的异常

若启动报错如下,说明未连接到nacos,需检查启动时的环境变量。

验证测试

  • 根据以上操作启动gateway、system、uaa三个模块

  • 使用apifox获取图片验证码进行测试,正常获取验证码,即项目后端部署完成(10002为网关端口)

Other 可能会出现的异常

若接口请求测试时出现以下异常,则可能是jdk版本导致,将jdk版本切换为1.8即可

Over!

相关推荐
鸽鸽程序猿16 小时前
【项目】基于Spring全家桶的论坛系统 【下】
后端·spring·restful
Lisonseekpan17 小时前
Spring Boot 中使用 Caffeine 缓存详解与案例
java·spring boot·后端·spring·缓存
小许学java17 小时前
Spring AI快速入门以及项目的创建
java·开发语言·人工智能·后端·spring·ai编程·spring ai
kfepiza19 小时前
Spring 如何解决循环依赖 笔记251008
java·spring boot·spring
kfepiza20 小时前
Spring的三级缓存原理 笔记251008
笔记·spring·缓存
青衫客361 天前
基于 Python 构建的安全 gRPC 服务——TLS、mTLS 与 Casbin 授权实战
python·安全·微服务
popoxf1 天前
spring容器启动流程(反射视角)
java·后端·spring
谷哥的小弟1 天前
Spring Framework源码解析——ApplicationContextAware
spring·源码
AAA修煤气灶刘哥1 天前
监控摄像头?不,我们管这个叫优雅的埋点艺术!
java·后端·spring cloud
武子康1 天前
Java-141 深入浅出 MySQL Spring事务失效的常见场景与解决方案详解(3)
java·数据库·mysql·spring·性能优化·系统架构·事务