当前位置: 代码迷 >> 综合 >> Docker 配置 Seata 集成 Nacos
  详细解决方案

Docker 配置 Seata 集成 Nacos

热度:86   发布时间:2023-12-12 01:47:54.0
  1. 运行命令安装seata
docker pull seataio/seata-server
  •  
  1. 运行seata 镜像
docker run --name seata -p 8091:8091 -d  seataio/seata-server
  •  
  1. 创建本地配置文件的文件夹
cd
cd /
cd /home
mkdir dockers
cd dockers
mkdir seata
cd seata
  1. 复制配置文件
docker cp seata:/seata-server  /home/dockers/seata
  •  

此时输入命令 ls 应该能看到如下的文件夹

在这里插入图片描述
5. 停止并删除seata服务

docker stop seata
docker rm seata
  1. 到resources文件夹下修改配置文件registry.conf, 修改完了以后保存退出
sudo vim registry.conf
  •  
registry {# file 、nacos 、eureka、redis、zk、consul、etcd3、sofatype = "nacos"nacos {application = "seata-server"# 这里修改为你的nacos服务器地址serverAddr = "192.168.40.131:8848"# 这里修改为你的namespace,一般默认为publicnamespace = "public"cluster = "default"username = ""password = ""}eureka {serviceUrl = "http://localhost:8761/eureka"application = "default"weight = "1"}redis {serverAddr = "localhost:6379"db = 0password = ""cluster = "default"timeout = 0}zk {cluster = "default"serverAddr = "127.0.0.1:2181"sessionTimeout = 6000connectTimeout = 2000username = ""password = ""}consul {cluster = "default"serverAddr = "127.0.0.1:8500"}etcd3 {cluster = "default"serverAddr = "http://localhost:2379"}sofa {serverAddr = "127.0.0.1:9603"application = "default"region = "DEFAULT_ZONE"datacenter = "DefaultDataCenter"cluster = "default"group = "SEATA_GROUP"addressWaitTime = "3000"}file {name = "file.conf"}
}config {# file、nacos 、apollo、zk、consul、etcd3type = "file"nacos {serverAddr = "172.168.1.35:8848"namespace = "89f54c6f-3b21-46a4-bd1b-242ae159c12e"group = "DEFAULT_GROUP"username = ""password = ""}consul {serverAddr = "127.0.0.1:8500"}apollo {appId = "seata-server"apolloMeta = "http://192.168.1.204:8801"namespace = "application"}zk {serverAddr = "127.0.0.1:2181"sessionTimeout = 6000connectTimeout = 2000username = ""password = ""}etcd3 {serverAddr = "http://localhost:2379"}file {name = "file.conf"}
}
  1. 修改file.conf 配置文件。主要修改mysql的地址,用户名,密码。这里mysql是5.+版本的,使用8+版本的注意修改驱动
store {## store mode: file、dbmode = "db"## file store propertyfile {## store location dirdir = "sessionStore"# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptionsmaxBranchSessionSize = 16384# globe session size , if exceeded throws exceptionsmaxGlobalSessionSize = 512# file buffer size , if exceeded allocate new bufferfileWriteBufferCacheSize = 16384# when recover batch read sizesessionReloadReadSize = 100# async, syncflushDiskMode = async}## database store propertydb {## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.datasource = "druid"## mysql/oracle/postgresql/h2/oceanbase etc.dbType = "mysql"driverClassName = "com.mysql.jdbc.Driver"url = "jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai"user = "root"password = "root"minConn = 5maxConn = 30globalTable = "global_table"branchTable = "branch_table"lockTable = "lock_table"queryLimit = 100maxWait = 5000}
}
  1. 进入mysql,创建数据库seata,然后执行以下sql命令
-- 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(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`)
);-- 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(36) ,`gmt_create` datetime ,`gmt_modified` datetime,primary key(`row_key`)
);
  1. 创建并启动一个新的seata容器,注意:如果你的文件夹不是按照本文创建的话,请将“/home/dockers/seata/resources”改成你自己的registry.conf文件所在地址。
docker run --name seata 
-p 8091:8091 
-e SEATA_CONFIG_NAME=file:/root/seata-config/registry
-e SEATA_IP=192.168.1.190 
-v /home/dockers/seata/resources:/root/seata-config   
-d    seataio/seata-server
  1. 启动nacos并重启seata
docker restart seata
  •  

最后登录nacos,就可以看到seata服务了 。

在这里插入图片描述