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...

相关推荐
装不满的克莱因瓶10 分钟前
SpringBoot 如何将 lib 目录中jar包打包进最终的jar包里面
spring boot·后端·maven·jar·mvn
ltl1 小时前
Transformer 原论文实验结果:为什么 28.4 BLEU 足以改写路线图
后端
Curvatureflight1 小时前
【架构实战】生产级大模型 API 接入指南:流式响应(Streaming)异常处理与监控闭环
python·架构
这是谁的博客?1 小时前
微服务架构设计模式深度解析:从拆分策略到容灾机制
微服务·设计模式·云原生·架构·架构设计·后端开发·分布式系统
excel1 小时前
为什么我推荐使用 Termius:现代 SSH 工具的完整体验
前端·后端
卷毛的技术笔记2 小时前
Java后端硬核实战:用Spring AI Alibaba+Redis给LLM装上“超强记忆中枢”
java·人工智能·redis·后端·spring·ai·系统架构
oo哦哦3 小时前
企业级矩阵管理中台:从“人海战术“到“AI智能增长“的架构演进与实践解析
人工智能·矩阵·架构·轻量化中台
IT_陈寒3 小时前
Java的Optional差点让我掉坑里,这几个坑你别踩
前端·人工智能·后端
heimeiyingwang3 小时前
【架构实战】分库分表ShardingSphere:突破数据库瓶颈
架构
子兮曰3 小时前
Harness 驾驭工程深度教程:从 AGENTS.md 到全链路 AI 编码基础设施
前端·后端·ai编程