使用docker运行seata-server:1.0.0

本文档使用docker容器运行seata-server:1.0.0版本,并以nacos作为注册中心与配置中心,使用mysql作为seata数据库

3.1 docker 拉取seata-server:1.0.0镜像

1 docker pull seataio/seata-server:1.0.0

3.2 查看镜像是否拉取成功

1 docker image ls

3.3 docker启动seata-server

1 docker run --name seata-server -p 8091:8091 -d  seataio/seata-server:1.0.0

3.4 将nacos-config导入到nacos配置中心,需要注意的是seata-server:1.0.0的容器中并没有关于nacos的配置文件,所以这里在github中将对应的配置下载下来供大家使用。 

nacos-config.sh:将以下内容保存至sh文件,txt中的配置推向nacos配置中心的脚本

#!/usr/bin/env bash
if [ $# != 1 ]; then
echo "./nacos-config.sh nacosIp"
exit -1
fi
nacosIp=$1
echo "set nacosIp=$nacosIp"
error=0
for line in $(cat nacos-config.txt)
do
key=${line%%=*}
value=${line#*=}
echo "\r\n set "${key}" = "${value}
result=`curl -X POST "http://$nacosIp:8848/nacos/v1/cs/configs?dataId=$key&group=SEATA_GROUP&content=$value"`
if [ "$result"x == "true"x ]; then
  echo "\033[42;37m $result \033[0m"
else
  echo "\033[41;37 $result \033[0m"
  let error++
fi
done
if [ $error -eq 0 ]; then
echo  "\r\n\033[42;37m init nacos config finished, please start seata-server. \033[0m"
else
echo  "\r\n\033[41;33m init nacos config fail. \033[0m"
fi

nacos-config.txt:seata的配置,这里已经将对应的数据库配置修改掉了,如果配置有变的话只需要修改对应的配置项就可以,配置项默认被推到public命名空间,后续只需要将这些配置克隆到自己的命名空间就可以了

transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.thread-factory.boss-thread-prefix=NettyBoss
transport.thread-factory.worker-thread-prefix=NettyServerNIOWorker
transport.thread-factory.server-executor-thread-prefix=NettyServerBizHandler
transport.thread-factory.share-boss-worker=false
transport.thread-factory.client-selector-thread-prefix=NettyClientSelector
transport.thread-factory.client-selector-thread-size=1
transport.thread-factory.client-worker-thread-prefix=NettyClientWorkerThread
transport.thread-factory.boss-thread-size=1
transport.thread-factory.worker-thread-size=8
transport.shutdown.wait=3
service.vgroup_mapping.seata_yanwu_base=default
service.vgroup_mapping.seata_yanwu_file=default
service.vgroup_mapping.seata_yanwu_device=default
service.enableDegrade=false
service.disable=false
service.max.commit.retry.timeout=-1
service.max.rollback.retry.timeout=-1
client.async.commit.buffer.limit=10000
client.lock.retry.internal=10
client.lock.retry.times=30
store.mode=db
store.file.dir=file_store/data
store.file.max-branch-session-size=16384
store.file.max-global-session-size=512
store.file.file-write-buffer-cache-size=16384
store.file.flush-disk-mode=async
store.file.session.reload.read_size=100
store.db.datasource=dbcp
store.db.driver-class-name=com.mysql.jdbc.Driver
store.db.db-type=mysql
store.db.url=jdbc:mysql://192.168.0.177:3306/seata?useUnicode=true
store.db.user=root
177
store.db.min-conn=1
store.db.max-conn=3
store.db.global.table=global_table
store.db.branch.table=branch_table
store.db.query-limit=100
store.db.lock-table=lock_table
recovery.committing-retry-period=1000
recovery.asyn-committing-retry-period=1000
recovery.rollbacking-retry-period=1000
recovery.timeout-retry-period=1000
transaction.undo.data.validation=true
transaction.undo.log.serialization=jackson
transaction.undo.log.save.days=7
transaction.undo.log.delete.period=86400000
transaction.undo.log.table=undo_log
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registry-type=compact
metrics.exporter-list=prometheus
metrics.exporter-prometheus-port=9898

将这两个文件拿到服务器中,然后执行下面的命令,就可以将配置推到nacos

1 sh nacos-config.sh 192.168.0.177
2 ### 192.168.0.177 为nacos的服务器地址

3.5  进入seata-server容器

1 docker exec -ti seata-server sh

3.6 修改seata的配置

1 vi resources/registry.conf

将文件改为如下内容

registry {
  type = "nacos"
  nacos {
    serverAddr = "192.168.0.177:8848"
    namespace = "e02de5de-d737-45d5-af22-ae87d0137308"
    cluster = "default"
  }
}
config {
  type = "nacos"
  nacos {
    serverAddr = "192.168.0.177:8848"
    namespace = "e02de5de-d737-45d5-af22-ae87d0137308"
    group = "SEATA_GROUP"
  }
}

3.7  重启seata-server容器

1 docker restart seata-server

3.8 在seata配置的数据库中数据库执行以下SQL语句,创建seata所需要的表

-- the table to store GlobalSession data
drop table if exists `global_table`;
create table `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(64),
  `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`)
);

-- the table to store BranchSession data
drop table if exists `branch_table`;
create table `branch_table` (
  `branch_id` bigint not null,
  `xid` varchar(128) not null,
  `transaction_id` bigint ,
  `resource_group_id` varchar(32),
  `resource_id` varchar(256) ,
  `lock_key` varchar(128) ,
  `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`)
);

-- the table to store lock data
drop table if exists `lock_table`;
create table `lock_table` (
  `row_key` varchar(128) not null,
  `xid` varchar(96),
  `transaction_id` long ,
  `branch_id` long,
  `resource_id` varchar(256) ,
  `table_name` varchar(32) ,
  `pk` varchar(32) ,
  `gmt_create` datetime ,
  `gmt_modified` datetime,
  primary key(`row_key`)
);

相关推荐