859630097com

seata服务端和客户端配置(使用nacos进行注册发现,使用mysql进行数据持久化),以及过程中可能会出现的问题与解决方案

说明:

之所以只用nacos进行了注册与发现,因为seata使用nacos后进行配置中心的化,需要往nacos中导入py脚本生成配置,还需要在服务端多加两个配置,过程比较繁琐,容易出问题,不太适合对这个框架理解不是很深的开发者

版本说明:

mysql 5.7
seata 1.4
springboot:2.3.7
springcloud:Hoxton.SR12
springcloudAlibaba: 2.2.6.RELEASE

服务端搭建及配置

  1. 下载seata 下载地址:下载中心 (seata.io)

  2. 上传至虚拟机/服务器/本地

    解压该文件:解压后

     

     

     

  3. 进入conf目录

     

     

     

  4. 修改registry.conf文件 

     

     

    对应配置:

    registry {
     # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
    type = "nacos"
    loadBalance = "RandomLoadBalance"
    loadBalanceVirtualNodes = 10

    nacos {
      application = "seata-server"
      serverAddr = "192.168.3.160:8848"
      group = "SEATA_GROUP"
      namespace = ""
      cluster = "default"
      username = ""
      password = ""
     }
     
    file {
      name = "file.conf"
     }
    }

    config {
     # file、nacos 、apollo、zk、consul、etcd3
    type = "file"

    nacos {
      serverAddr = "127.0.0.1:8848"
      namespace = ""
      group = "SEATA_GROUP"
      username = ""
      password = ""
     }

    file {
      name = "file.conf"
     }
    }

     

  5. 修改file.config文件

     

     

    对应配置:

    ## transaction log store, only used in seata-server
    store {
     ## store mode: file、db、redis
    mode = "db"

     ## database store property
    db {
       ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
      datasource = "druid"
       ## mysql/oracle/postgresql/h2/oceanbase etc.
      dbType = "mysql"
      driverClassName = "com.mysql.jdbc.Driver"
      url = "jdbc:mysql://127.0.0.1:3306/seata"
      user = "root"
      password = "123456"
      minConn = 5
      maxConn = 100
      globalTable = "global_table"
      branchTable = "branch_table"
      lockTable = "lock_table"
      queryLimit = 100
      maxWait = 5000
     }
    }

     

  6. 因为我们这里配置的持久化方式为mysql,在第六步中也有体现,这里需要将第六步配置的数据库创建出来

    1. 创建数据库库名为seata

    2. 导入SQL脚本,脚本为:

      /*
      Navicat Premium Data Transfer

      Source Server         : Mysql3.160
      Source Server Type   : MySQL
      Source Server Version : 50732
      Source Host           : 192.168.3.160:3306
      Source Schema         : seata

      Target Server Type   : MySQL
      Target Server Version : 50732
      File Encoding         : 65001

      Date: 13/12/2021 14:33:52
      */

      SET NAMES utf8mb4;
      SET FOREIGN_KEY_CHECKS = 0;

      -- ----------------------------
      -- Table structure for branch_table
      -- ----------------------------
      DROP TABLE IF EXISTS `branch_table`;
      CREATE TABLE `branch_table`  (
       `branch_id` bigint(20) NOT NULL,
       `xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
       `transaction_id` bigint(20) NULL DEFAULT NULL,
       `resource_group_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
       `resource_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
       `branch_type` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
       `status` tinyint(4) NULL DEFAULT NULL,
       `client_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
       `application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
       `gmt_create` datetime(6) NULL DEFAULT NULL,
       `gmt_modified` datetime(6) NULL DEFAULT NULL,
       PRIMARY KEY (`branch_id`) USING BTREE,
       INDEX `idx_xid`(`xid`) USING BTREE
      ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

      -- ----------------------------
      -- Records of branch_table
      -- ----------------------------

      -- ----------------------------
      -- Table structure for global_table
      -- ----------------------------
      DROP TABLE IF EXISTS `global_table`;
      CREATE

分类:

技术点:

相关文章: