最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Docker+nacos+seata1.3.0安裝與使用配置教程

 更新時(shí)間:2021年07月13日 15:23:32   作者:陌生人的魅力  
這篇文章主要介紹了Docker+nacos+seata1.3.0安裝與使用配置教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在此之前我搞了一天,雖然seata好用,用起來(lái)也超級(jí)簡(jiǎn)單,但是安裝配置是真的麻煩,遇見(jiàn)了各種坑,下面來(lái)進(jìn)入正題。o(╥﹏╥)o

一 . 版本

   注意:如果版本不匹配也會(huì)有各種報(bào)錯(cuò),可以根據(jù)官網(wǎng)匹配版本。

seata:1.3.0
alibaba.cloud:2.2.3.RELEASE
nacos:2.0.2

二. docker安裝搭建seata服務(wù)端

         2.1 下載seata鏡像

docker pull seataio/seata-server:1.3.0

        2.2 在Linux目錄下創(chuàng)建registry.conf,我的路徑在/data/seate/registry.conf,接下來(lái)的所有創(chuàng)建都在這個(gè)目錄下

cd /data
mkdir seate
vim registry.conf

        2.3 registry.conf中的內(nèi)容如下

registry {
  type = "nacos"
 
  nacos {
    application = "seata-server"
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    namespace = ""
    cluster = "default"
    username = ""
    password = ""
  }
}
 
config {
  type = "nacos"
 
  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = ""
    password = ""
  }
}

注意registry和config需要在同一個(gè)組下,注冊(cè)中心我用的是nacos,注意nacos的地址要改。

----->>>這里我插一句,需要新建一個(gè)數(shù)據(jù)庫(kù)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 = InnoDB
  DEFAULT 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 = InnoDB
  DEFAULT CHARSET = utf8;
 
-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(96),
    `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 = InnoDB
  DEFAULT CHARSET = utf8;

        實(shí)現(xiàn)分布式每個(gè)業(yè)務(wù)庫(kù)都要加一張表undo_log,不然會(huì)報(bào)錯(cuò),

CREATE TABLE `undo_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主鍵',
  `branch_id` bigint(20) NOT NULL COMMENT 'branch transaction id',
  `xid` varchar(100) 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',
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table';

2.4 創(chuàng)建推送配置文件 vim config.txt,是將文件中的配置推送到nacos中去。

vim config.txt
service.vgroupMapping.btb_tx_group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://172.0.0.1:3306/seata?useUnicode=true
store.db.user=root
store.db.password=root
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000

注意btb_tx_group需要與客戶端保持一致,順便注意數(shù)據(jù)庫(kù)驅(qū)動(dòng),如果是8以上用我的這個(gè)驅(qū)動(dòng),5.7的用com.mysql.jdbc.Driver

        2.5 創(chuàng)建推送腳本,因?yàn)閳?zhí)行腳本要在config.txt的下一層,所有加一層目錄

mkdir sh
cd sh
vim nacos-config.sh

內(nèi)容如下:最好不要有任何的修改

#!/usr/bin/env bash
# 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
do
  case $opt in
  h)
    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
done
 
if [[ -z ${host} ]]; then
    host=localhost
fi
if [[ -z ${port} ]]; then
    port=8848
fi
if [[ -z ${group} ]]; then
    group="SEATA_GROUP"
fi
if [[ -z ${tenant} ]]; then
    tenant=""
fi
if [[ -z ${username} ]]; then
    username=""
fi
if [[ -z ${password} ]]; then
    password=""
fi
 
nacosAddr=$host:$port
contentType="content-type:application/json;charset=UTF-8"
 
echo "set nacosAddr=$nacosAddr"
echo "set group=$group"
 
failCount=0
tempLog=$(mktemp -u)
function addConfig() {
  curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$1&group=$group&content=$2&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null
  if [[ -z $(cat "${tempLog}") ]]; then
    echo " Please check the cluster status. "
    exit 1
  fi
  if [[ $(cat "${tempLog}") =~ "true" ]]; then
    echo "Set $1=$2 successfully "
  else
    echo "Set $1=$2 failure "
    (( failCount++ ))
  fi
}
 
count=0
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
  (( count++ ))
	key=${line%%=*}
    value=${line#*=}
	addConfig "${key}" "${value}"
done
 
echo "========================================================================="
echo " Complete initialization parameters,  total-count:$count ,  failure-count:$failCount "
echo "========================================================================="
 
if [[ ${failCount} -eq 0 ]]; then
	echo " Init nacos config finished, please start seata-server. "
else
	echo " init nacos config fail. "
fi

        2.6 執(zhí)行推送腳本,后面是nacos的ip地址,如果端口不是8848還需要加一個(gè)-p 8884你的端口

bash nacos-config.sh -h 127.0.0.1

        2.7 創(chuàng)建容器,注意SEATA_IP如果是阿里云服務(wù)器需要寫(xiě)外網(wǎng)ip

docker run -d --restart always --name seata-server -p 8091:8091 -e SEATA_IP=172.0.0.1 -e SEATA_CONFIG_NAME=file:/data/seata/registry -v /data/seata:/data/seata  seataio/seata-server:1.3.0

三 . 客戶端(也就是微服務(wù),項(xiàng)目中使用seata)

3.1 pom.xml 引入依賴

<!-- seata分布式事務(wù)-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>io.seata</groupId>
                    <artifactId>seata-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>

注意這里一定要剔除原來(lái)自帶的 io.seata包,并且服務(wù)端和客戶端的包版本要一致。

3.2 配置項(xiàng)目配置文件

#seata
seata.application-id=${spring.application.name}
seata.tx-service-group=btb_tx_group
seata.config.type=nacos
seata.config.nacos.server-addr=172.0.0.1:8848
seata.config.nacos.group=SEATA_GROUP
seata.registry.type=nacos
seata.registry.nacos.application=seata-server
seata.registry.nacos.server-addr=172.0.0.1:8848
seata.registry.nacos.group=SEATA_GROUP

注意:這里的btb_tx_group要跟服務(wù)端的vgroupMapping后面的key保持一致,

如:service.vgroupMapping.btb_tx_group=default

3.3 加入注解使用

@GlobalTransactional

擴(kuò)展: 我用的是一個(gè)數(shù)據(jù)庫(kù),執(zhí)行報(bào)錯(cuò),說(shuō)我缺少主鍵,于是我在表undo_log加了一個(gè)增的主鍵id,上面的創(chuàng)建undo_log表的sql是我加了id的,官方給的是沒(méi)有id的。請(qǐng)知曉?。。?!

問(wèn)題:單數(shù)源是有報(bào)錯(cuò)的,原因是因?yàn)槲沂且粋€(gè)數(shù)據(jù)庫(kù),需要設(shè)置代理配置如下 ,根據(jù)自己實(shí)際情況是指配置文件,不然會(huì)報(bào)錯(cuò)

#單數(shù)據(jù)源
seata.enable-auto-data-source-proxy=true
#多數(shù)據(jù)源
seata.enable-auto-data-source-proxy=false

到此這篇關(guān)于Docker+nacos+seata1.3.0安裝與使用的文章就介紹到這了,更多相關(guān)Docker+nacos+seata安裝使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳細(xì)講解Docker-Compose部署Kafka?KRaft集群環(huán)境

    詳細(xì)講解Docker-Compose部署Kafka?KRaft集群環(huán)境

    這篇文章主要為大家介紹了Docker-Compose部署Kafka?KRaft集群環(huán)境的全面詳細(xì)講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • ubuntu 14.04 64位安裝配置docker教程

    ubuntu 14.04 64位安裝配置docker教程

    這篇文章主要為大家詳細(xì)介紹了ubuntu 14.04 64位安裝配置docker教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • 通過(guò)Docker安裝啟動(dòng)DB2在Spring?Boot整合DB2的方法

    通過(guò)Docker安裝啟動(dòng)DB2在Spring?Boot整合DB2的方法

    DB2是IBM的一款優(yōu)秀的關(guān)系型數(shù)據(jù)庫(kù),這篇文章主要介紹了通過(guò)Docker啟動(dòng)DB2,并在Spring?Boot整合DB2,需要的朋友可以參考下
    2023-01-01
  • 一文學(xué)會(huì)docker?安裝mysql的方法

    一文學(xué)會(huì)docker?安裝mysql的方法

    這篇文章主要介紹了docker?安裝?mysql的方法,通過(guò)使用docker命令下載mysql接著使用docker命令創(chuàng)建實(shí)例并啟動(dòng),對(duì)docker?安裝?mysql相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-04-04
  • docker容器中登陸并操作postgresql的實(shí)現(xiàn)

    docker容器中登陸并操作postgresql的實(shí)現(xiàn)

    本文主要介紹了docker容器中登陸并操作postgresql的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-02-02
  • Docker部署SQL Server 2019 Always On集群的實(shí)現(xiàn)

    Docker部署SQL Server 2019 Always On集群的實(shí)現(xiàn)

    這篇文章主要介紹了Docker部署SQL Server 2019 Always On集群的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Docker Cloud實(shí)現(xiàn)部署應(yīng)用操作詳解

    Docker Cloud實(shí)現(xiàn)部署應(yīng)用操作詳解

    這篇文章主要介紹了Docker Cloud實(shí)現(xiàn)部署應(yīng)用操作,較為詳細(xì)的分析了Docker Cloud部署應(yīng)用的步驟、命令、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2018-06-06
  • 關(guān)于Docker容器內(nèi)部無(wú)法解析域名問(wèn)題的解決

    關(guān)于Docker容器內(nèi)部無(wú)法解析域名問(wèn)題的解決

    最近工作中遇到一個(gè)問(wèn)題,項(xiàng)目?jī)?nèi)部需要訪問(wèn)外網(wǎng),但上傳文件,但是一直報(bào)unknown host,無(wú)法解析域名,所以下面這篇文章主要給大家介紹了關(guān)于Docker容器內(nèi)部無(wú)法解析域名問(wèn)題的解決方法,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-07-07
  • docker run和start的區(qū)別說(shuō)明

    docker run和start的區(qū)別說(shuō)明

    這篇文章主要介紹了docker run和start的區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • 詳解docker-compose.yml文件常用模版命令

    詳解docker-compose.yml文件常用模版命令

    這篇文章主要介紹了docker-compose.yml文件常用模版命令,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2021-11-11

最新評(píng)論

枝江市| 曲水县| 托里县| 朝阳县| 久治县| 玉龙| 涟水县| 眉山市| 潮安县| 朝阳区| 漳平市| 黄大仙区| 百色市| 类乌齐县| 乃东县| 澳门| 巨野县| 资中县| 金堂县| 花垣县| 修武县| 马尔康县| 陇西县| 红原县| 广水市| 全南县| 德昌县| 孟津县| 宜春市| 绿春县| 九江县| 汤阴县| 五指山市| 萍乡市| 上高县| 沈阳市| 宜兰县| 南丹县| 凤阳县| 芷江| 土默特右旗|