Seata
seata为独立的服务,files目录里含有server端及源码
seata-server.sh:Linux启动seata执行脚本
seata-server.bat:windows启动seata执行脚本
配置seata服务端
导入seata数据库
新建seata数据库(库名自定义),导入如下sql
sql文件路径(源码):seata-1.3.0/script/server/db/mysql.sql
配置nacos注册中心
修改seata-server-1.3.0/seata/conf/registry.conf ↓
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = ""
password = ""
}
file {
name = "file.conf"
}
}
config {
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
file {
name = "file.conf"
}
}
配置数据库连接相关
复制txt文件至服务端的conf下
txt文件路径(源码):seata-1.3.0/script/config-center/config.txt
复制至(server端) -> seata-server-1.3.0/seata/conf/config.txt
# 修改为db模式
store.mode=db
# 如mysql8.0+,则修改为:com.mysql.cj.jdbc.Driver
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=username
store.db.password=password
配置sh脚本,将seata配置推送至nacos
1.复制sh执行文件至服务端的conf下
2.sh文件路径(源码):seata-1.3.0/script/config-center/nacos/nacos-config.sh
3.复制至(server端) -> seata-server-1.3.0/seata/conf/nacos-config.sh
4.86行添加conf:cat (dirname"(dirname "(dirname"PWD")/conf/config.txt
5.在conf目录下执行:sh nacos-config.sh -h 127.0.0.1 -p 8848
注:参数ip端口为nacos服务端地址,windows可安装git来执行sh命令
修改conf/file.conf
store {
mode = "db"
db {
datasource = "druid"
dbType = "mysql"
# 如mysql8.0+,则修改为:com.mysql.cj.jdbc.Driver
driverClassName = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://127.0.0.1:3306/seata"
user = "mysql"
password = "mysql"
minConn = 5
maxConn = 30
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
配置seata客户端
所有微服务业务数据库均需要导入事务表
sql文件路径(源码):seata-1.3.0/script/client/at/db/mysql.sql
application.yml配置
seata:
enabled: true
tx-service-group: ${spring.application.name}
enable-auto-data-source-proxy: true
config:
type: nacos
nacos:
namespace:
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848