阿里巴巴:
TXC:淘宝交易系统的分布式事务框架,阿里巴巴中间件团队自2014年开始启动该项目,用于解决应用架构从单一服务向微服务转变所带来的分布式事务问题;
GTS:全球交易服务。TXC作为阿里云中间件产品,新名称GTS于2016年发布;
Fescar:2019年开始了基于TXC/GTS的开源项目Fescar,用于开源项目社区发展;最后更名为 Seata
蚂蚁金服:
Seata社区:
Seata包含以下几个角色
Seata角色交互过程
交互步骤
安装版本seata-server-1.4.2
采用Nacos注册中心,Mysql存储。提前准备环境
环境 | 版本 | 准备 | IP |
---|---|---|---|
Nacos | 2.0.4 | 创建命名空间seata-namespace | 192.168.101.8:8848 |
Mysql | 5.6 | 创建数据库seata_server | 192.168.101.8:3306 |
Seata | 1.4.2 | 172.26.0.2:8091 |
步骤一:创建数据库seata_server。并执行脚本。参考https://github.com/seata/seata/blob/1.4.2/script/server/db/mysql.sql
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 = utf8mb4;
-- 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 = utf8mb4;
-- 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 = utf8mb4;
步骤二:在Nacos上创建命名空间seata-namespace(ID为e489e0de-8001-41b8-83a6-3241d426a9f7)
步骤三:在Nacos的seata-group命名空间下创建DataID为seataServer.properties
。Group为DEFAULT_GROUP,配置格式为properties,配置内容如下。配置参数参考地址https://seata.io/zh-cn/docs/user/configurations.html。配置config.txt地址https://github.com/seata/seata/blob/1.4.2/script/config-center/config.txt
# 重点修改config.txt的数据库配置
store.mode=db
# mysql8及以上版本对应的driver:com.mysql.cj.jdbc.Driver
# mysql8以下版本的driver:com.mysql.jdbc.Driver
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://192.168.101.8:3306/seata_server?useUnicode=true&rewriteBatchedStatements=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
store.db.user=root
store.db.password=root
store.db.minConn=5
store.db.maxConn=10
# 默认是my_test_tx_group
service.vgroupMapping.my_test_tx_group=default
步骤四:创建registry.conf配置文件(在./seata-server/nacos-db/config/目录下)
registry {
type = "nacos"
nacos {
# seata服务注册在nacos上的别名,客户端通过该别名调用服务
application = "seata-server"
# nacos服务的ip和端口
serverAddr = "192.168.101.8:8848"
# nacos上指定的namespace
namespace = "e489e0de-8001-41b8-83a6-3241d426a9f7"
cluster = "default"
group = "DEFAULT_GROUP"
username = "nacos"
password = "nacos"
}
}
config {
type = "nacos"
nacos {
# nacos服务的ip和端口
serverAddr = "192.168.101.8:8848"
# nacos上指定的namespace
namespace = "e489e0de-8001-41b8-83a6-3241d426a9f7"
group = "DEFAULT_GROUP"
username = "nacos"
password = "nacos"
# 从v1.4.2版本开始,已支持从一个Nacos dataId中获取所有配置信息,只需要额外添加一个dataId配置项
dataId="seataServer.properties"
}
}
步骤五:创建docker-compose-nacos-db.yml
version: "3"
services:
seata-server:
image: seataio/seata-server:1.4.2
hostname: seata-server
ports:
- "8091:8091"
environment:
- SEATA_PORT=8091
- SEATA_CONFIG_NAME=file:/root/seata-config/registry
volumes:
- "./seata-server/nacos-db/config/:/root/seata-config/:rw"
restart: always
networks:
seata-net:
ipv4_address: 172.26.0.2
networks:
seata-net:
driver: bridge
ipam:
config:
- subnet: 172.26.0.0/16
步骤六:启动
$ docker-compose -f docker-compose-nacos-db.yml up
...省略...
: Server started, listen port: 8091
表示启动成功
步骤七:在Nacos中可以看到Seata Server的注册信息