spring cloud seata 环境搭建(docker)


spring cloud seata 环境搭建(docker)

 

官网:https://seata.io/zh-cn/docs/ops/deploy-by-docker.html

 

************************

相关操作

 

下载镜像

docker pull seataio/seata-server

 

创建容器

 docker run --name seata-server -p 8091:8091 seataio/seata-server

 

seata-server 环境变量(均为可选)

seata_ip:指定启动ip

seata_port:指定seata-server启动端口,默认为8091

store_mode:seata-server日志存储模式,可为file、db,默认为file

server_node:seata-server节点id,默认为1

seata_env:运行环境,dev、test,如指定dev,启动时会使用registry-dev.conf文件

seata_config_name:配置文件名称,如seata_config_name=file:/root/registry,启动时加载root/registry.conf

 

 

************************

使用consul 做注册、配置中心,db存储日志

 

配置文件:registry.conf

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "consul"

  consul {
    cluster = "default"
    serverAddr = "192.168.57.21:8500"
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "consul"

  consul {
    serverAddr = "192.168.57.21:8500"
  }
}

 

配置参数:config.txt

transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.shutdown.wait=3
transport.compressor=none
transport.serialization=seata
transport.enableClientBatchSendRequest=false

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=8

service.enableDegrade=false
service.disableGlobalTransaction=false
service.vgroupMapping.my_test_tx_group=default

client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.rm.reportSuccessEnable=true
client.rm.asynCommitBufferLimit=10000

store.mode=db

store.file.sessionReloadReadSize=100
store.file.file-write-buffer-cache-size=16384
store.file.flush-disk-mode=async

store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://192.168.57.20:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
store.db.user=root
store.db.password=123456
store.db.minConn=1
store.db.maxConn=3
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table

server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1

server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000

client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.logTable=undo_log
client.log.exceptionRate=100

metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheus-port=9898

seata.enabled=true
seata.enableAutoDataSourceProxy=true

 

参数同步到配置中心:consul-config.sh

contentType="content-type:application/json;charset=UTF-8"

consulAddr=$2:$4
echo "Set consulAddr=$consulAddr"

function addConfig() {
  curl -X PUT -H ${1} -d ${2} "http://$3/v1/kv/$4"
}

for line in $(cat ${5}); do
  key=${line%=*}
  value=${line#*=}
  addConfig ${contentType} ${value} ${consulAddr} ${key}
done

echo "配置参数添加完成"

 

数据库表(数据库名seata):global_table、branch_table、lock_table

-- -------------------------------- 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,
    `gmt_modified`      DATETIME,
    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;

 

 

************************

相关操作

 

创建容器

#consul
docker run -it -d --net fixed3 --ip 192.168.57.21 -p 8500:8500 --name consul \
consul agent -server -node node-1 -ui -bootstrap-expect 1 -client=0.0.0.0

#mysql
docker run -it -d --net fixed --ip 192.168.57.20 -p 3306:3306 \
--privileged=true -e  MYSQL_ROOT_PASSWORD=123456 --name mysql mysql:5.7

#seata
docker run -it -d --net fixed3 --ip 192.168.57.22 -p 8091:8091 \
-v /usr/seata/registry.conf:/seata-server/resources/registry.conf \
--name seata seataio/seata-server

 

参数同步到consul中

./consul-config.sh -h 192.168.57.21 -p 8500 config.txt

 

************************

相关输出

 

seata启动日志

        spring cloud seata 环境搭建(docker)_第1张图片

        spring cloud seata 环境搭建(docker)_第2张图片

 

consul注册服务

        spring cloud seata 环境搭建(docker)_第3张图片

 

consul kv 存储参数

        spring cloud seata 环境搭建(docker)_第4张图片

 

 

你可能感兴趣的:(spring,cloud,事务)