相关推荐:
CentOS Stream 9 静态IP配置
CentOS Stream 9 搭建Nacos2.2.0集群以及OpenResty反向代理以及GRPC协议配置
官方GitHub:https://github.com/seata/seata/releases/tag/v1.6.1
在线下载:
cd /usr/local
wget https://github.com/seata/seata/releases/download/v1.6.1/seata-server-1.6.1.tar.gz
或者手动下载本地再上传
tar -zxvf seata-server-1.6.1.tar.gz
- file:(默认)单机模式,全局事务会话信息内存中读写并持久化本地文件root.data,性能较高(默认)
- db:(5.7+)高可用模式,全局事务会话信息通过db共享,相应性能差些
https://github.com/seata/seata/tree/1.6.1/script/server/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` (`xid`)
) 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);
打开config/application.yml
修改第47行
为db
vi seata/conf/application.yml
添加
mode: db
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true&useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
user: root
password: 123456
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 1000
max-wait: 500
将服务注册到Nacos中
修改第44行
为 type: nacos
添加;
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
namespace:
cluster: default
username: nacos
password: nacos
context-path:
##if use MSE Nacos with auth, mutex with username/password attribute
#access-key:
#secret-key:
选择从NacosConfig获取配置,
上面db配置了,这一步可以不用配置
,以数据库配置为例
修改第41行 type: nacosvi seata/conf/application.yml
添加:
type: nacos nacos: server-addr: 127.0.0.1:8848 namespace: group: SEATA_GROUP username: nacos password: nacos context-path: ##if use MSE Nacos with auth, mutex with username/password attribute #access-key: #secret-key: data-id: seata.properties
ESC :wq保存并退出
seata.properties
Group
SEATA_GROUP
配置格式
Properties
配置内容:
store.mode=db store.db.datasource=druid store.db.dbType=mysql store.db.driverClassName=com.mysql.cj.jdbc.Driver store.db.url=jdbc:mysql://192.168.20.128:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai store.db.user=root store.db.password=123456
sh /usr/local/seata/bin/seata-server.sh -h 192.168.20.128 -p 8091 -m db -n 1
参数 | 全写 | 作用 | 备注 |
---|---|---|---|
-h | -- host |
指定在注册中心注册的IP | 不指定时获取当前IP,外部访问部署在云环境和容器中的server建议指定 |
-p | -- post |
指定server启动的端口 | 默认为8091 |
-m | -- storeMode |
事务日志存储模式 | 支持file,db,redis 默认为file 注:redis需seata-server1.3版本及以上 |
-n | -- serverNode |
用于指定seata-server节点ID | (适合集群)如1,2,3…默认为1 |
-e | -- seataEnv |
指定seata-server运行环境 | 如dev,test等,服务启动时会使用registry-dev.conf这样的配置 |
查看启动日志(Ctrl C 可退出)
tail -f /usr/local/seata/logs/start.out
访问页面:http://192.168.20.128:7091/#/login
echo $JAVA_HOME
vi /usr/local/seata/bin/seata-server.sh
添加JDK路径,并延迟15秒启动,主要等nacos启动完成…:
因为我本地搭建的Nacos集群,需要等OpenResty完成代理(对着浏览器刷新集群地址,差不多就是15秒),才能获取到集群地址,不然等seata去获取nacos注册中心时,获取不到,就报错退出程序了…
tail -f /usr/local/seata/logs/start.out 查看启动日志,面对不同问题,针对性的去解决~
echo "seata delayed 15s start"
sleep 15
JAVA_HOME=/usr/local/java/jdk1.8.0_361
JAVA=$JAVA_HOME/bin
vi /etc/systemd/system/seata.service
添加内容(如果nacos在本机的话,配置了NacosConfig,一定要配置在nacos服务启动之后再执行):
[Unit]
Description=seata
After=nacos-cluster.service
[Service]
Type=forking
ExecStartPre=/bin/sleep 10
ExecStart=sh /usr/local/seata/bin/seata-server.sh -h 192.168.20.128 -p 8091 -m db -n 1
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /etc/systemd/system/seata.service
systemctl enable seata.service
systemctl status seata.service
关于项目中事务的使用,有时间再写~
搞定,感谢阅览~
END