使用docker运行seata-server:1.0.0

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

1.1 docker 拉取seata-server:1.0.0镜像

1 docker pull seataio/seata-server:1.0.0

1.2 查看镜像是否拉取成功

1 docker image ls

1.3 docker启动seata-server

1 docker run --name seata-server -p 8091:8091 -e SEATA_IP=192.168.0.177 -e SEATA_PORT=8091 -d  seataio/seata-server:1.0.0

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

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

 1 #!/usr/bin/env bash
 2 if [ $# != 1 ]; then
 3 echo "./nacos-config.sh nacosIp"
 4 exit -1
 5 fi
 6 nacosIp=$1
 7 echo "set nacosIp=$nacosIp"
 8 error=0
 9 for line in $(cat nacos-config.txt)
10 do
11 key=${line%%=*}
12 value=${line#*=}
13 echo "\r\n set "${key}" = "${value}
14 result=`curl -X POST "http://$nacosIp:8848/nacos/v1/cs/configs?dataId=$key&group=SEATA_GROUP&content=$value"`
15 if [ "$result"x == "true"x ]; then
16   echo "\033[42;37m $result \033[0m"
17 else
18   echo "\033[41;37 $result \033[0m"
19   let error++
20 fi
21 done
22 if [ $error -eq 0 ]; then
23 echo  "\r\n\033[42;37m init nacos config finished, please start seata-server. \033[0m"
24 else
25 echo  "\r\n\033[41;33m init nacos config fail. \033[0m"
26 fi

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

 1 transport.type=TCP
 2 transport.server=NIO
 3 transport.heartbeat=true
 4 transport.thread-factory.boss-thread-prefix=NettyBoss
 5 transport.thread-factory.worker-thread-prefix=NettyServerNIOWorker
 6 transport.thread-factory.server-executor-thread-prefix=NettyServerBizHandler
 7 transport.thread-factory.share-boss-worker=false
 8 transport.thread-factory.client-selector-thread-prefix=NettyClientSelector
 9 transport.thread-factory.client-selector-thread-size=1
10 transport.thread-factory.client-worker-thread-prefix=NettyClientWorkerThread
11 transport.thread-factory.boss-thread-size=1
12 transport.thread-factory.worker-thread-size=8
13 transport.shutdown.wait=3
14 service.vgroup_mapping.seata_yanwu_base=default
15 service.vgroup_mapping.seata_yanwu_file=default
16 service.vgroup_mapping.seata_yanwu_device=default
17 service.enableDegrade=false
18 service.disable=false
19 service.max.commit.retry.timeout=-1
20 service.max.rollback.retry.timeout=-1
21 client.async.commit.buffer.limit=10000
22 client.lock.retry.internal=10
23 client.lock.retry.times=30
24 store.mode=db
25 store.file.dir=file_store/data
26 store.file.max-branch-session-size=16384
27 store.file.max-global-session-size=512
28 store.file.file-write-buffer-cache-size=16384
29 store.file.flush-disk-mode=async
30 store.file.session.reload.read_size=100
31 store.db.datasource=dbcp
32 store.db.driver-class-name=com.mysql.jdbc.Driver
33 store.db.db-type=mysql
34 store.db.url=jdbc:mysql://192.168.0.177:3306/seata?useUnicode=true
35 store.db.user=root
36 store.db.password=yanwu121318
37 store.db.min-conn=1
38 store.db.max-conn=3
39 store.db.global.table=global_table
40 store.db.branch.table=branch_table
41 store.db.query-limit=100
42 store.db.lock-table=lock_table
43 recovery.committing-retry-period=1000
44 recovery.asyn-committing-retry-period=1000
45 recovery.rollbacking-retry-period=1000
46 recovery.timeout-retry-period=1000
47 transaction.undo.data.validation=true
48 transaction.undo.log.serialization=jackson
49 transaction.undo.log.save.days=7
50 transaction.undo.log.delete.period=86400000
51 transaction.undo.log.table=undo_log
52 transport.serialization=seata
53 transport.compressor=none
54 metrics.enabled=false
55 metrics.registry-type=compact
56 metrics.exporter-list=prometheus
57 metrics.exporter-prometheus-port=9898

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

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

1.5  进入seata-server容器

1 docker exec -ti seata-server sh

1.6 修改seata的配置

1 vi resources/registry.conf

   将文件改为如下内容

 1 registry {
 2   type = "nacos"
 3   nacos {
 4     serverAddr = "192.168.0.177:8848"
 5     namespace = "e02de5de-d737-45d5-af22-ae87d0137308"
 6     cluster = "default"
 7   }
 8 }
 9 config {
10   type = "nacos"
11   nacos {
12     serverAddr = "192.168.0.177:8848"
13     namespace = "e02de5de-d737-45d5-af22-ae87d0137308"
14     group = "SEATA_GROUP"
15   }
16 }

1.7  重启seata-server容器

1 docker restart seata-server

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

 1 -- the table to store GlobalSession data
 2 drop table if exists `global_table`;
 3 create table `global_table` (
 4   `xid` varchar(128)  not null,
 5   `transaction_id` bigint,
 6   `status` tinyint not null,
 7   `application_id` varchar(32),
 8   `transaction_service_group` varchar(32),
 9   `transaction_name` varchar(64),
10   `timeout` int,
11   `begin_time` bigint,
12   `application_data` varchar(2000),
13   `gmt_create` datetime,
14   `gmt_modified` datetime,
15   primary key (`xid`),
16   key `idx_gmt_modified_status` (`gmt_modified`, `status`),
17   key `idx_transaction_id` (`transaction_id`)
18 );
19 
20 -- the table to store BranchSession data
21 drop table if exists `branch_table`;
22 create table `branch_table` (
23   `branch_id` bigint not null,
24   `xid` varchar(128) not null,
25   `transaction_id` bigint ,
26   `resource_group_id` varchar(32),
27   `resource_id` varchar(256) ,
28   `lock_key` varchar(128) ,
29   `branch_type` varchar(8) ,
30   `status` tinyint,
31   `client_id` varchar(64),
32   `application_data` varchar(2000),
33   `gmt_create` datetime,
34   `gmt_modified` datetime,
35   primary key (`branch_id`),
36   key `idx_xid` (`xid`)
37 );
38 
39 -- the table to store lock data
40 drop table if exists `lock_table`;
41 create table `lock_table` (
42   `row_key` varchar(128) not null,
43   `xid` varchar(96),
44   `transaction_id` long ,
45   `branch_id` long,
46   `resource_id` varchar(256) ,
47   `table_name` varchar(32) ,
48   `pk` varchar(32) ,
49   `gmt_create` datetime ,
50   `gmt_modified` datetime,
51   primary key(`row_key`)
52 );

 

posted @ 2020-04-09 14:04  言午12138  阅读(2257)  评论(0编辑  收藏  举报