目录
1. 版本说明
2. Windows下部署Seata1.5.2
2.1 创建回滚日志表undo_log
2.2 创建Seata服务端需要的四张表
2.3 在nacos创建seata命名空间,添加seataServer.yml配置
2.4 修改本地D:/tool/seata-server-1.5.2/seata/conf/applicaltion.yml文件
2.5 启动Seata
2.6 测试
3. 解决Seata无法启动问题
1. 版本说明
(1) spring-cloud-alibaba:2021.0.4.0 对应 seata-all:1.5.2,所以选择 Seata1.5.2 版本;
(2)目前 Seata 支持的 JDK版本为 JDK8、JDK11,这里使用JDK8。
2. Windows下部署Seata1.5.2
2.1 创建回滚日志表undo_log
注意:需要用到分布式事务的数据库都要创建这个表。
CREATE TABLE IF NOT EXISTS `undo_log`
(
`branch_id` BIGINT NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(128) NOT NULL COMMENT 'global transaction id',
`context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
`rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info',
`log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status',
`log_created` DATETIME(6) NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime',
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT ='AT transaction mode undo table';
ALTER TABLE `undo_log` ADD INDEX `ix_log_created` (`log_created`);
2.2 创建Seata服务端需要的四张表
注意:Seata存储模式store.mode=db,在Seata服务端需要连接的数据路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_status_gmt_modified` (`status` , `gmt_modified`),
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),
`status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`row_key`),
KEY `idx_status` (`status`),
KEY `idx_branch_id` (`branch_id`),
KEY `idx_xid_and_branch_id` (`xid` , `branch_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `distributed_lock`
(
`lock_key` CHAR(20) NOT NULL,
`lock_value` VARCHAR(20) NOT NULL,
`expire` BIGINT,
primary key (`lock_key`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);
2.3 在nacos创建seata命名空间,添加seataServer.yml配置
seataServer.yml如下:
内容如下:
service:
vgroupMapping:
default_tx_group: default
store:
db:
datasource: druid
dbType: mysql
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://172.xxx.xxx.xxx:9906/seata?useUnicode=true
user: root
password: root
minConn: 5
maxConn: 30
globalTable: global_table
branchTable: branch_table
lockTable: lock_table
distributedLockTable: distributed_lock
queryLimit: 100
maxWait: 5000
mode: db
2.4 修改本地D:/tool/seata-server-1.5.2/seata/conf/applicaltion.yml文件
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${user.home}/logs/seata
extend:
logstash-appender:
destination: 127.0.0.1:4560
kafka-appender:
bootstrap-servers: 127.0.0.1:9092
topic: logback_to_logstash
console:
user:
username: seata
password: seata
seata:
config:
# support: nacos, consul, apollo, zk, etcd3
type: nacos
nacos:
server-addr: 172.xxx.xxx.xxx:8848 #请把localhost改为nacos的ip
namespace: seata # 命名空间
group: SEATA_GROUP
username: nacos #nacos的账户
password: nacos #nacos的密码
data-id: seataServer.yml
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: nacos
nacos:
application: seata-server
server-addr: 172.xxx.xxx.xxx:8848 #请把localhost改为nacos的ip
namespace: seata # 命名空间
group: SEATA_GROUP
cluster: default
username: nacos #nacos的账户
password: nacos #nacos的密码
#store:
# support: file 、 db 、 redis
#mode: file
# server:
# service-port: 8091 #If not configured, the default is '${server.port} + 1000'
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
2.5 启动Seata
seata-server.bat -h 127.0.0.1 -m db
2.6 测试
浏览器输入网址:http://localhost:7091/,输入用户名和密码登录Seata。
注意:登录Seata的用户名密码默认是seata seata,可自定配置,修改application.yml的配置,如下:
3. 解决Seata无法启动问题
当在Windows下,进入Seata的bin目录下,输入cmd回车,输入Seata启动命令,如下:
seata-server.bat -h 127.0.0.1 -m db
(1)报错信息,如下:
(2)错误原因:
(1)在启动Seata Server时,Java虚拟机不认识CMSParallelRemarkEnabled 这个选项。
(2)CMSParallelRemarkEnabled 是与 CMS(Concurrent Mark-Sweep)垃圾回收器相关的选项,但在较新的 Java 版本中被移除了。
注意:目前Seata支持JDK8或JDK11。
(3)解决方案:
打开seata/bin目录下的seata-server.bat文件,将以下配置:
if "%JAVACMD%"=="" set JAVACMD=java
修改为,如下:
// 本地jdk路径
if "%JAVACMD%"=="" set JAVACMD="D:\Java\jdk1.8.0_251\bin\java.exe"