项目版本
- Spring Cloud Hoxton.SR8
- Spring Cloud Alibaba 2.2.5.RELEASE
- Spring Boot 2.3.2.RELEASE
- Nacos 2.0.1
- Sentinel 1.8.1
- Seata 1.4.2
Nacos,Sentinel,Seata 均为 Docker 版本
Nacos 部署
基本无坑点,略过
Seata 部署
推荐使用 Nacos 作为注册中心+配置中心
目录结构
/seata ├── config └── registry.conf └── config-center └── nacos └── nacos-config.sh └── config.txt └── docker-compose.yml
docker-compose.yml
version: '3'
networks:
seata:
name: seata
driver: bridge
services:
seata:
image: seataio/seata-server:1.4.2
hostname: seata
container_name: seata
networks:
- seata
ports:
- '8091:8091'
environment:
TZ: Asia/Shanghai
SEATA_IP: 192.168.25.100
SEATA_PORT: 8091
SEATA_CONFIG_NAME: file:/root/seata/config/registry
volumes:
- ./config:/root/seata/config
deploy:
resources:
limits:
cpus: '0.5'
memory: 1024M
restart: always
registry.conf
registry {
# file、nacos、zk、consul、etcd3、eureka、redis、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.25.100:8848"
group = "seata-tx"
namespace = "5cd2ecf8-3ca8-40e4-9014-0123b2851a2f"
cluster = "default"
username = ""
password = ""
}
}
config {
# file、nacos、zk、consul、etcd3、apollo
type = "nacos"
file {
name = "file:/root/seata/config/file.conf"
}
nacos {
serverAddr = "192.168.25.100:8848"
group = "seata-tx"
namespace = "5cd2ecf8-3ca8-40e4-9014-0123b2851a2f"
username = ""
password = ""
}
}
config.txt
service.vgroupMapping.service-order-group=default
service.vgroupMapping.service-storage-group=default
service.vgroupMapping.service-account-group=default
service.default.grouplist=192.168.25.100:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://192.168.25.100:3306/seata?rewriteBatchedStatements=true
store.db.user=seata
store.db.password=seata
store.db.minConn=5
store.db.maxConn=100
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.lockTable=lock_table
store.db.queryLimit=100
store.db.maxWait=5000
nacos-config.sh
https://github.com/seata/seata/blob/develop/script/config-center/nacos/nacos-config.sh
推送命令
bash nacos-config.sh -h 192.168.25.100 -p 8848 -g seata-tx -t 5cd2ecf8-3ca8-40e4-9014-0123b2851a2f -u nacos -w nacos
坑点
-
docker-compose.yml
Seata 服务端注册进 Nacos 后,注册 IP 是 Seata 容器中的虚拟 IP
指定环境变量
SEATA_IP
和SEATA_PORT
后,注册中心以此为准显示 Seata 服务端地址 -
registry.conf
注意命名空间,所属组对应即可
服务端
registry.nacos.application
的值要与客户端一致 -
config.txt
service.vgroupMapping.xxx=default
的xxx
要与客户端对应
客户端
pom.xml
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
</exclusion>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</dependency>
bootstrap.yml
spring:
profiles: dev
cloud:
nacos:
discovery:
server-addr: 192.168.25.100:8848
group: seata-tx
namespace: 5cd2ecf8-3ca8-40e4-9014-0123b2851a2f
config:
server-addr: 192.168.25.100:8848
group: seata-tx
namespace: 5cd2ecf8-3ca8-40e4-9014-0123b2851a2f
file-extension: yaml
sentinel:
transport:
dashboard: 192.168.25.100:9958
port: 8719
seata:
enabled: true
tx-service-group: service-order-group
enable-auto-data-source-proxy: true
registry:
type: nacos
nacos:
application: seata-server
server-addr: 192.168.25.100:8848
group: seata-tx
namespace: 5cd2ecf8-3ca8-40e4-9014-0123b2851a2f
cluster: default
config:
type: nacos
nacos:
server-addr: 192.168.25.100:8848
group: seata-tx
namespace: 5cd2ecf8-3ca8-40e4-9014-0123b2851a2f
坑点
-
Seata 服务端版本要与客户端依赖版本一致
-
bootstrap.yml
客户端的
seata.tx-service-group: xxx
要与服务端的service.vgroupMapping.xxx
对应