Seata服务搭建 —— db数据源

Posted mry6

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Seata服务搭建 —— db数据源相关的知识,希望对你有一定的参考价值。

Seata服务搭建 —— db数据源

Seata Server(TC)环境搭建

官网地址:https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html

Server端存储模式(store.mode)支持三种:
1》file:单机模式,全局事务会话信息内存中读写并持久化本地文件root.data,性能较高(默认)
2》db:(mysql 5.7+)高可用模式,全局事务会话信息通过db共享,相应性能差些
3》redis:Seata-Server 1.3及以上版本支持,性能较高,存在事务信息丢失风险,请提前配置适合当前场景的redis持久化配置。

资源目录:
官网地址:https://github.com/seata/seata/tree/1.3.0/script
1》client
存放client端sql脚本,参数配置
2》config-center
各个配置中心参数导入脚本,config.txt(包含server和client,原名nacos-config.txt)为通用参数文件
3》server
server端数据库脚本及各个容器配置

db存储模式

步骤一:下载安装包
官网地址:https://github.com/seata/seata/releases


步骤二:打开config/file.conf

默认file.conf文件如下:

步骤三:修改mode=“db” 且 修改数据库连接信息(url\\username\\password)

store 
  ## store mode: file、db、redis
  mode = "db"

  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://106.14.156.185:3306/seata_server"
    user = "root"
    password = "root"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  


步骤四:创建数据库seata_server
数据库表对应的位置:https://github.com/seata/seata/blob/1.4.0/script/server/db/mysql.sql

步骤五:新建表

-- -------------------------------- 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(96),
    `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;

以上是关于Seata服务搭建 —— db数据源的主要内容,如果未能解决你的问题,请参考以下文章

十九:分布式事务Seata源码分析

seata系列centos服务器带你踩坑搭建seata以及解决MySQL8.0无法启动问题

分布式事务Seata

Seata服务搭建 —— nacos

分布式事务Seata

Seata服务高可用+负载均衡搭建