Seata服务端部署
本文参考官方部署说明文档
系统环境
阿里云ubuntu
Java: openjdk version "1.8.0_382"
Seata:seata-server-1.8.0
下载Seata-server
github下载地址:https://github.com/seata/seata/releases
官网下载地址:https://seata.io/zh-cn/blog/download.html
部署
安装
将下载好的Seata-server存放到指定的工作目录,本文工作目录为/opt,执行命令如下:
mv seata-server-1.8.0.tar.gz /opt
进入工作目录,并解压安装Seata-server,命令如下:
#进入安装目录
cd /opt
#解压安装包
tar -zxvf seata-server-1.8.0.tar.gz
配置
进入Seata的配置目录
cd /opt/seata/conf
配置文件结构
Seata-server是一个基于spring-boot开发的项目,启动配置文件为application.yml,核心配置部分包含seata.config、seata.registry、seata.store三个部分(1.5.x版本之后使用了spring-boot,建议在application.yml中集中配置)。
- seata.config:指定配置中心,提供全局配置,包含seata-server和全局store的相关配置;默认为file,指定读取同配置目录下的file.conf文件。
- seata.registry:指定seata-server服务端的注册中心,1.5.0版本之后seata-server调整为spring-boot,不再读取registry.conf文件
- seata.store:指定事务数据的存储模式。该模块的配置内容与seata.config中store的配置部分重叠;seata.config用于指定全局的事务日志存储配置,seata.store指定当前seata端使用的事务日志存储配置,seata.store配置的优先级高于seata.config。
【application.yml】文件
server:
port: 7091
spring:
application:
name: seata-server
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: file
registry:
# support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa
type: eureka
eureka:
service-url: http://127.0.0.1:8080/eureka
application: ${spring.application.name}
weight: 1
server:
service-port: 8091 #If not configured, the default is '${server.port} + 1000'
max-commit-retry-timeout: -1
max-rollback-retry-timeout: -1
rollback-retry-timeout-unlock-enable: false
enable-check-auth: true
enable-parallel-request-handle: true
retry-dead-threshold: 130000
xaer-nota-retry-timeout: 60000
enableParallelRequestHandle: true
recovery:
committing-retry-period: 1000
async-committing-retry-period: 1000
rollbacking-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
store:
# support: file 、 db 、 redis
mode: db
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true
user: admin
password: "!QAZ2wsx"
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 1000
max-wait: 5000
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: 1015zhoulvyuan0fd57724fb9818439e9810c45619efa3
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**
补充说明:console部分在1.5.x版本后添加,security部分在1.6.x版本之后添加,使用新版本的seata时需要添加这两个部分的配置,否则启动seata会出现读取不到配置的异常。
【file.conf】文件
server {
service-port = 8091 #If not configured, the default is '${server.port} + 1000'
max-commit-retry-timeout = -1
max-rollback-retry-timeout = -1
rollback-retry-timeout-unlock-enable = false
enable-check-auth = true
enable-parallel-request-handle = true
retry-dead-threshold = 130000
xaer-nota-retry-timeout = 60000
enableParallelRequestHandle = true
recovery {
committing-retry-period = 1000
async-committing-retry-period = 1000
rollbacking-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
}
}
store {
# support: file 、 db 、 redis
mode = db
session {
mode = db
}
lock {
mode = db
}
db {
datasource = druid
db-type = mysql
driver-class-name = com.mysql.jdbc.Driver
url = "jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true"
user = admin
password = "!QAZ2wsx"
min-conn = 10
max-conn = 100
global-table = global_table
branch-table = branch_table
lock-table = lock_table
distributed-lock-table = distributed_lock
query-limit = 1000
max-wait = 5000
}
}
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
}
}
数据库脚本
当store.mode选择为db模式时,需要在数据库执行相应的脚本,创建支持事物日志的表。全局事务会话信息由3块内容构成,全局事务-->分支事务-->全局锁,对应表global_table、branch_table、lock_table。
执行脚本可从官方源代码中获取
启动
进入Seata的启动目录
cd /opt/seata/bin
执行启动脚本
sh seata-server.sh
补充说明:我在ubuntu环境下使用sh命令执行脚本会出现语法错误,但是可以使用bash命令执行,解决方案是将sh命令链接到bash
参考文献
seata-server的相关配置可以参考官网参数配置表,不同版本之前配置上存在差异,参考时需要对应到指定版本的配置。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!