应用系统定制开发分布式事务框架seata-1.5.2+nacos-1.4.1环境搭建

事务框架seata-1.5.2+nacos-1.4.1环境搭建

  1. 启动配置,在nacos中配置seata

    1. 为seata应用系统定制开发配置新增一个命名空间seata-server,应用系统定制开发或者命名空间ID。
      将命名空间ID设置为 conf/application.yml文件中 seata.config.nacos.namespace以及seata.register.nacos.namespace 的值
    2. 在seata-server命名空间中增加配置 seataSerer.properties, 配置格式选择properties。
      seataSerer.properties名称需和conf/application.yml文件中seata.config.nacos.data-id 节点值一致
    3. seataSerer.properties 配置值为
      # 数据存储方式,db代表数据库store.mode=dbstore.db.datasource=druidstore.db.dbType=mysqlstore.db.driverClassName=com.mysql.cj.jdbc.Driverstore.db.url=jdbc:mysql://127.0.0.1:3306/seata-server-db?useUnicode=true&rewriteBatchedStatements=true&useSSL=falsestore.db.user=rootstore.db.password=123456store.db.minConn=5store.db.maxConn=30store.db.globalTable=global_tablestore.db.branchTable=branch_tablestore.db.queryLimit=100store.db.lockTable=lock_tablestore.db.maxWait=5000# 事务、日志等配置server.recovery.committingRetryPeriod=1000server.recovery.asynCommittingRetryPeriod=1000server.recovery.rollbackingRetryPeriod=1000server.recovery.timeoutRetryPeriod=1000server.maxCommitRetryTimeout=-1server.maxRollbackRetryTimeout=-1server.rollbackRetryTimeoutUnlockEnable=falseserver.undo.logSaveDays=7server.undo.logDeletePeriod=86400000# 客户端与服务端传输方式transport.serialization=seatatransport.compressor=none# 关闭metrics功能,提高性能metrics.enabled=falsemetrics.registryType=compactmetrics.exporterList=prometheusmetrics.exporterPrometheusPort=9898
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
```
  • 1
  1. 下载-server

首先准备安装包,从https://github.com/seata/seata/releases下载 seata-1.5.2-release版本
下载后解压

  1. 安装 seata

    1. 新建数据库 seata-server-db(需要和 nacos中 seataSerer.properties 配置的名称一致),并创建branch_table、distributed_lock、global_table、lock_table表。sql脚本存放位置 script\server\db 目录下
    2. 首先备份原来的application.yml为application.yml.bak,接着拷贝拷贝application.example.yml为application.yml
    3. 在新的application.xml中增加控制台账号密码
      console:  user:    username: seata    password: seata
      • 1
      • 2
      • 3
      • 4
    4. 配置nacos注册中心和配置中心属性
      seata:  config:    # support: nacos 、 consul 、 apollo 、 zk  、 etcd3    type: nacos    nacos:      server-addr: 127.0.0.1:8848      namespace: ba144b64-05c1-4fee-972f-81fd0498a236 #nacos命名空间ID      group: SEATA_GROUP      username: nacos      password: nacos      data-id: seataServer.properties # nacos配置中心指定的配置data-id名称  registry:    type: nacos    preferred-networks: 30.240.*    nacos:      application: seata-server      server-addr: 127.0.0.1:8848      group: SEATA_GROUP      namespace: ba144b64-05c1-4fee-972f-81fd0498a236 #nacos命名空间ID      # cluster: default      username: nacos      password: nacos
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      1. 设置security
      seata:  security:    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017    tokenValidityInMilliseconds: 1800000    ignore:      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      1. 启动 seata
        进入 seata/bin目录

        windows换进双击seata-server.bat启动即可
        linux环境运行seata-server.sh

windows环境下启动成功效果

spingboot中使用seata,只写步骤,细节略

  1. 在pom文件中引入seata相关jar包

    <dependency>	<groupId>com.alibaba.cloud</groupId>  <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><dependency>  <groupId>com.alibaba.cloud</groupId>  <artifactId>spring-cloud-starter-alibaba-seata</artifactId></dependency>				
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  2. application.yaml中编写seata相关配置

    seata:  tx-service-group: default_tx_group  service:    vgroup-mapping:      default_tx_group: default  registry:    type: nacos    nacos:      namespace: ba144b64-05c1-4fee-972f-81fd0498a236      group: SEATA_GROUP      application: seata-server
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  3. 在业务方法上添加注解 @GlobalTransactional

    AT模式,在业务模块数据库中增加undo_log表,sql如下

    CREATE TABLE `undo_log` (  `branch_id` bigint NOT NULL COMMENT 'branch transaction id',  `xid` varchar(128) NOT NULL COMMENT 'global transaction id',  `context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',  `rollback_info` longblob NOT NULL COMMENT 'rollback info',  `log_status` int NOT NULL COMMENT '0:normal status,1:defense status',  `log_created` datetime(6) NOT NULL COMMENT 'create datetime',  `log_modified` datetime(6) NOT NULL COMMENT 'modify datetime',  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='AT transaction mode undo table';
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发