环境搭建seata1.5.2版本
说明,高版本的seata必须要用高版本的springboot、springcloud、springcloudAlibaba,否则会报很多无法解决的错误可以参考版本说明
seata依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/io.seata/seata-spring-boot-starter -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.5.2</version>
</dependency>
服务端yml配置文件(高版本中将file.conf等文件都集成到了yml中)
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${user.home}/logs/seata
extend:
logstash-appender:
destination: 127.0.0.1:4560
kafka-appender:
bootstrap-servers: 127.0.0.1:9092
topic: logback_to_logstash
console:
user:
username: seata
password: seata
seata:
service:
vgroup-mapping:
default-tx-group: default
# grouplist:
# default: 127.0.0.1:8091
enable-degrade: false
disable-global-transaction: false
config:
# support: nacos, consul, apollo, zk, etcd3
type: nacos
nacos:
server-addr: 127.0.0.1:8848
#namespace: 4a5bdb96-a1a7-4a29-b0e0-ea14a0ffa083
group: SEATA_GROUP
username: nacos
password: nacos
##if use MSE Nacos with auth, mutex with username/password attribute
#access-key: ""
#secret-key: ""
#data-id: seataServer.properties
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: nacos
preferred-networks: 30.240.*
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
#namespace: 4a5bdb96-a1a7-4a29-b0e0-ea14a0ffa083
cluster: default
username: nacos
password: nacos
##if use MSE Nacos with auth, mutex with username/password attribute
#access-key: ""
#secret-key: ""
store:
# support: file 、 db 、 redis
mode: db
session:
mode: db
lock:
mode: db
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.48.3:3306/cloud?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
user: root
password: root
min-conn: 5
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 100
max-wait: 5000
# server:
# service-port: 8091 #If not configured, the default is '${server.port} + 1000'
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
客户端yml配置文件(高版本中将file.conf等文件都集成到了yml中)
server:
port: 2002
spring:
application:
name: seata-storage-service
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/seata_storage?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: root
feign:
hystrix:
enabled: false
logging:
level:
io:
seata: info
mybatis:
mapperLocations: classpath:mapper/*.xml
seata:
application-id: ${spring.application.name}
enabled: true
tx-service-group: default-tx-group #事务组名称
service:
vgroup-mapping:
default-tx-group: default
config:
type: nacos
nacos:
group: SEATA_GROUP
server-addr: 127.0.0.1:8848
username: nacos
password: nacos
registry:
type: nacos
nacos:
application: seata-server
server-addr: localhost:8848
username: nacos
password: nacos
cluster: default
group: SEATA_GROUP
enable-auto-data-source-proxy: false
其中特别要注意事务组名称tx-service-group: default-tx-group一定要和服务端的一致
seata:
service:
vgroup-mapping:
default-tx-group: default #事务组名称
如下
注意
- 当seata回滚失败的时候会将错误信息记录在\seata-server-1.5.2\seata\bin\file_store\data\root.data下,清除里边信息才不会报错
- nacos为内置derby数据库时,是不支持多用户访问,必须将其他服务停掉才能重启nacos
- 配置文件将mode改为db无效时,看\seata-server-1.5.2\seata\lib\jdbc下jar包和使用的版本是否正确,seata自己的jar包是5的版本,两个版本不能共存
- 如果配置了config到nacos,一定要注意将config.txt的值上传到nacos的配置文件的值是否相同(我就遇到明明yml中配置了db却无法写入db,走的还是默认的file)