<返回更多

Seata Server 环境搭建

2022-06-17    java柚子茶
加入收藏

Seata Server 环境搭建

参考地址:

seata.io/zh-cn/docs/…

Server 端存储模式(store.mode)支持三种:

配置文件

配置文件目录:

github.com/seata/seata…

Seata Server 环境搭建

 

client

存放client端sql脚本,参数配置

config-center
各个配置中心参数导入脚本,config.txt(包含server和client,原名nacos-config.txt)为通用参数文件
server
server端数据库脚本及各个容器配置

db存储模式 + Nacos(注册&配置中心)部署

步骤一:下载安装包 github.com/seata/seata…

Seata Server 环境搭建

 


步骤二:建表(仅db模式) 全局事务会话信息由3块内容构成,全

局事务-->分支事务-->全局锁,对应表global_table、branch_table、lock_table 创建数据库seata,执行sql脚本,文件在
script/server/db/MySQL.sql(seata源码)中

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
  `xid`                       VARCHAR(128) NOT NULL,
  `transaction_id`            BIGINT,
  `status`                    TINYINT      NOT NULL,
  `Application_id`            VARCHAR(32),
  `transaction_service_group` VARCHAR(32),
  `transaction_name`          VARCHAR(128),
  `timeout`                   INT,
  `begin_time`                BIGINT,
  `application_data`          VARCHAR(2000),
  `gmt_create`                DATETIME,
  `gmt_modified`              DATETIME,
  PRIMARY KEY (`xid`),
  KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
  KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
  `branch_id`         BIGINT       NOT NULL,
  `xid`               VARCHAR(128) NOT NULL,
  `transaction_id`    BIGINT,
  `resource_group_id` VARCHAR(32),
  `resource_id`       VARCHAR(256),
  `branch_type`       VARCHAR(8),
  `status`            TINYINT,
  `client_id`         VARCHAR(64),
  `application_data`  VARCHAR(2000),
  `gmt_create`        DATETIME(6),
  `gmt_modified`      DATETIME(6),
  PRIMARY KEY (`branch_id`),
  KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
  `row_key`        VARCHAR(128) NOT NULL,
  `xid`            VARCHAR(128),
  `transaction_id` BIGINT,
  `branch_id`      BIGINT       NOT NULL,
  `resource_id`    VARCHAR(256),
  `table_name`     VARCHAR(32),
  `pk`             VARCHAR(36),
  `gmt_create`     DATETIME,
  `gmt_modified`   DATETIME,
  PRIMARY KEY (`row_key`),
  KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;


步骤三:修改store.mode
启动包: seata-->conf-->file.conf,修改store.mode="db"
源码: 根目录-->seata-server-->resources-->file.conf,修改store.mode="db"


步骤四:修改数据库连接
启动包: seata-->conf-->file.conf,修改store.db相关属性。
源码: 根目录-->seata-server-->resources-->file.conf,修改store.db相关属性。

此时可以调到步骤七:直接启动Seata Server,注册中心和配置中心都是file

## transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db"
  ## rsa decryption public key
  publicKey = ""
  ## 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"
    ## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
    url = "jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true"
    user = "root"
    password = "root123"
    minConn = 5
    maxConn = 100
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }

  ## redis store property
  redis {
    ## redis mode: single、sentinel
    mode = "single"
    ## single mode property
    single {
      host = "127.0.0.1"
      port = "6379"
    }
    ## sentinel mode property
    sentinel {
      masterName = ""
      ## such as "10.28.235.65:26379,10.28.235.65:26380,10.28.235.65:26381"
      sentinelHosts = ""
    }
    password = ""
    database = "0"
    minConn = 1
    maxConn = 10
    maxTotal = 100
    queryLimit = 100
  }
}


步骤五:配置Nacos注册中心
将Seata Server注册到Nacos,修改conf目录下的registry.conf配置
然后启动注册中心Nacos Server

Seata Server 环境搭建

 


步骤六:配置Nacos配置中心

# 进入Nacos安装目录,linux单机启动 
bin/startup.sh ‐m standalone

# windows单机启动
bin/startup.bat

注意:如果配置了seata server使用nacos作为配置中心,则配置信息会从nacos读取,file.conf可以不用配置。 客户端配置registry.conf 使用nacos时也要注意group要和seata server中的group一致,默认group是"DEFAULT_GROUP" 获取
/seata/script/config-center/config.txt,修改配置信息配置事务分组, 要与客户端配置的事务分组一致 (客户端properties配置:spring.cloud.alibaba.seata.tx‐service‐group=my_test_tx_group)
配置参数同步到Nacos shell:

sh /Users/zhengsh/software/seata/script/config-center/nacos/nacos-config.sh ‐h localhost ‐p 8848 ‐g SEATA_GROUP ‐t 5a3c7d6c‐f497‐4d68‐a71a‐2e5e3340b3ca


参数说明:

-h: host,默认值 localhost
-p: port,默认值 8848
-g: 配置分组,默认值为 'SEATA_GROUP'
-t: 租户信息,对应 Nacos 的命名空间ID字段, 默认值为空

执行结果

Seata Server 环境搭建

 

精简配置

service.vgroupMapping.my_test_tx_group=default 
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false

store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true 10 store.db.user=root
store.db.password=root
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000

配置中心结果

Seata Server 环境搭建

 


步骤七:启动Seata Server
源码启动: 执行server模块下
io.seata.server.Server.java的main方法

命令启动: bin/seata-server.sh -h 127.0.0.1 -p 8091 -m db -n 1 -e test
启动Seata Server

bin/seata‐server.sh
Seata Server 环境搭建

 

启动成功,默认端口8091

在注册中心中可以查看到seata-server注册成功


作者:心城以北
链接:
https://juejin.cn/post/7106501042778406948

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>