欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

seata docker 高可用部署的详细介绍

程序员文章站 2022-08-08 08:14:02
版本1.4.2启动通过环境变量seata_config_name指定配置文件位置/root/seata-config/registry.conf配置文件实现高可用需要依赖注册中心,配置中心,数据库re...

版本

1.4.2

启动

通过环境变量seata_config_name指定配置文件位置/root/seata-config/registry.conf

docker run --name seata-server \
        -p 8091:8091 \
        -e seata_config_name=file:/root/seata-config/registry \ 
        -v /user/seata/config:/root/seata-config  \
        seataio/seata-server

配置文件

实现高可用需要依赖注册中心,配置中心,数据库
registry.conf

registry {
  type = "nacos"

  nacos {
    application = "seata-server"
    serveraddr = "192.168.199.2"
    namespace = "test"
    group = "seata_group"
    cluster = "default"
    username = ""
    password = ""
  }
}

config {
  type = "nacos"  
  nacos {
    serveraddr = "192.168.199.2"
    namespace = "test"
    group = "seata_group"
    username = ""
    password = ""
  }
}

nacos配置

注:使用nacos配置,需要在对应分组(seata_group)下针对配置项目逐条配置文本值,而不是创建包含所有配置的properties文件,可以使用官方源码中的脚本导入
全部可用配置参考

1. 使用数据库

store.mode=db
store.db.datasource=druid
store.db.dbtype=mysql
store.db.driverclassname=com.mysql.jdbc.driver
store.db.url=jdbc:mysql://192.168.199.2:3306/seata?useunicode=true&rewritebatchedstatements=true
store.db.user=root
store.db.password=123456

创建数据库

建库脚本

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

异常处理

1. 客户端报错 data too long for column ‘application_id'

io.seata.core.exception.tmtransactionexception: transactionexception[begin global request failed. xid=null, msg=data truncation: data too long for column ‘application_id' at row 1]
at io.seata.tm.defaulttransactionmanager.begin(defaulttransactionmanager.java:55) ~[seata-all-1.3.0.jar:1.3.0]
at io.seata.tm.api.defaultglobaltransaction.begin(defaultglobaltransaction.java:104) ~[seata-all-1.3.0.jar:1.3.0]
at io.seata.tm.api.transactionaltemplate.begintransaction(transactionaltemplate.java:175) ~[seata-all-1.3.0.jar:1.3.0]

seata数据库global_table.application_id字段默认长度为varchar(32),如果客户端应用id超长则报此错
手动修改字段类型增加长度即可

到此这篇关于seata docker 高可用部署的文章就介绍到这了,更多相关seata docker部署内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!