下载安装:https://github.com/apache/incubator-seata/releases
解压:
tar -zxvf seata-server-1.7.0.tar.gz
bin 启动文件
conf 配置文件
备注:
早起版本conf有什么register.conf,config.conf等,当前版本没有,采用yml配置(这是我配置好的文件)
主要修改seata.config 和 seata.register
config: 就是seata-server启动的配置文件,比如seata-server依赖mysql
type:nacos 表示配置文件由nacos管理
其他就是nacos的配置
data-id:指向nacos的配置,比如我配置了seata.properties
详细配置:
#Transaction storage configuration, only for the server. The file, DB, and redis configuration values are optional.
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://10.3.50.123:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=Unilumin123*
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
register:表示将seata-server注册地址
cluster:表示nacos集群名称
找一个nacos服务,需要知道四个:namespace,group,serverName,cluster-name
还有一个事就是搞4张表,global_table,branch_table,distributed_lock,lock_table(这个自己找一下叭)
至此seata-server环境准备好了
启动:
sh seata-server.sh
详细日志:(可以看到启动模式 store mode:db)
可以作妖一下,改一下nacos中的seata.properties文件,比如随便写一个mysql地址,再重启seata-server,可以看到是失败的,说明seata-server启动用了nacos中的配置文件
重启方式,可以通过 ps -aux | grep seata 查看进程id,然后通过kill 命令把进程杀死
准备一个springboot服务
pom依赖(其他依赖自己搞一下,比如nacos等)
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-seata -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>2021.1</version>
<!--版本过低,排除后手动引入新版本-->
<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.7.0</version>
</dependency>
yml配置(seata相关配置)
# Seata 配置
seata:
registry:
type: nacos
nacos:
# Nacos 服务地址
server-addr: ${spring.cloud.nacos.discovery.server-addr}
group: SEATA_GROUP
namespace: ""
application: seata-server # 必须和服务器配置一样
username: nacos
password: nacos
tx-service-group: seata-demo
service:
vgroup-mapping:
seata-demo: unilumin # 必须和服务器配置一样
tx-service-group:自定义名称,不过需要在vgroup-mapping做映射
将自定义名称seata-demo映射到nacos 集群名称上,需要与seate-server配置register.cluster一样
启动服务,可以看到RM注册到seata-server
seata-server日志:
至此seata-server单机版环境搭建成功,后续就可以做各种模式测试了
主要是教程都是早期版本,因此就有了本篇教程