SpringCloud Alibaba microservice combat 16-2.2.1.RELEASE version upgrade

Overview

It’s been a long time since we updated the SpringCloud Alibaba series of articles. Today we will upgrade the version to the latest graduation version. And pull out the original containerized deployment components seata, nacos, sentinel and deploy them separately to prepare for our future k8s deployment.

The official recommended version is as follows:
image.png

This article mainly talks about some problems encountered during the upgrade process and describes the process and methods to solve them. If you want to know the detailed usage, please read the previous article.

Major version upgrade

<properties>
...
	<spring-boot.version>2.2.5.RELEASE</spring-boot.version>
	<alibaba-cloud.version>2.2.1.RELEASE</alibaba-cloud.version>
	<springcloud.version>Hoxton.SR3</springcloud.version>
...
</properties>

Modify the component version corresponding to the main pom file of the parent module, and download the jar package again after the modification is complete.

nacos 1.2

The nacos upgrade is relatively easy, and it can be completed in two steps according to the following steps.

  • Initialize the nacos databasenacos-mysql.sql
  • Modify the nacos configuration file application.properties, release the database-related configuration notes, and modify it to your own database configuration
    image.png

seat 1.2

The process of initializing seata has been explained in detail in the previous tutorial, but the difference between the old and new versions is quite big. Let's mention here by the way. You can follow the steps below to complete.

  • Create a data table undo_log in the business system, and obtain the sql file from the following address:
    https://github.com/seata/seata/blob/develop/script/client/at/db/mysql.sql

  • Create a library named seata in your mysql database and initialize it. The sql file is obtained from the following address:
    https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql

  • The new version of seata has modified the artifactId, so we need to modify the dependency of seata

<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>

SpringCloud Alibaba 2.2.1 RELEASE The version of SEATA 1.1 is used. If you want to experience the features of SEATA 1.2, you can remove the dependency of seata on this basis and manually add version 1.2.

<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
	<exclusions>
		<exclusion>
			<artifactId>seata-spring-boot-starter</artifactId>
			<groupId>io.seata</groupId>
		</exclusion>
	</exclusions>
</dependency>

<dependency>
	<groupId>io.seata</groupId>
	<artifactId>seata-spring-boot-starter</artifactId>
	<version>1.2.0</version>
</dependency>
  • Seata modify configuration of the client
    that our client is to use registry.confas seata configuration file, you now need to configure moved application.yml or distribution center, the specific configuration file you can refer to the official website https://github.com/seata/seata/blob/develop/script/client/spring/application.yml, my configuration is as follows:
seata:
  enabled: true
  application-id: ${
    
    spring.application.name}
  tx-service-group: account_service_group
  enable-auto-data-source-proxy: true
  config:
    type: nacos
    nacos:
      namespace:
      serverAddr: 10.0.23.48:8848
      group: SEATA_GROUP
      userName: "nacos"
      password: "nacos"
  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: 10.0.23.48:8848
      namespace:
      userName: "nacos"
      password: "nacos"

You can modify other modules yourself.

  • Push the configuration of seata to nacos, here is the db mode, please refer to the official instructions for the operation steps: https://github.com/seata/seata/tree/develop/script/config-center
service.vgroupMapping.account_service_group=default
service.vgroupMapping.product_service_group=default
service.vgroupMapping.order_service_group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://10.0.23.48:3306/seata?useUnicode=true
store.db.user=root
store.db.password=xxxxxx
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000

After the modification is completed, execute the shell command in git, sh nacos-config.sh -h 10.0.23.48 -p 8848 -g SEATA_GROUP -u nacos -w nacosand after the execution is completed, the configuration file is pushed to nacos
image.png

  • Modify the seata server configuration registry.confand start the seata server after completion
registry {
  type = "nacos"
  nacos {
    application = "seata-server"
    serverAddr = "10.0.23.48:8848"
    namespace = ""
    cluster = "default"
    username = "nacos"
    password = "nacos"
  }
}
config {
  type = "nacos"
  nacos {
    serverAddr = "10.0.23.48:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = ""
    password = ""
  }
}
  • After the above steps of configuring seata, the upgrade is complete, please test by yourself
    image.png

sentinel 1.7

When using sentinel, many students will encounter situations where the api management menu is not displayed in the sentinel console, and the nacos current limiting configuration cannot be read. You can add startup parameters when the gateway module is started -Dcsp.sentinel.app.type=1, and restart the sentinel console. display.

image.png

In the previous article, I mentioned over the old version of the Sentinel gateway integrated with the flow of time the problem is not in effect, the reason is because the sentinel get to the gateway id not our account-service configuration, but add a CompositeDiscoveryClient_prefix, the original description as follows:
image.png

This problem is no longer in the new version, so we can delete the prefix in the gateway current limiting configuration file. The deleted configuration is as follows:
image.png

auth-service

When using postman to get access_token from auth-service, if the following error occursorg.springframework.security.core.authority.SimpleGrantedAuthority; local class incompatible: stream classdesc serialVersionUID = 510, local class serialVersionUID = 520

image.png

The reason for this problem is that the original database already stores the access_token corresponding to the account, but Spring Security does not support cross-version serialization, and the solution is very simple. Just delete the access_token corresponding to your user and regenerate it.

SpringCloud Gateway

When using PostMan for integration test, I found that the interface call always prompts 404 Not Found error.
image.png

Through org.springframework.cloud.gateway.filter.NettyRoutingFilterthe debugging of the source code file , it is found that the new version of Spring Cloud Gateway still retains the prefix we configured when doing forwarding.
image.png

As shown in the figure above, the prefix is ​​added after forwarding and the corresponding request path cannot be found, so a 404 exception occurs.

To solve this problem, we need to delete this prefix before forwarding. It happens that SprtingCloud Gateway provides a StripPrefix GatewayFilterfilter, which can be used to solve this problem:

The StripPrefix GatewayFilter factory takes one parameter, parts. The parts parameter indicates the number of parts in the path to strip from the request before sending it downstream.

For details, please refer to: https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.2.RELEASE/reference/html/#the-stripprefix-gatewayfilter-factory

Now that the cause of the abnormality is known and a solution is found, it is very simple. You only need to add the default filter when configuring the mapping in the gateway module:

spring:
  cloud:
	gateway:
      discovery:
        locator:
          enabled: true
      routes:
      - id: account-service
        uri: lb://account-service
        predicates:
          - Path=/account-service/**
		...
      # 解决前缀转发问题
      default-filters:
        - StripPrefix=1

After the above steps, our SpringCloud alibaba upgrade is completed, and various problems will be encountered during the upgrade process. When facing problems, don’t be impatient. Use code debugging to locate the problem. After locating the problem, I believe I will make good use of the search engine. It can be solved.

Insert picture description here

Guess you like

Origin blog.csdn.net/jianzhang11/article/details/106567841