docker部署seata1.6.0

news/2024/12/29 12:59:17/

docker部署seata1.6.0

Seata 是 阿里巴巴 开源的 分布式事务中间件,解决 微服务 场景下面临的分布式事务问题。需要先搭建seata服务端然后与springcloud的集成以实现分布式事务控制的过程 ,项目中只需要在远程调用APi服务的方法上使用注解 @GlobalTransactional,就能实现跨模块事务回滚。

一、安装seata1.6.0

docker pull seataio/seata-server:1.6.0
# 启动容器
docker run -d --name seata-server -p 8091:8091 -p 7091:7091  seataio/seata-server:1.6.0
# 拷贝文件到宿主机目录/opt/seata/seata-server(这个目录需要先手动创建)
cd /opt
mkdir seata
cd /opt/seata
mkdir seata-server
docker cp seata-server:/seata-server/resources  /opt/seata/seata-server/
# 停止并删除容器
docker stop seata-server
docker rm seata-server
# 修改/opt/seata/seata-server/resources目录下的文件application.yml
# 重新启动容器
docker run -i -t -d --restart always --name seata-server \
-p 7091:7091 -p 8091:8091  \
-e SEATA_IP=192.168.124.11 \
-e SEATA_PORT=8091 \
-e TZ=Asia/Shanghai  \
-v /opt/seata/seata-server/resources:/seata-server/resources \
-v /etc/localtime:/etc/localtime \
seataio/seata-server:1.6.0# -e SEATA_IP=[公网IP] 这个ip必须是公网ip,否则会访问失败

在这里插入图片描述

二、修改配置文件application.yml

  • 修改控制台登录账号密码
console:user:username: seata11password: 123456
  • 修改type=nacos
  • 修改nacos连接的账号密码
  • 修改数据库连接
#  Copyright 1999-2019 Seata.io Group.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.server:port: 7091spring:application:name: seata-serverlogging:config: classpath:logback-spring.xmlfile:path: ${user.home}/logs/seataextend:logstash-appender:destination: 127.0.0.1:4560kafka-appender:bootstrap-servers: 127.0.0.1:9092topic: logback_to_logstashconsole:user:username: seata11password: 123456
seata:config:# support: nacos, consul, apollo, zk, etcd3type: nacosnacos:server-addr: 192.168.124.11:8848namespace: eca990b0-5481-4f9e-b4d0-f2a517bb26778group: SEATA_GROUPusername: rootpassword: 123456#context-path:##if use MSE Nacos with auth, mutex with username/password attribute#access-key: ""#secret-key: ""data-id: seataServer.propertiesregistry:# support: nacos, eureka, redis, zk, consul, etcd3, sofatype: nacospreferred-networks: 30.240.*nacos:application: seata-serverserver-addr: 192.168.124.11:8848group: SEATA_GROUPnamespace: eca990b0-5481-4f9e-b4d0-f2a517bb26778cluster: defaultusername: rootpassword: 123456#context-path:##if use MSE Nacos with auth, mutex with username/password attribute#access-key: ""#secret-key: ""store:# support: file 、 db 、 redismode: dbsession:mode: dblock:mode: dbfile:dir: sessionStoremax-branch-session-size: 16384max-global-session-size: 512file-write-buffer-cache-size: 16384session-reload-read-size: 100flush-disk-mode: asyncdb:datasource: druiddb-type: mysqldriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://192.168.124.11:3306/seata_db?rewriteBatchedStatements=trueuser: rootpassword: 123456min-conn: 5max-conn: 100global-table: global_tablebranch-table: branch_tablelock-table: lock_tabledistributed-lock-table: distributed_lockquery-limit: 100max-wait: 5000server:service-port: 8091 #If not configured, the default is '${server.port} + 1000security:secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017tokenValidityInMilliseconds: 1800000ignore:urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

三、nacos中创建配置文件seataServer.properties

在这里插入图片描述

  • seataServer.properties
  • 修改service.vgroupMapping.mygroup=default

#For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html
#Transport configuration, for client and server
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.rpcRmRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
transport.serialization=seata
transport.compressor=none#Transaction routing rules configuration, only for the client
# 此处的mygroup名字可以自定义,只修改这个值即可,
# 需要在nacos中配置dataId为service.vgroupMapping.mygroup,配置格式:为txt,内容为default
service.vgroupMapping.mygroup=default
#If you use a registry, you can ignore it
service.default.grouplist=192.168.124.11:8091
service.enableDegrade=false
service.disableGlobalTransaction=false#Transaction rule configuration, only for the client
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=true
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.sagaJsonParser=fastjson
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
#For TCC transaction mode
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h#Log rule configuration, for client and server
log.exceptionRate=100#Transaction storage configuration, only for the server. The file, db, and redis configuration values are optional.
# 默认为file,一定要改为db,我们自己的服务启动会连接不到seata
store.mode=db
store.lock.mode=db
store.session.mode=db
#Used for password encryption#These configurations are required if the `store mode` is `db`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.
# 修改mysql的配置# 数据存储方式,db代表数据库
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://192.168.124.11:3306/seata_db?useUnicode=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
store.db.user=root
store.db.password=123456
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
# 事务、日志等配置#Transaction rule configuration, only for the server
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.distributedLockExpireTime=10000
server.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.enableParallelRequestHandle=false#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

四、nacos中配置service.vgroupMapping.mygroup

在这里插入图片描述

五、项目中配置seata

  • bootstrap.yml中配置

seata:application-id: ${spring.application.name}#数据源代理模式使用AT模式(可以不用配置,seata默认使用AT模式)data-source-proxy-mode: ATtx-service-group: mygroup # 事务分组名称,要和服务端对应#事务群组(可以每个应用独立取名,也可以使用相同的名字),#要与服务端nacos配置seataServer.properties中service.vgroupMapping.mygroup=default中存在,#此处的mygroup名字可以自定义,与 tx-service-group: mygroup中的mygroup保持一致service:vgroup-mapping:mygroup: defaultenabled: falseregistry:type: nacosnacos:username: rootpassword: 123456namespace: @nacos.config.namespace@server-addr: @nacos.server-addr@group: SEATA_GROUP#seata服务名application: seata-serverconfig:type: nacosnacos:username: rootpassword: 123456namespace: @nacos.config.namespace@server-addr: @nacos.server-addr@group: SEATA_GROUP

六、导入seata数据库

  • seata-server-1.6.0下载地址:https://github.com/apache/incubator-seata/tags
    在这里插入图片描述

  • 数据库脚本目录: \seata-server-1.6.0\seata\script\server\db
    在这里插入图片描述
    在这里插入图片描述

  • 配置完后重启seata容器 docker restart seata-server

  • 项目中就可以使用分布式事务了


http://www.ppmy.cn/news/1359279.html

相关文章

代码随想录算法训练营第36天| Leetcode 435. 无重叠区间、763.划分字母区间、56. 合并区间

文章目录 Leetcode 435. 无重叠区间Leetcode 763.划分字母区间Leetcode 56. 合并区间 Leetcode 435. 无重叠区间 题目链接: Leetcode 435. 无重叠区间 题目描述: 给定一个区间的集合 intervals ,其中 intervals[i] [starti, endi] 。返回需…

【鸿蒙 HarmonyOS 4.0】开发工具安装

一、准备开发环境 1.1、安装IDE 鸿蒙应用开发需要使用配套的IDE——HUAWEI DevEco Studio。 DevEco Studio基于IntelliJ IDEA Community(IDEA社区版)构建,为鸿蒙应用提供了一站式开发环境,集成了开发、运行、调试以及发布应用的…

腾讯云OSS文件上传功能

腾讯云COS介绍 腾讯云COS(Cloud Object Storage)是一种基于对象的存储服务,用于存储和管理海量的非结构化数据,如图片、音视频文件、备份数据等。它具有以下特点和优势: 高可靠性:采用分布式存储架构&…

【2024软件测试面试必会技能】Charles(5):Charles设置过滤

设置过滤 一、只展示window/mac上的指定网址 方法一:右击域名——Focus——可针对该域名以外的其他域名都进行过滤,只展示该域名的请求数据。如下图: 方法二: 在Filter输入框中输入指定域名对其他的进行过滤;只展示指…

代码随想录 -- 字符串

文章目录 反转字符串描述题解 反转字符串II描述题解 替换数字描述题解:replace函数题解:双指针 翻转字符串里的单词描述题解 右旋字符串描述题解 实现 strStr()描述题解:暴力算法题解:KMP算法(懵懂) 重复的子字符串描述题解题解&a…

PyTorch使用Tricks:学习率衰减 !!

文章目录 前言 1、指数衰减 2、固定步长衰减 3、多步长衰减 4、余弦退火衰减 5、自适应学习率衰减 6、自定义函数实现学习率调整:不同层不同的学习率 前言 在训练神经网络时,如果学习率过大,优化算法可能会在最优解附近震荡而无法收敛&#x…

Redis部署方式(一)四种部署方式介绍

redis的四种部署方式: Redis单机模式部署、Redis主从模式部署、Redis哨兵模式部署、Cluster集群模式部署,后面三种(主从模式,Sentinel哨兵模式,Cluster模式)也可以统称为集群模式。 一、单机 1、缺点&…

TypeScript学习笔记-基础

一、type 和 interface type和 interface的区别:TypeScript 中文网: 文档 - 日常类型 type类型别名和interface接口非常相似,在很多情况下可以在它们之间自由选择。interface 的几乎所有功能都在 type 中可用,主要区别在于无法重新打开类型…