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

相关推荐
iuyou️12 分钟前
Spring Boot知识点详解
java·spring boot·后端
一弓虽24 分钟前
SpringBoot 学习
java·spring boot·后端·学习
姑苏洛言33 分钟前
扫码小程序实现仓库进销存管理中遇到的问题 setStorageSync 存储大小限制错误解决方案
前端·后端
光而不耀@lgy1 小时前
C++初登门槛
linux·开发语言·网络·c++·后端
方圆想当图灵1 小时前
由 Mybatis 源码畅谈软件设计(七):SQL “染色” 拦截器实战
后端·mybatis·代码规范
毅航2 小时前
MyBatis 事务管理:一文掌握Mybatis事务管理核心逻辑
java·后端·mybatis
我的golang之路果然有问题2 小时前
速成GO访问sql,个人笔记
经验分享·笔记·后端·sql·golang·go·database
柏油2 小时前
MySql InnoDB 事务实现之 undo log 日志
数据库·后端·mysql
cooldream20092 小时前
深入解析大数据的Lambda架构:设计、特点与应用场景
大数据·架构·系统架构师
写bug写bug4 小时前
Java Streams 中的7个常见错误
java·后端