seata1.3 nacos1.3.0配置中心
1.下载seata-dev-tools
https://gitee.com/seata-io/seata
2.下载seata1.3
https://download.youkuaiyun.com/download/LawsonJin/12647510
3.cd script/config-center/nacos/
4.vim nacos-config.sh 44行 配置nacos的地址 、端口、账号密码
if [[ -z ${host} ]]; then
host=nacos.baidu.com
fi
if [[ -z ${port} ]]; then
port=80
fi
if [[ -z ${group} ]]; then
group="SEATA_GROUP"
fi
if [[ -z ${tenant} ]]; then
tenant=""
fi
if [[ -z ${username} ]]; then
username="nacos"
fi
if [[ -z ${password} ]]; then
password="hon20"
fi
5. sh nacos-config.sh 上传配置信息
6.unzip seata1.3 下载seata1.3解压
7.cd seata1.3/conf
8.vim file.conf 这里我使用db模式
## transaction log store, only used in seata-server
store {
## store mode: file、db、redis
mode = "db"
## 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://39.97.999.29:3306/seata"
user = "root"
password = "ho20"
minConn = 5
maxConn = 30
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
service {
vgroupMapping.storage-service-group= "default"
vgroupMapping.order-service-group= "default"
vgroupMapping.business-service-group= "default"
}
}
9.配置数据库文件 seata数据库
/*
Navicat Premium Data Transfer
Source Server : OBD服务器
Source Server Type : MySQL
Source Server Version : 50730
Source Host : 39.97.208.29:3306
Source Schema : seata
Target Server Type : MySQL
Target Server Version : 50730
File Encoding : 65001
Date: 09/09/2020 11:54:01
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for branch_table
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
`branch_id` bigint(20) NOT NULL,
`xid` varchar(128) NOT NULL,
`transaction_id` bigint(20) DEFAULT NULL,
`resource_group_id` varchar(32) DEFAULT NULL,
`resource_id` varchar(256) DEFAULT NULL,
`branch_type` varchar(8) DEFAULT NULL,
`status` tinyint(4) DEFAULT NULL,
`client_id` varchar(64) DEFAULT NULL,
`application_data` varchar(2000) DEFAULT NULL,
`gmt_create` datetime(6) DEFAULT NULL,
`gmt_modified` datetime(6) DEFAULT NULL,
PRIMARY KEY (`branch_id`),
KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for global_table
-- ----------------------------
DROP TABLE IF EXISTS `global_table`;
CREATE TABLE `global_table` (
`xid` varchar(128) NOT NULL,
`transaction_id` bigint(20) DEFAULT NULL,
`status` tinyint(4) NOT NULL,
`application_id` varchar(32) DEFAULT NULL,
`transaction_service_group` varchar(32) DEFAULT NULL,
`transaction_name` varchar(128) DEFAULT NULL,
`timeout` int(11) DEFAULT NULL,
`begin_time` bigint(20) DEFAULT NULL,
`application_data` varchar(2000) DEFAULT NULL,
`gmt_create` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`xid`),
KEY `idx_gmt_modified_status` (`gmt_modified`,`status`),
KEY `idx_transaction_id` (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for lock_table
-- ----------------------------
DROP TABLE IF EXISTS `lock_table`;
CREATE TABLE `lock_table` (
`row_key` varchar(128) NOT NULL,
`xid` varchar(96) DEFAULT NULL,
`transaction_id` bigint(20) DEFAULT NULL,
`branch_id` bigint(20) NOT NULL,
`resource_id` varchar(256) DEFAULT NULL,
`table_name` varchar(32) DEFAULT NULL,
`pk` varchar(36) DEFAULT NULL,
`gmt_create` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`row_key`),
KEY `idx_branch_id` (`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET FOREIGN_KEY_CHECKS = 1;
10.每个需要全局事务的数据库中,放一个undo_log的表
/*
Navicat Premium Data Transfer
Source Server : OBD服务器
Source Server Type : MySQL
Source Server Version : 50730
Source Host : 39.97.208.29:3306
Source Schema : seata-demo
Target Server Type : MySQL
Target Server Version : 50730
File Encoding : 65001
Date: 07/08/2020 10:15:13
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=432 DEFAULT CHARSET=utf8;
SET FOREIGN_KEY_CHECKS = 1;
11.vim registry.conf
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "nacos.baidu.com:80"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "ho20"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "nacos.baidu.com:80"
namespace = ""
group = "SEATA_GROUP"
username = "nacos"
password = "ho0"
}
}
12. cd bin
13.sh seata-server.sh -p 8091 -h 192.168.0.199 -m file &> seata.log & -h如果是外网的话,请设置为外网IP,否则出错
14. 代码中配置seata tips:需要在每个分布式事务的微服务中都配置
seata:
tx-service-group: test_tx_service_group
config:
type: nacos
nacos:
serverAddr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: ${spring.cloud.nacos.username}
password: ${spring.cloud.nacos.password}
registry:
type: nacos
nacos:
server-addr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: ${spring.cloud.nacos.username}
password: ${spring.cloud.nacos.password}
15:在业务开始的地方添加注解@GlobalTransactional ,该注解下的所有增删改都会走分布式事务
16.seata常见问题 https://seata.io/zh-cn/docs/overview/faq.html
17.集群:在其他机器上,再开启一个seata,配置不变。