一、seata服务端下载,下载方式介绍两种入口,如下:
1. seata官网 (http://seata.io/zh-cn/blog/download.html) 下载中心
找到对应版本,下载 binary 即可。 下载包名为:seata-server-1.5.2.zip
2. github上下载 Releases · seata/seata · GitHub
找到对应的1.5.2版本,每个版本下都有一个缩放的Assets,点击下载即可。
二、解压、修改配置(配置nacos)
1. 解压zip,linux解压后目录一致
2.seata配置nacos,进入 conf目录下 cd \seata-server-1.5.2\seata\conf ,修改 application.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: xx.xx.xx.110:8848
namespace: seata-namespace-id
group: SEATA_GROUP
username: nacos
password: nacos
data-id: seataServer.properties
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: nacos
nacos:
application: seata-server
server-addr: xx.xx.xx.110:8848
group: SEATA_GROUP
namespace: seata-namespace-id
cluster: default
username: nacos
password: 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
注意其中需要修改的几个值:
3.nacos中创建命名空间,id为 上图中的 seata-namespace-id , 名称 为 seata
4. nacos配置列表中新增配置,Data id 为 上图中的 seataServer.properties, group 为:SEATA_GROUP. 如下:以下内容可以直接复制使用。
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://xx.xx.x.xxx:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=xxxxxx
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
service.vgroupMapping.default_tx_group=default
三、配置数据库(mysql)
1. 上面2.4中配置了mysql数据库地址,从下载包中找到对应sql.
cd \seata-server-1.5.2\seata\script\server\db
该目录下找到对应mysql.sql文件,在 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(128),
`pk` VARCHAR(128),
`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);
四、启动seata
1. 进入启动目录 ,输入如下命令启动即可。
1. 进入bin目录(这里只提示路径)
cd seata-server-1.5.2\seata\bin;
2. 执行服务
sh seata-server.sh -h xx.xx.x.xxx -p 8091
注意上面的 -h :指该服务器ip,不指定的话,不然注册到nacos的会是不想要的本地ip(127.xx.xx.xx)
2.启动完成后可以浏览日志,或者去nacos中服务列表查看seata 服务是否已成功注册。如下图:
注意:seata启动会占用两个端口,8091 和 7091 。 其中 8091 是注册到nacos中的服务端端口,7091是其客户端端口。7091对应页面如下图:
访问地址:xx.xx.x.xxx:7091 账号: seata/seata
五、springcloud集成seata1.5.2 请参考:
Springcloud 集成 Seata1.5.2_不知道取啥昵称的博客-CSDN博客