适用与2.2.0版本
服务端
Docker方式
store.mode=db 方式不推荐,需要将mysql驱动映射到容器中的lib/jdbc或libs/jdbc中,试了两种方式,都是报错,加之Seata运行只需要安装Java环境即可,所以放弃使用docke运行
Jar运行方式
下载
seata.apache.org/zh-cn/downl...

修改配置
正式环境注册和配置中心推荐nacos,store推荐db模式
yml
server:
port: 7091
spring:
application:
name: seata-server
profiles:
# 环境配置
active: prod
logging:
config: classpath:logback-spring.xml
file:
path: ${log.home:${user.home}/logs/seata}
console:
user:
username: seata
password: seata
seata:
config:
# support: nacos 、 consul 、 apollo 、 zk 、 etcd3
type: nacos
nacos:
server-addr: 192.168.1.100:8848
#环境
namespace: prod
# 分组
group: seata-server
context-path:
##1.The following configuration is for the open source version of Nacos
username:
password:
##2.The following configuration is for the MSE Nacos on aliyun
#access-key:
#secret-key:
##3.The following configuration is used to deploy on Aliyun ECS or ACK without authentication
#ram-role-name:
data-id: seataServer.yml
registry:
# support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa 、 seata
type: nacos
preferred-networks: 30.240.*
metadata:
weight: 100
nacos:
application: seata-server
server-addr: 192.168.1.100:8848
#分组
group: seata-server
#环境
namespace: prod
#集群
cluster: prod
context-path:
##1.The following configuration is for the open source version of Nacos
username:
password:
##2.The following configuration is for the MSE Nacos on aliyun
#access-key:
#secret-key:
##3.The following configuration is used to deploy on Aliyun ECS or ACK without authentication
#ram-role-name:
server:
service-port: 8091 #If not configured, the default is '${server.port} + 1000'
max-commit-retry-timeout: -1
max-rollback-retry-timeout: -1
rollback-failed-unlock-enable: false
enable-check-auth: true
enable-parallel-request-handle: true
enable-parallel-handle-branch: false
retry-dead-threshold: 130000
xaer-nota-retry-timeout: 60000
enableParallelRequestHandle: true
applicationDataLimitCheck: true
applicationDataLimit: 64000
recovery:
committing-retry-period: 1000
async-committing-retry-period: 1000
rollbacking-retry-period: 1000
end-status-retry-period: 1000
timeout-retry-period: 1000
undo:
log-save-days: 7
log-delete-period: 86400000
session:
branch-async-queue-size: 5000 #branch async remove queue size
enable-branch-async-remove: false #enable to asynchronous remove branchSession
ratelimit:
enable: false
bucketTokenNumPerSecond: 999999
bucketTokenMaxNum: 999999
bucketTokenInitialNum: 999999
metrics:
enabled: false
registry-type: compact
exporter-list: prometheus
exporter-prometheus-port: 9898
transport:
rpc-tc-request-timeout: 15000
enable-tc-server-batch-send-response: false
shutdown:
wait: 3
thread-factory:
boss-thread-prefix: NettyBoss
worker-thread-prefix: NettyServerNIOWorker
boss-thread-size: 1
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
csrf-ignore-urls: /metadata/v1/**
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/version.json,/health,/error
Nacos配置
yaml
# 配置客户端对应的集群cluster参数
service:
vgroupMapping:
default_tx_group: prod
store:
# support: file 、 db 、 redis 、 raft
mode: db
session:
mode: db
lock:
mode: db
db:
datasource: druid
dbType: mysql
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.100:3306/seata?rewriteBatchedStatements=true
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
vgroup-table: vgroup_table
query-limit: 1000
max-wait: 5000
druid:
time-between-eviction-runs-millis: 120000
min-evictable-idle-time-millis: 300000
test-while-idle: true
test-on-borrow: false
keep-alive: false
hikari:
idle-timeout: 600000
keepalive-time: 120000
max-lifetime: 1800000
validation-timeout: 5000
dbcp:
time-between-eviction-runs-millis: 120000
min-evictable-idle-time-millis: 300000
test-while-idle: true
test-on-borrow: false
初始化数据库
SQL路径:seata-server\script\server\db
运行
一定要指定当前服务器的IP,不然在Nacos里面注册的IP不是真实的
sh ./bin/seata-server.sh -h 192.168.1.100
查看运行日志
tail -f /root/logs/seata/seata-server.8091.all.log
客户端
配置
yaml
seata:
application-id: applicationName
# 群组
tx-service-group: default_tx_group
data-source-proxy-mode: AT
config:
type: nacos
nacos:
namespace: "prod"
server-addr: 192.168.1.100:8848
group: "seata-server"
context-path:
data-id: seataServer.yml
registry:
type: nacos
preferredNetworks: ""
nacos:
application: seata-server
server-addr: 192.168.1.100:8848
group : "seata-server"
namespace: "prod"
context-path:
client-application: ${spring.application.name}
server:
port: 8088
spring:
application:
name: springboot-seata
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
password: '123456'
url: jdbc:mysql://192.168.1.79:3306/seata-test?useSSL=false&useUnicode=true&characterEncoding=UTF8
username: 'root'
示例代码
执行SQL初始化数据库
