seata的搭建与安装

seata1.3.0 服务端的搭建

1.从官网下载seata-server1.3.0

https://github.com/seata/seata/releases/tag/v1.3.0

2.下载以后conf目录有两个配置文件,一个是注册配置文件,另一个是file配置文件

注册配置文件用nacos的话,注意seata-server服务端与连接到该服务端的客户端是在一个group下面,否则客户端会报错无法从nacos注册服务器找到服务端。

seata的搭建与安装

 

 

 file配置文件

service {
  #transaction service group mapping
  vgroupMapping.fsp_tx_group = "default"
  default.grouplist = "127.0.0.1:8091"
  #degrade, current not support
  enableDegrade = false
  #disable seata
  disableGlobalTransaction = false
}

 注意默认事务组是fsp_tx_group,后续客户端连接事务组的时候也要是这个

    alibaba:
      seata:
        tx-service-group: fsp_tx_group

 客户端的file配置文件也要是一样的事务组名称

service {
  vgroupMapping.fsp_tx_group = "default" #修改自定义事务组名称
  default.grouplist = "127.0.0.1:8091"
  enableDegrade = false
  disable = false
  max.commit.retry.timeout = "-1"
  max.rollback.retry.timeout = "-1"
  disableGlobalTransaction = false
}

 file里面可以配置数据库

## transaction log store, only used in server side
store {
  ## store mode: file、db
  mode = "db"
  ## file store property
  file {
    ## store location dir
    dir = "sessionStore"
    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
    sessionReloadReadSize = 100
    # async, sync
    flushDiskMode = async
  }

  ## 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://localhost:3306/seata"
    user = "root"
    password = "root"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }
}
## server configuration, only used in server side
server {
  recovery {
    #schedule committing retry period in milliseconds
    committingRetryPeriod = 1000
    #schedule asyn committing retry period in milliseconds
    asynCommittingRetryPeriod = 1000
    #schedule rollbacking retry period in milliseconds
    rollbackingRetryPeriod = 1000
    #schedule timeout retry period in milliseconds
    timeoutRetryPeriod = 1000
  }
  undo {
    logSaveDays = 7
    #schedule delete expired undo_log in milliseconds
    logDeletePeriod = 86400000
  }
  #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
  maxCommitRetryTimeout = "-1"
  maxRollbackRetryTimeout = "-1"
  rollbackRetryTimeoutUnlockEnable = false
}

## metrics configuration, only used in server side
metrics {
  enabled = false
  registryType = "compact"
  # multi exporters use comma divided
  exporterList = "prometheus"
  exporterPrometheusPort = 9898
}

同时搭建seata-server服务所依赖的数据库,global_tablesql,branch_table,lock_table语句见https://gitee.com/xiaoyinjun/seata-demo/blob/master/sql/seata.sql

配置好文件之后,启动脚本sh seata-server.sh -p 8091 -h  ******(绑定的ip地址)就可以执行了。

客户端代码示例见https://gitee.com/xiaoyinjun/seata-demo.git。如果按照以上搭建seata-server服务器,搭建客户端代码示例中所需要的数据库,建库语句在sql目录里面。就可以一键运行了。

seata官方文档见地址https://seata.io/zh-cn/docs/overview/what-is-seata.html

上一篇:Seata 分布式事务


下一篇:Seata RPC 模块的重构之路