https://github.com/alibaba/nacos/releases
nacos-server-1.3.1.tar.gz上传到服务器的自定义目录中,并执行解压命令
tar -zxvf nacos-server-1.3.1.tar.gz
注意nacos1.3.1以下版本不支持mysql8
压缩包中sql脚本路径 /nacos/conf/nacos-mysql.sql
自己手动去创建nacos数据库,并执行官网的sql脚本建库建表
打开配置项比编辑mysql配置
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.164.31:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=root
db.password=123456
#*************** Naming Module Related Configurations ***************#
startup.sh -m standalone
访问nacos
http://192.168.164.35:8848/nacos
整合使用教程:https://blog.csdn.net/zjcjava/article/details/88316190
关于dataid的配置:https://www.jianshu.com/p/8db1c16542db
下载seata的server编译启动程序,下载地址:https://github.com/alibaba/nacos/releases
Linux选择下载seata-server-1.2.0.tar.gz,Windows选择下载seata-server-1.2.0.zip。
tar -zxvf seata-server-1.2.0.tar.gz
cd /seata/conf
1、registry.conf配置
默认情况下,seata-server的配置模式是file模式,这里选择db如下:
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
#改为nacos,前面那些配置只有关注nacos就好,其余能够删掉
type = "nacos"
nacos {
#这里其实官网配置文件是有一个坑的,就是`nacos`的`application`配置,旧值为seata-server,咱们须要批改为serverAddr
application = "serverAddr"
serverAddr = "192.168.164.35:8848" #改为Nacos服务器ip地址
namespace = "public" #改为Nacos给Seata用的Namespace,须要上Nacos新建一个,这里使用公共的public
cluster = "default"
username = "nacos" #改为Nacos的用户名
password = "nacos" #改为Nacos的密码
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
#改为nacos,前面那些配置只有关注nacos就好,其余能够删掉
type = "nacos"
#同上修改
nacos {
serverAddr = "192.168.164.35:8848"
namespace = "public"
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
}
}
2、修改file.conf配置
## transaction log store, only used in seata-server
store {
## store mode: file、db
mode = "db"
## database store property
db {
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
datasource = "druid"
## mysql/oracle/postgresql/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://192.168.164.31:3306/seata"
user = "root"
password = "123456"
minConn = 5
maxConn = 30
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
3、创建seata库并建表
/*
Navicat MySQL Data Transfer
Source Server : MkzCloud
Source Server Version : 80020
Source Host : 10.101.128.148:3306
Source Database : mkz_seata
Target Server Type : MYSQL
Target Server Version : 80020
File Encoding : 65001
Date: 2020-05-06 17:20:42
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for branch_table
-- 分支事务表
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
`branch_id` bigint NOT NULL,
`xid` varchar(128) NOT NULL,
`transaction_id` bigint DEFAULT NULL,
`resource_group_id` varchar(32) DEFAULT NULL,
`resource_id` varchar(256) DEFAULT NULL,
`branch_type` varchar(8) DEFAULT NULL,
`status` tinyint 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 DEFAULT NULL,
`status` tinyint NOT NULL,
`application_id` varchar(32) DEFAULT NULL,
`transaction_service_group` varchar(32) DEFAULT NULL,
`transaction_name` varchar(128) DEFAULT NULL,
`timeout` int DEFAULT NULL,
`begin_time` bigint 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 DEFAULT NULL,
`branch_id` bigint 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;
使用到seata分布式事务的所有业务库(订单库、积分库、商品库)中都要新建一张undo_log表,记录回滚日志(记录通过整合前置镜像SQL和后置镜像SQL所得的回滚SQL)
-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) 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=1 DEFAULT CHARSET=utf8;
4、下载源码:https://github.com/seata/seata/tree/1.2.0
将 config.txt 和nacos-config.sh 放到linux中,(可以放到任何位置,只要这两个文件在同一级目录下即可)nacos目录下,自己创建一个other目录
并且赋予nacos-config.sh执行权限
chmod +x nacos-config.sh
修改config.txt文件
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
#所有须要用到Seata的微服务名,须要跟微服务中Seata的配置统一
service.vgroupMapping.my_test_tx_group=default
service.vgroupMapping.my_order_tx_group=default
service.vgroupMapping.my_goods_tx_group=default
service.vgroupMapping.my_product_tx_group=default
service.default.grouplist=192.168.164.35:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
#修改为db模式
store.mode=db
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
#修改数据源配置
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://192.168.164.31:3306/seata?useUnicode=true
store.db.user=root
store.db.password=123456
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
client.undo.dataValidation=true
client.undo.logSerialization=jackson
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
修改nacos-config.sh 指定config.txt位置
for line in $(cat config.txt | sed s/[[:space:]]//g); do
最后,执行nacos-config.sh,将配置信息注册号nacos中
./nacos-config.sh
bash nacos-config.sh -h nacos的ip -p nacos的端口 -g nacos上seata的group -t nacos上seata的namespace
## 例如
bash nacos-config.sh -h 127.0.0.1 -p 8848 -g seata -t SEATA_GROUP
./seata-server.sh -p 8091 -h 192.168.164.35 -m db &
脚本参数:
-p 指定启动seata server的端口号。
-h 指定seata server所绑定的主机,这里配置要注意指定的主机IP要与业务服务内的配置文件保持一致,如:-h 192.168.1.10,业务服务配置文件内应该配置192.168.1.10,即使在同一台主机上也要保持一致。
-m 事务日志、事务执行信息存储的方式,目前支持file、db。