Seata 部署手册

适用与2.2.0版本

服务端

Docker方式

store.mode=db 方式不推荐,需要将mysql驱动映射到容器中的lib/jdbc或libs/jdbc中,试了两种方式,都是报错,加之Seata运行只需要安装Java环境即可,所以放弃使用docke运行

Jar运行方式

下载

seata.apache.org/zh-cn/downl...

修改配置

正式环境注册和配置中心推荐nacos,store推荐db模式

yml 复制代码
server:
  port: 7091

spring:
  application:
    name: seata-server
  profiles:
    # 环境配置
    active: prod

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${log.home:${user.home}/logs/seata}
console:
  user:
    username: seata
    password: seata
seata:
  config:
    # support: nacos 、 consul 、 apollo 、 zk  、 etcd3
    type: nacos
    nacos:
      server-addr: 192.168.1.100:8848
      #环境
      namespace: prod
      # 分组
      group: seata-server
      context-path:
      ##1.The following configuration is for the open source version of Nacos
      username:
      password:
      ##2.The following configuration is for the MSE Nacos on aliyun
      #access-key:
      #secret-key:
      ##3.The following configuration is used to deploy on Aliyun ECS or ACK without authentication
      #ram-role-name:
      data-id: seataServer.yml
  registry:
    # support: nacos 、 eureka 、 redis 、 zk  、 consul 、 etcd3 、 sofa 、 seata
    type: nacos
    preferred-networks: 30.240.*
    metadata:
      weight: 100
    nacos:
      application: seata-server
      server-addr: 192.168.1.100:8848
      #分组
      group: seata-server
      #环境
      namespace: prod
      #集群
      cluster: prod
      context-path:
      ##1.The following configuration is for the open source version of Nacos
      username:
      password:
      ##2.The following configuration is for the MSE Nacos on aliyun
      #access-key:
      #secret-key:
      ##3.The following configuration is used to deploy on Aliyun ECS or ACK without authentication
      #ram-role-name:
  server:
    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
    max-commit-retry-timeout: -1
    max-rollback-retry-timeout: -1
    rollback-failed-unlock-enable: false
    enable-check-auth: true
    enable-parallel-request-handle: true
    enable-parallel-handle-branch: false
    retry-dead-threshold: 130000
    xaer-nota-retry-timeout: 60000
    enableParallelRequestHandle: true
    applicationDataLimitCheck: true
    applicationDataLimit: 64000
    recovery:
      committing-retry-period: 1000
      async-committing-retry-period: 1000
      rollbacking-retry-period: 1000
      end-status-retry-period: 1000
      timeout-retry-period: 1000
    undo:
      log-save-days: 7
      log-delete-period: 86400000
    session:
      branch-async-queue-size: 5000 #branch async remove queue size
      enable-branch-async-remove: false #enable to asynchronous remove branchSession
    ratelimit:
      enable: false
      bucketTokenNumPerSecond: 999999
      bucketTokenMaxNum: 999999
      bucketTokenInitialNum: 999999
  metrics:
    enabled: false
    registry-type: compact
    exporter-list: prometheus
    exporter-prometheus-port: 9898
  transport:
    rpc-tc-request-timeout: 15000
    enable-tc-server-batch-send-response: false
    shutdown:
      wait: 3
    thread-factory:
      boss-thread-prefix: NettyBoss
      worker-thread-prefix: NettyServerNIOWorker
      boss-thread-size: 1
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    csrf-ignore-urls: /metadata/v1/**
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/version.json,/health,/error

Nacos配置

yaml 复制代码
# 配置客户端对应的集群cluster参数
service:
  vgroupMapping:
    default_tx_group: prod

store:
  # support: file 、 db 、 redis 、 raft
  mode: db
  session:
    mode: db
  lock:
    mode: db
  db:
    datasource: druid
    dbType: mysql
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.1.100:3306/seata?rewriteBatchedStatements=true
    user: root
    password: '123456'
    min-conn: 10
    max-conn: 100
    global-table: global_table
    branch-table: branch_table
    lock-table: lock_table
    distributed-lock-table: distributed_lock
    vgroup-table: vgroup_table
    query-limit: 1000
    max-wait: 5000
    druid:
      time-between-eviction-runs-millis: 120000
      min-evictable-idle-time-millis: 300000
      test-while-idle: true
      test-on-borrow: false
      keep-alive: false
    hikari:
      idle-timeout: 600000
      keepalive-time: 120000
      max-lifetime: 1800000
      validation-timeout: 5000
    dbcp:
      time-between-eviction-runs-millis: 120000
      min-evictable-idle-time-millis: 300000
      test-while-idle: true
      test-on-borrow: false

初始化数据库

SQL路径:seata-server\script\server\db

运行

一定要指定当前服务器的IP,不然在Nacos里面注册的IP不是真实的

sh ./bin/seata-server.sh -h 192.168.1.100

查看运行日志

tail -f /root/logs/seata/seata-server.8091.all.log

客户端

配置

yaml 复制代码
seata:
  application-id: applicationName
  # 群组
  tx-service-group: default_tx_group
  data-source-proxy-mode: AT
  config:
    type: nacos
    nacos:
      namespace: "prod"
      server-addr: 192.168.1.100:8848
      group: "seata-server"
      context-path:
      data-id: seataServer.yml
  registry:
    type: nacos
    preferredNetworks: ""
    nacos:
      application: seata-server
      server-addr: 192.168.1.100:8848
      group : "seata-server"
      namespace: "prod"
      context-path:
      client-application: ${spring.application.name}
server:
  port: 8088
spring:
  application:
    name: springboot-seata
  datasource:
    driverClassName: com.mysql.cj.jdbc.Driver
    password: '123456'
    url: jdbc:mysql://192.168.1.79:3306/seata-test?useSSL=false&useUnicode=true&characterEncoding=UTF8
    username: 'root'

示例代码

官网Demo

执行SQL初始化数据库

参考

developer.aliyun.com/article/146...

相关推荐
面朝大海,春不暖,花不开16 分钟前
自定义Spring Boot Starter的全面指南
java·spring boot·后端
颜颜yan_1 小时前
【HarmonyOS5】UIAbility组件生命周期详解:从创建到销毁的全景解析
架构·harmonyos·鸿蒙·鸿蒙系统
钡铼技术ARM工业边缘计算机1 小时前
【成本降40%·性能翻倍】RK3588边缘控制器在安防联动系统的升级路径
后端
CryptoPP1 小时前
使用WebSocket实时获取印度股票数据源(无调用次数限制)实战
后端·python·websocket·网络协议·区块链
白宇横流学长1 小时前
基于SpringBoot实现的大创管理系统设计与实现【源码+文档】
java·spring boot·后端
草捏子2 小时前
状态机设计:比if-else优雅100倍的设计
后端
打码人的日常分享3 小时前
智慧城市建设方案
大数据·架构·智慧城市·制造
考虑考虑4 小时前
Springboot3.5.x结构化日志新属性
spring boot·后端·spring
涡能增压发动积4 小时前
一起来学 Langgraph [第三节]
后端
sky_ph4 小时前
JAVA-GC浅析(二)G1(Garbage First)回收器
java·后端