seata部署指南(v1.6.1)

Seata 搭建 db模式

版本 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中的配置
    seata部署指南(v1.6.1)
    seata部署指南(v1.6.1)

; 五、配置Server

5.1、 修改 appplication.yml

seata部署指南(v1.6.1)
cd ./seata/conf/application.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: xxx
    password: xxx

seata:
  config:

    type: nacos
    nacos:
      server-addr: 172.22.1.190:8848
      group: DEFAULT_GROUP
      username: xxx
      password: xxx
      context-path:

      data-id: seataServer.properties
  registry:

    type: nacos
    preferred-networks: 172.22.*
    nacos:
      application: seata-server
      server-addr: xxx:8848
      group: test
      cluster: default
      username: nacos
      password: SOPQzj312
      context-path:

  store:

    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:

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

    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      group : "SEATA_GROUP"
      namespace: "xxxxx"
      username: "xxx"
      password: "xxx"
5.1.3、 修改 appplication.yml seata.registry
seata:
  registry:

    type: nacos
    nacos:
      application: "seata-server"
      serverAddr: 127.0.0.1:8848
      group: "SEATA_GROUP"
      namespace: "xxxxxx"
      username: "xxxx"
      password: "xxx"

5.2、启动Server

进入目录 cd ./seata/bin

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

5.3、查看nacos控台台

seata部署指南(v1.6.1)

; 5.4、访问seata控制台

http://xxx:7091/

seata部署指南(v1.6.1)

六、总结

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

Original: https://blog.csdn.net/sanduo112/article/details/128715912
Author: sanduo112
Title: seata部署指南(v1.6.1)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/812730/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 数据结构——链表

    1.什么是链表 链表是一种物理存储结构上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。 2.节点 节点维护变量data和next,分别用于存储数据和…

    Python 2023年6月12日
    076
  • pythonresponse对象的属性_Scrapy中response属性以及内容提取

    Python Python开发 Python语言 Scrapy中response属性以及内容提取 一.属性 url :HTTP响应的url地址,str类型 status:HTTP响…

    Python 2023年10月3日
    039
  • scrapy python proxy unsolved_Python基于scrapy采集数据时使用代理服务器的方法

    本文实例讲述了python基于scrapy采集数据时使用代理服务器的方法。分享给大家供大家参考。具体如下: # To authenticate the proxy, you mus…

    Python 2023年10月6日
    032
  • Scrapy了解

    Scrapy简介 Scrapy是适用于Python的一个快速、高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据。 1 Scrapy Engine(Sc…

    Python 2023年10月6日
    036
  • checkbox勾选带动画

    csharp;gutter:true; Checkbox复选框动画效果</p> <pre><code> Morning Noon Afterno…

    Python 2023年6月10日
    070
  • 前端之JavaScript—BOM和DOM

    一、BOM和DOM概述 通过之前的两篇文章,相信大家已经掌握了JavaScript的一些简单的语法。但是这些简单的语法,并没有和浏览器有任何交互。也就是我们还不能制作一些我们经常看…

    Python 2023年6月6日
    085
  • Node.js基础入门第四天

    经过前面三天的学习,Node.js的基础知识已逐渐掌握,今天继续学习缓存区和文件操作,并稍加整理加以分享,如有不足之处,还请指正。 缓存区 1. 什么是缓存区? JavaScrip…

    Python 2023年6月10日
    074
  • 为了周末带女神一起去看电影,我用Python爬取上万部电影的排名

    Original: https://www.cnblogs.com/pythonQqun200160592/p/15688071.htmlAuthor: python可乐编程Tit…

    Python 2023年5月24日
    072
  • Python中异常处理的用法

    为了保证程序的健壮性和容错性,即程序在遇到错误时不会崩溃,需要对异常进行处理。 [En] In order to ensure the robustness and fault t…

    Python 2023年5月24日
    082
  • vulnhub靶场之LOOZ: 1

    准备: 攻击机:虚拟机kali、本机win10。 靶机:looz: 1,下载地址:https://download.vulnhub.com/looz/Looz.zip,下载后直接v…

    Python 2023年10月13日
    075
  • shell实现文件监控并操作

    linux实现文件监控 shell实现当文件超过设定的大小之后,删除该文件 1. 监控并删除单个文件 设定文件路径 file_dir="文件路径" 取文件大小 …

    Python 2023年6月12日
    075
  • web python 维护性_浅谈如何提高自动化测试的稳定性和可维护性 (pytest&allure)

    序 在之前,我写过一个系列”从零开始搭建一个简单的ui自动化测试框架(pytest+selenium+allure)”,在这个系列里,主要介绍了如何从零开始…

    Python 2023年9月13日
    033
  • Rockchip RK3588 MIPI-DSI2 详解

    Rockchip RK3588 MIPI-DSI2 详解 目录 文章目录 Rockchip RK3588 MIPI-DSI2 详解 * @[toc] Introduction MI…

    Python 2023年9月16日
    0329
  • python从入门到实践13章答案

    系列文章目录 python从入门到实践12章答案 python从入门到实践14章答案 目录 前言 一、13-1星星 二、13-2更逼真的星星 三、13-3雨滴 四、13-4连绵细雨…

    Python 2023年9月19日
    047
  • 涉及区间的查询

    1.找出一系列连续的值 问题:判断哪些行表示一系列连续的项目。即某一行项目开始时间和前一行的项目结束时间是一致的。 示例表: 解决方案:利用窗函数 LEAD OVER 来查找下一行…

    Python 2023年10月23日
    045
  • 前端性能优化

    前端性能优化(考虑方向) 1、Echarts按需加载2、UI库按需加载3、图片压缩(https://tinypng.com/)4、较大的json和图片存放到服务器的静态资源文件夹5…

    Python 2023年11月6日
    032
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球