Seata配置

參考教程
seata 分布式事務的環境搭建與使用
Seata 1.4.0 + nacos配置和使用,超詳細
Seata 1.4.2 的安裝 + Nacos的配置和使用

官網下載地址
本文以v1.4.1為例

1.數據庫及表的創建

創建seata數據庫,創建以下表(右鍵連接-》新建數據庫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_gmt_modified_status` (`gmt_modified`, `status`),KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDBDEFAULT CHARSET = utf8;-- 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 = InnoDBDEFAULT CHARSET = utf8;-- 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),`gmt_create`     DATETIME,`gmt_modified`   DATETIME,PRIMARY KEY (`row_key`),KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDBDEFAULT CHARSET = utf8;

在每一個數據庫中創建undo_log表

-- for AT mode you must to init this sql for you business database. the seata server not need it.
CREATE TABLE IF NOT EXISTS `undo_log`
(`branch_id`     BIGINT       NOT NULL COMMENT 'branch transaction id',`xid`           VARCHAR(128) NOT NULL COMMENT 'global transaction id',`context`       VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',`rollback_info` LONGBLOB     NOT NULL COMMENT 'rollback info',`log_status`    INT(11)      NOT NULL COMMENT '0:normal status,1:defense status',`log_created`   DATETIME(6)  NOT NULL COMMENT 'create datetime',`log_modified`  DATETIME(6)  NOT NULL COMMENT 'modify datetime',UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDBAUTO_INCREMENT = 1DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';

創建業務庫user及表sys_user

CREATE TABLE `sys_user` (`id` int(11) NOT NULL,`user_name` varchar(32) DEFAULT NULL,`post` varchar(32) DEFAULT NULL,`is_delete` char(2) DEFAULT '0',PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

創建業務庫member及表sys_member

CREATE TABLE `sys_member` (`id` int(11) NOT NULL,`member_name` varchar(32) DEFAULT NULL,`integral` decimal(11,0) DEFAULT NULL,`is_delete` char(2) DEFAULT '0',PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2.修改配置文件

下載完成后解壓,進入seata\conf
①修改file.conf
在這里插入圖片描述

②修改registry.conf
在這里插入圖片描述

3.將配置導入到nacos

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=127.0.0.1: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=file
store.lock.mode=file
store.session.mode=file
#Used for password encryption
store.publicKey=#If `store.mode,store.lock.mode,store.session.mode` are not equal to `file`, you can remove the configuration block.
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100#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://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=username
store.db.password=password
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#These configurations are required if the `store mode` is `redis`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `redis`, you can remove the configuration block.
store.redis.mode=single
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.sentinel.sentinelPassword=
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=
store.redis.queryLimit=100#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-config.sh

#!/bin/sh
# 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.while getopts ":h:p:g:t:u:w:" opt
docase $opt inh)host=$OPTARG;;p)port=$OPTARG;;g)group=$OPTARG;;t)tenant=$OPTARG;;u)username=$OPTARG;;w)password=$OPTARG;;?)echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "exit 1;;esac
doneif [ -z ${host} ]; thenhost=localhost
fi
if [ -z ${port} ]; thenport=8848
fi
if [ -z ${group} ]; thengroup="SEATA_GROUP"
fi
if [ -z ${tenant} ]; thentenant=""
fi
if [ -z ${username} ]; thenusername=""
fi
if [ -z ${password} ]; thenpassword=""
finacosAddr=$host:$port
contentType="content-type:application/json;charset=UTF-8"echo "set nacosAddr=$nacosAddr"
echo "set group=$group"urlencode() {length="${#1}"i=0while [ $length -gt $i ]; dochar="${1:$i:1}"case $char in[a-zA-Z0-9.~_-]) printf $char ;;*) printf '%%%02X' "'$char" ;;esaci=`expr $i + 1`done
}failCount=0
tempLog=$(mktemp -u)
function addConfig() {dataId=`urlencode $1`content=`urlencode $2`curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$dataId&group=$group&content=$content&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/nullif [ -z $(cat "${tempLog}") ]; thenecho " Please check the cluster status. "exit 1fiif [ "$(cat "${tempLog}")" == "true" ]; thenecho "Set $1=$2 successfully "elseecho "Set $1=$2 failure "failCount=`expr $failCount + 1`fi
}count=0
COMMENT_START="#"
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); doif [[ "$line" =~ ^"${COMMENT_START}".*  ]]; thencontinueficount=`expr $count + 1`key=${line%%=*}value=${line#*=}addConfig "${key}" "${value}"
doneecho "========================================================================="
echo " Complete initialization parameters,  total-count:$count ,  failure-count:$failCount "
echo "========================================================================="if [ ${failCount} -eq 0 ]; thenecho " Init nacos config finished, please start seata-server. "
elseecho " init nacos config fail. "
fi

修改config.txt中的部分配置
在這里插入圖片描述

config.txt就是seata各種詳細的配置,執行 nacos-config.sh 即可將這些配置導入到nacos,這樣就不需要將file.conf和registry.conf放到我們的項目中了,需要什么配置就直接從nacos中讀取。

將nacos-config.sh文件 copy到seata\conf\目錄下
將config.txt(下載地址: [config-center])copy到seata\目錄下

copy到seata目錄下的原因是能夠使nacos-config.sh腳本讀取到
gitbash下載&安裝

在conf文件夾中右鍵,選擇git bash here
在這里插入圖片描述

sh nacos-config.sh -h 192.168.3.192 -p 8848 -g SEATA_GROUP  -u nacos -w nacos

命令解析:-h -p 指定nacos的端口地址;-g 指定配置的分組,注意,是配置的分組;-t 指定命名空間id(由于設為public,已刪); -u -w指定nacos的用戶名和密碼,同樣,這里開啟了nacos注冊和配置認證的才需要指定。

Git Bash中粘貼文本,我們只需右鍵單擊Git Bash窗口,并選擇“粘貼”。

過程中遇到的問題:please check the cluster status
解決:nacos改為單機啟動

出現如圖信息,說明導入成功
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/212618.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/212618.shtml
英文地址,請注明出處:http://en.pswp.cn/news/212618.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

kubeadm搭建1.20.7版本k8s

資源 服務器名稱ip地址服務master1(2C/4G,cpu核心數要求大于2)192.168.100.10docker、kubeadm、kubelet、kubectl、flannelnode01(2C/2G)192.168.100.30docker、kubeadm、kubelet、kubectl、flannelnode02&#xff08…

windows系統proteus中Ardunio Mega 2560和虛擬機上Ubuntu系統CuteCom進行串口通信

在文章利用proteus實現串口助手和arduino Mega 2560的串口通信-CSDN博客 中,實現了windows系統的proteus中Ardunio Mega 2560和SSCOM通過虛擬串口進行通信。虛擬串口的連接示意圖如下圖所示。 在文章windows系統和虛擬機上ubuntu系統通過虛擬串口進行通信-CSDN博客…

3DMAX關于顯示驅動問題的解決方法大全

3DMAX與顯卡驅動有關的問題主要有以下幾種情況: 1.3DMAX啟動彈出這樣的界面: 2.主工具欄按鈕不顯示,或者鼠標移上去才顯示(刷新問題)。 3.視口菜單不顯示或顯示不全。 問題分析: 首先&#x…

安全基礎從0開始

文章目錄 常見名詞小實戰 網站搭建小實戰抓包模擬器狀態碼返回值網站搭建WEB應用安全漏洞 數據包&封包&信息收集**參考點** 常見名詞 前后端,POC/EXP,Payload/Shellcode,后門/Webshell,木馬/病毒, 反彈&…

ReactNative0.73發布,架構升級與更好的調試體驗

這次更新包含了多種提升開發體驗的改進,包括: 更流暢的調試體驗: 通過 Hermes 引擎調試支持、控制臺日志歷史記錄和實驗性調試器,讓調試過程更加高效順暢。穩定的符號鏈接支持: 簡化您的開發工作流程,輕松將文件或目錄鏈接到其他…

react表單-受控

react - 表單組件 受控組件 表單項中的值(value/checked)受到類組件state中數據來控制,同時還需要綁定一個onChange事件來完成對state中數據的修改 import React, { Component } from react;class AppInput extends Component {// 設置受控組…

基于ssm應急資源管理系統論文

摘 要 現代經濟快節奏發展以及不斷完善升級的信息化技術,讓傳統數據信息的管理升級為軟件存儲,歸納,集中處理數據信息的管理方式。本應急資源管理系統就是在這樣的大環境下誕生,其可以幫助管理者在短時間內處理完畢龐大的數據信息…

排序算法之七:歸并排序(遞歸)

基本思想 基本思想: 歸并排序(MERGE-SORT)是建立在歸并操作上的一種有效的排序算法,該算法是采用分治法(Divide and Conquer)的一個非常典型的應用。將已有序的子序列合并,得到完全有序的序列&#xff1…

C++:this指針

目錄 前言 成員函數返回this指向的對象本身時,為什是返回引用類型? 成員函數返回this對象本身時,內部通常會通過拷貝構造函數來創建一個臨時對象? 總結 前言 c通過提供特殊的對象指針,this指針 指向被調用的成員函…

openssl 常用命令 pkcs12

openssl pkcs12 openssl pkcs12 官方文檔 1. 描述 The pkcs12 command allows PKCS#12 files (sometimes referred to as PFX files) to be created and parsed. PKCS#12 files are used by several programs including Netscape, MSIE and MS Outlook. pkcs12 命令是用來創…

Nodejs 第二十二章(腳手架)

編寫自己的腳手架 那什么是腳手架? 例如:vue-cli Angular CLI Create React App 編寫自己的腳手架是指創建一個定制化的工具,用于快速生成項目的基礎結構和代碼文件,以及提供一些常用的命令和功能。通過編寫自己的腳手架,你可以…

Linux和Windows環境下如何使用gitee?

1. Linux 1.1 創建遠程倉庫 1.2 安裝git sudo yum install -y git 1.3 克隆遠程倉庫到本地 git clone 地址 1.4 將文件添加到git的暫存區(git三板斧之add) git add 文件名 # 將指定文件添加到git的暫存區 git add . # 添加新文件和修改過的…

深入理解HTTP狀態碼及其在Web開發中的應用

在Web開發中,我們經常需要與服務器進行交互,以獲取或發送數據。為了實現這一目標,我們使用HTTP協議。HTTP協議是一種無狀態的、應用層的協議,它定義了客戶端和服務器之間的通信方式。在HTTP協議中,有五種常用的HTTP狀態…

Python高級算法——動態規劃

Python中的動態規劃:高級算法解析 動態規劃是一種解決多階段決策問題的數學方法,常用于優化問題。它通過將問題分解為子問題,并在解決這些子問題的基礎上構建全局最優解。在本文中,我們將深入講解Python中的動態規劃,…

vs2017+qt5.14.2遇到的問題

1、在安裝qt插件后,導入pro文件時,報 msvc-version.conf loaded but QMAKE_MSC_VER isn’t set 修改E:\Qt\Qt5.14.2\5.14.2\msvc2017_64\mkspecs\common\msvc-version.conf文件中添加

RabbitMQ學習筆記10 綜合實戰 實現新商家規定時間內上架商品檢查

配置文件: 記住添加這個。 加上這段代碼,可以自動創建隊列和交換機以及綁定關系。 我們看到了我們創建的死信交換機和普通隊列。 我們可以看到我們隊列下面綁定的交換機。 我們創建一個controller包進行測試: 啟動: 過一段時間會變成死信隊列…

elasticsearch|大數據|elasticsearch的api部分實戰操作以及用戶和密碼的管理

一, 前言 本文主要內容是通過elasticsearch的api來進行一些集群的管理和信息查詢工作,以及elasticsearch用戶的增刪改查和密碼的重設以及重置如何操作 接上文:elasticsearch|大數據|elasticsearch低版本集群的部署安裝和安全增強---密碼設…

SSM與SpringBoot面試題總結

什么是spring?談談你對IOC和AOP的理解。 Spring:是一個企業級java應用框架,他的作用主要是簡化軟件的開發以及配置過程,簡化項目部署環境。 Spring的優點: 1、Spring低侵入設計,對業務代碼的污染非常低。 2、Spring的DI機制將…

FPGA設計時序約束十一、others類約束之Set_Maximum_Time_Borrow

目錄 一、序言 二、Set Maximum Time Borrow 2.1 基本概念 2.2 設置界面 2.3 命令語法 2.4 命令示例 三、參考資料 一、序言 在Vivado的時序約束窗口中,存在一類特殊的約束,劃分在others目錄下,可用于設置忽略或修改默認的時序路徑分析…

IntelliJ IDEA開啟git版本控制的簡單教程

這篇文章想要分享一下怎么在IntelliJ IDEA開啟版本控制,博主使用的是gitee,首先需要安裝git,關于git的安裝這里就不介紹了,很簡單。 目錄 創建git倉庫 創建項目 開啟版本控制 拉取項目 創建git倉庫 首先,需要登錄…