关于华为私有云部署若依springcloud微服务项目改造及部署

关于华为私有云部署若依springcloud微服务项目改造及部署

1.项目介绍

​ 当前微服务项目主流的注册中心为阿里巴巴的nacos,但介于甲方要求使用华为的注册中心,所以在接下来讲解项目改造:

2.改造项目

1.修改根目录下pom文件

在这里插入图片描述
将其中的

						<!-- SpringCloud Alibaba 微服务 -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- Alibaba Nacos 配置 -->
            <dependency>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-client</artifactId>
                <version>${alibaba.nacos.version}</version>
            </dependency>

注释掉,将华为的更换

						<dependency>
                <groupId>com.huaweicloud</groupId>
                <artifactId>spring-cloud-huawei-bom</artifactId>
                <version>${spring-cloud-huawei.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
<!--               华为注册中心         -->
            <dependency>
                <groupId>com.huaweicloud</groupId>
                <artifactId>spring-cloud-starter-huawei-servicecomb-discovery</artifactId>
            </dependency>
<!--               华为配置中心        -->
            <dependency>
                <groupId>com.huaweicloud</groupId>
                <artifactId>spring-cloud-starter-huawei-config</artifactId>
            </dependency>

这里切记确定好spring-cloud-huawei-bom的版本

到此,root下的pom文件改好了,接下来就是网关(gateway)

2.改造网关(ruoyi-gateway)

<!-- SpringCloud Gateway -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

        <!-- SpringCloud Alibaba Nacos -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <!-- SpringCloud Alibaba Nacos Config -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <!-- SpringCloud Alibaba Sentinel -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

        <!-- SpringCloud Alibaba Sentinel Gateway -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
        </dependency>

        <!-- Sentinel Datasource Nacos -->
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-datasource-nacos</artifactId>
        </dependency>
        
        <!-- SpringCloud Loadbalancer -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-loadbalancer</artifactId>
        </dependency>

将这些全部注释,然后增加新的依赖

		<dependency>
            <groupId>com.huaweicloud</groupId>
            <artifactId>spring-cloud-starter-huawei-service-engine-gateway</artifactId>
        </dependency>

接下来就是改造网关的bootstrap.yml文件,我们需要将之前的注册中心地址更换为华为的注册中心,所以注释掉之前配置的springcloudnacos以及sentinel如下

server:
  port: 8080
  env: development
spring: 
  application:
    # 应用名称
    name: ruoyi-gateway
  profiles:
    # 环境配置
    active: dev
  main:
    allow-circular-references: true
    allow-bean-definition-overriding: true
  cloud:
    nacos:
      discovery:
        # 服务注册地址
        server-addr: XXXXXXXXXXXXX:8848
      config:
        # 配置中心地址
        server-addr: XXXXXXXXXXXXX:8848
        # 配置文件格式
        file-extension: yml
        # 共享配置
        shared-configs:
          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
    sentinel:
      # 取消控制台懒加载
      eager: true
      transport:
        # 控制台地址
        dashboard: XXXXXXXXXXXXX:8718
      # nacos配置持久化
      datasource:
        ds1:
          nacos:
            server-addr: XXXXXXXXXXXXX:8848
            dataId: sentinel-ruoyi-gateway
            groupId: DEFAULT_GROUP
            data-type: json
            rule-type: flow

改为:

server:
  port: 8080
  env: development
# Spring
spring: 
  application:
    # 应用名称
    name: ruoyi-gateway
  profiles:
    # 环境配置
    active: dev
  main:
    allow-circular-references: true
    allow-bean-definition-overriding: true
  cloud:
    servicecomb:
      discovery:
        service-name: ruoyi-gateway
        appName: ruoyi
        address: https://xxxxxxxxxxxxx
      config:
        serverAddr: https://xxxxxxxxxxxxx
        fileSource: ruoyi-gateway-dev.yaml,application-dev.yaml
        env: development

addressserverAddr更换为华为云微服务引擎的注册地址和配置地址,

3.改造权限认证(ruoyi-auth)

权限认证和网关稍有不同,直接将

				<!-- SpringCloud Alibaba Nacos -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        
        <!-- SpringCloud Alibaba Nacos Config -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        
        <!-- SpringCloud Alibaba Sentinel -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

注释,替换为

		<dependency>
			<groupId>com.huaweicloud</groupId>
			<artifactId>spring-cloud-starter-huawei-service-engine</artifactId>
		</dependency>

其他模块修改方式和ruoyi-auth一样,更换pom文件依赖项,以及bootstrap.yml文件

3.华为云的配置以及应用的创建与部署

之后就是进入华为云的应用管理与运维平台(下面的截图是公有云的相关配置截图)

在这里插入图片描述
首先我们需要的是在应用管理中创建一个应用
在这里插入图片描述
直接输入应用名就行,之后就是配置中心的配置文件
在这里插入图片描述
其中微服务引擎(cse)中的我打码的地方就是bootstrap.yml中的两个地址,‘

进入控制台以后,按照截图进行操作即可
在这里插入图片描述
其中,进行第二步时选择相应的环境,如生产环境和正式环境,这个环境也可以在创建配置文件的时候选择
在这里插入图片描述
配置项:为bootstrap.yml中的config下的fileSource的值,告诉应用注册到配置中心以后找哪一个配置文件

:配置文件里面的内容,如springboot项目中,application.yaml文件的内容一样

这个就相当于阿里巴巴nacos的配置中心,我们将配置文件统一放到这里

之后我们返回到应用管理与运维平台

应用管理-应用列表,点击我们刚创建的应用
在这里插入图片描述
新增组件

选择组件类型-微服务
在这里插入图片描述
下一步

选择运行时:
在这里插入图片描述
​ 如果是mac开发的话,这里建议使用jar包方式部署

​ 选择框架/服务网络-spring-cloud
在这里插入图片描述
​ jar包方式我们将jar包上传到华为云的obs桶中选择,也可以选择其他方式上传

开启构建:是根据上传的jar包自动制作为一个docker镜像,

组织:用来管理docker镜像的

选择集群:是华为云的云容器引擎cce,需购买
在这里插入图片描述
​ 如果是windows开发的话,这个就无所谓了,(我只选择过jar包部署和docker)

​ 选择框架/服务网络-spring-cloud

之后创建并部署就行,注意查看部署成功以后的运行日志

4.提示

查看是否注册到微服务引擎
在这里插入图片描述
如果修改了bootstrap.yml文件,且更换了注册中心的地址以及配置中心的地址,还是无法注册上去的话查看是否配置账号的AKSK,如果遇到其他问题可以前往华为云官方文档查看相应配置步骤,实在找不到就提交工单

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值