seata部署指南(v1.6.1)

news2024/10/5 20:23:42

Seata 搭建 db模式

  • 版本 V1.6.1
    • 一、 简介
    • 二、下载
    • 三、建表(仅db)
    • 四、配置 seata server 参数
      • 4.1、V1.4.2之前方式
      • 4.2、V1.4.2 之后推荐方式(seataServer.properties)
    • 五、配置Server
      • 5.1、 修改 appplication.yml
        • 5.1.1、 修改 appplication.yml seata.store (db)
        • 5.1.2、 修改 appplication.yml seata.config
        • 5.1.3、 修改 appplication.yml seata.registry
      • 5.2、启动Server
      • 5.3、查看nacos控台台
      • 5.4、访问seata控制台
    • 六、总结
    • 七、参考

版本 V1.6.1

一、 简介

Server端存储模式(store.mode)现有file、db、redis三种(后续将引入raft,mongodb),file模式无需改动,直接启动即可,下面专门讲下db和redis启动步骤。
注: file模式为单机模式,全局事务会话信息内存中读写并持久化本地文件root.data,性能较高;

db模式为高可用模式,全局事务会话信息通过db共享,相应性能差些;(推荐)

redis模式Seata-Server 1.3及以上版本支持,性能较高,存在事务信息丢失风险,请提前配置合适当前场景的redis持久化配置.

二、下载

1、官网 https://seata.io/zh-cn/
2、参考文档:https://seata.io/zh-cn/blog/seata-quick-start.html
3、部署指南:https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html

三、建表(仅db)

全局事务会话信息由3块内容构成,全局事务–>分支事务–>全局锁,对应表global_table、branch_table、lock_table
当前版本支持 3大数据库:mysql、postgresql 、oracle。

  1. 解压缩: seata-1.6.1.tar.gz
  2. mysql初始化脚本:seata/script/server/db/mysql.sql
DROP DATABASE IF EXISTS `sxxc_seata`;

CREATE DATABASE  `sxxc_seata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

USE `sxxc_seata`;
-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_status_gmt_modified` (`status` , `gmt_modified`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(128),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `status`         TINYINT      NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_status` (`status`),
    KEY `idx_branch_id` (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

CREATE TABLE IF NOT EXISTS `distributed_lock`
(
    `lock_key`       CHAR(20) NOT NULL,
    `lock_value`     VARCHAR(20) NOT NULL,
    `expire`         BIGINT,
    primary key (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);

四、配置 seata server 参数

4.1、V1.4.2之前方式

1. 修改config.txt
config.txt位置: seata/seata/script/config-center/config.txt

#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
service.vgroupMapping.default_tx_group=default
#If you use a registry, you can ignore it
service.default.grouplist=172.22.1.190: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.
store.mode=db
store.lock.mode=db
store.session.mode=db
#Used for password encryption
store.publicKey=""

#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.
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://172.22.2.187:3306/sxxc_seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=StQzZ&YW6Kt!PcXP
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
  1. 初始化到nacos脚本

进入目录: cd ./seata/script/config-center

修改config.txt: 具体参考 ”修改config.txt“

sh nacos-config.sh -h 172.22.1.190 -p 8848 -g SEATA_GROUP -t d229c141-52de-4e60-bd4f-216391283c58 -u nacos -w SOPQzj312#!40Cc

-h – nacos ip
-p – nacos 端口
-g – seata-server配置文件 分组名
-t – seata-server配置文件 命名空间ID,当然在此之前需要现在nacos上新建命名空间并记录下命名空间ID
-u – nacos账号
-w – nacos密码

4.2、V1.4.2 之后推荐方式(seataServer.properties)

Seata从v1.4.2版本开始,支持从一个Nacos dataId配置项中获取所有配置信息。所以,在nacos配置中心中新建配置,dataId为 seataServer.properties配置项

  1. 在nacos中 添加dataID:seataServer.properties文件,具体内容还是config.txt中的配置
    在这里插入图片描述
    在这里插入图片描述

五、配置Server

5.1、 修改 appplication.yml

在这里插入图片描述
cd ./seata/conf/application.yml
如下参考:

#  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: 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: xxx
    password: xxx

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: 172.22.1.190:8848
      group: DEFAULT_GROUP
      username: xxx
      password: xxx
      context-path:
      ##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: 172.22.*
    nacos:
      application: seata-server
      server-addr: xxx:8848
      group: test
      cluster: default
      username: nacos
      password: SOPQzj312#!40Cc
      context-path:
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key:
      #secret-key:
  store:
    # support: file 、 db 、 redis
    mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://xxx:3306/sxxc_seata?rewriteBatchedStatements=true
      user: xxx
      password: xxx
      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
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

5.1.1、 修改 appplication.yml seata.store (db)

seata:
  store:
    # support: file 、 db 、 redis
    mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://xxxxx:3306/seata?rewriteBatchedStatements=true
      user: xxxx # mysql的用户名
      password: xxx #mysql的密码
      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

5.1.2、 修改 appplication.yml seata.config

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      group : "SEATA_GROUP"
      namespace: "xxxxx"
      username: "xxx" # nacos的用户名
      password: "xxx"  # nacos的密码

5.1.3、 修改 appplication.yml seata.registry

seata:
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      application: "seata-server"
      serverAddr: 127.0.0.1:8848
      group: "SEATA_GROUP"
      namespace: "xxxxxx"
      username: "xxxx" # nacos的用户名
      password: "xxx" # nacos的密码

5.2、启动Server

进入目录 cd ./seata/bin

sh seata-server.sh -h 172.22.1.190 -p 8091 -m db

5.3、查看nacos控台台

在这里插入图片描述

5.4、访问seata控制台

http://xxx:7091/
在这里插入图片描述

六、总结

seata安装版本是1.6.1,版本不同,安装流程也可能不同,这里的版本需要保持一致

  1. 执行sql创建数据表
  2. 使用脚本添加配置到nacos配置中心
  3. 修改application.yml文件,分别修改store、config、registry相关配置。
  4. 启动服务,成功登陆seata控制台。
  5. 查看nacos控制台,服务列表新增seata服务。

七、参考

Seata新手部署指南

原文地址:https://www.cnblogs.com/jeremylai7/p/16832440.html
原文地址:https://www.yht7.com/news/213351

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/168732.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

文件操作(File类)

文章目录一、初识文件二、File类构造方法常用方法一、初识文件 我们目前是如何存储数据的?弊端是什么? int a 1; int[] arr new int[5];我们这些数据是在内存中存储的,是不能够长久保存的。 那么,我们的计算机当中有没有一块硬件可以长久存储数据…

PostgreSQL(一)Windows安装

目录一、下载二、安装PostgreSQL三、安装StackBuilder四、打开PostgreSQL管理工具pgAdmin五、打开命令行一、下载 下载地址: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads 下载后安装包如下: 二、安装PostgreSQL 双击打开安…

DataX使用入门

DataX 是阿里云 DataWorks数据集成 的开源版本,在阿里巴巴集团内被广泛使用的离线数据同步工具/平台。DataX 实现了包括 MySQL、Oracle、OceanBase、SqlServer、Postgre、HDFS、Hive、ADS、HBase、TableStore(OTS)、MaxCompute(ODPS)、Hologres、DRDS 等各种异构数据…

Java 日志框架 Log4J

文章目录引言什么是Log4JLog4J三大组件Log4J日志级别Log4J基本使用自定义配置文件Appender示例FileAppenderDailyRollingFileAppenderRollingFileAppenderJDBCAppender自定义Logger引言 Java 日志框架 JUL 在这篇文章中已经向大家介绍了我们为什么要使用日志文件、常见的日志…

张力调节(精密调节气阀应用)

跳舞轮对应张力调节范围,我们可以通过改变气缸的气压方式间接改变,张力跳舞轮在收放卷闭环控制上的详细应用,可以参看下面的文章链接,这里我们主要讨论精密可调气阀的模拟量编程问题。 PLC张力控制(开环闭环算法分析&…

【实践向】当移除了三级缓存……

本文会手把手带你一起把使用二级缓存替换三级缓存,看下移除了三级缓存,只有二级缓存会出什么问题,用实践回答那个被问了无数次的“为什么要有三级缓存?”以及“二级缓存解决不了循环依赖问题吗?”等类似问题(&#xff…

“Flash配置不当漏洞”详解

危害 可被用来进行跨域访问,可能会导致“跨站点伪造请求”或“跨站点跟踪”(“跨站点脚本编制”的变体)之类的攻击,从而导致其它用户的信息被非法读取。 导致不受信任的第三方域的flash也能访问当前域的资源,绕过同源策…

一、构建自己的图像分类数据集(Datawhale组队学习)

文章目录安装配置环境图像采集采集函数爬取一类图片爬取多类图片一些参考类别的关键词制作图像分类数据集的注意事项删除多余文件删除系统自动生成的多余文件删除gif格式的图像文件删除非三通道的图像统计图像尺寸、比例分布采用的数据集统计数据集的基本信息可视化图像尺寸分布…

Embarcadero Dev-C++第一次使用注意事项

Embarcadero Dev-C第一次使用注意事项 Embarcadero Dev-C简介 2000年左右,Bloodshed software开发了Dev-C ,提供轻量、免费、开源的C/CIDE。Dev-C是最适合初学C语言的IDE之一,但至2015年Dev C5.11,停止了更新维护了。 后来&…

springboot,vue电影院售票系统

开发工具:IDEA服务器:Tomcat9.0, jdk1.8项目构建:maven数据库:mysql5.7系统用户前台和管理后台两部分,项目采用前后端分离前端技术:vue elementUI服务端技术:springbootmybatis项目功…

pom文件中自定义的repository不生效

问题描述 对应的pom中依赖获取失败 pom文件依赖配置如下: <dependencies><dependency><groupId>it.geosolutions</groupId><artifactId>geoserver-manager</artifactId><version>1.7.0</version><exclusions><excl…

verilog学习笔记- 15)动态数码管显示实验

目录 简介&#xff1a; 实验任务&#xff1a; 硬件设计&#xff1a; 程序设计&#xff1a; 下载验证&#xff1a; 简介&#xff1a; 由于一般的静态驱动操作虽然方便&#xff0c;但占用的 I/0 口较多&#xff0c;例如要驱动6 位 8 段数码管&#xff0c;以静态驱动方式让数…

值得收藏的30道Python基础练手题(附详解)

今天给大家分享30道Python练习题&#xff0c;建议大家先独立思考一下解题思路&#xff0c;再查看答案。 1. 已知一个字符串为 “hello_world_JMzz”&#xff0c;如何得到一个队列 [“hello”,”world”,”JMzz”] &#xff1f; 使用 split 函数&#xff0c;分割字符串&…

ESP8266 ArduinoIDE 闪存文件操作系统

一、闪存文件系统基本操作 esp8266 的采用 SPIFFS 嵌入式文件系统&#xff0c;在内部 Flash 为 4M&#xff0c;其中 1M 用于存储程序&#xff0c;其他的空间有一部分用于系统&#xff0c;3M 中剩下的大部分空间可以用来存放文件。 其中这个空间大小是可以自定义的&#xff0c;…

【Node.js实战】一文带你开发博客项目之安全(sql注入、xss攻击、md5加密算法)

个人简介 &#x1f440;个人主页&#xff1a; 前端杂货铺 &#x1f64b;‍♂️学习方向&#xff1a; 主攻前端方向&#xff0c;也会涉及到服务端 &#x1f4c3;个人状态&#xff1a; 在校大学生一枚&#xff0c;已拿多个前端 offer&#xff08;秋招&#xff09; &#x1f680;未…

Netty进阶

三. Netty 进阶 1. 粘包与半包 1.1 粘包现象 服务端代码 public class HelloWorldServer {static final Logger log LoggerFactory.getLogger(HelloWorldServer.class);void start() {NioEventLoopGroup boss new NioEventLoopGroup(1);NioEventLoopGroup worker new Ni…

想要全面了解DevOps,从概念、实现相关工具到如何落地,看这篇就够了

我们总是在提DevOps&#xff0c;敏捷管理&#xff0c;但大家未必真的明白什么是DevOps。本文是将向大家介绍到底什么是DevOps&#xff0c;DevOps的初衷到底是为了解决什么问题&#xff1f;它能够如何实现&#xff1f;能够带来哪些价值&#xff1f;来让大家对DevOps有一个全面的…

Vscode++Opencv+Anaconda+Python安装教程

最近在学习opencv的时候vscode一直报这个错&#xff1a; Import “cv2” could not be resolved Pylance (reportMissingImports) 但是在Jupyter上面可以运行&#xff0c;一直没找到解决方法&#xff0c;无奈只好重装。 一&#xff1a;安装AnacondaPython 进入Anaconda官网 w…

计网必会:封装、协议、解封装

文章目录解释什么是封装什么是协议解封装是啥封装过程拓展知识需要了解解释 什么是封装 封装就是给初始的数据增加“数据”&#xff0c;让原始数据的信息量扩大&#xff0c;方便层与层间的交流&#xff0c;所谓封装&#xff0c;就是包装的意思&#xff0c;中文博大精深哈哈哈…

03.指针的进阶2.练习题(重点)

1.指针和数组笔试题解析 //1. sizeof(数组名)&#xff0c;数组名表示整个数组。计算的是整个数组的大小,单位是字节 //2. &数组名&#xff0c;数组名表示整个数组。取出的是整个数组的地址 //除此之外&#xff0c;所有的数组名都是数组首元素的地址 EG1:整型 int main…