seata官網:http://seata.io/zh-cn/docs/user/registry/nacos.html
本次采用,將容器的文件復制到容器外,在容器外修改完成后,再復制進去。這里要修改的文件有:registry.conf和file.conf。 容器內部不能容vim 懶得執行apt-get update和apt-get install vim ,因為很慢
在mysql5.7數據庫中創建一個名稱為seata的數據庫,腳本可以在Seata的GitHub地址獲取,找到https://github.com/seata/seata/blob/162f83ea851edff801bcdeb3f9ecd018db7e284d/script/server/db/mysql.sql文件,在seata數據庫里執行SQL完成初始化操作
docker pull seataio/seata-server:1.2.0 # 下載seata-server 1.2.0的鏡像
docker run -d --name seata-server -e SEATA_IP=192.168.100.132 -e SEATA_PORT=8091 -p 8091:8091 seataio/seata-server:1.2.0
在usr/local 下創建文件夾seata
docker cp c02504e4eb14:/seata-server/resources/file.conf /usr/local/seata/file.conf #拷貝容器內文件file.conf到容器外的/usr/local/seata徑下
docker cp c02504e4eb14:/seata-server/resources/registry.conf /usr/local/seata/registry.conf #拷貝容器內文件registry.conf到容器外的/usr/local/seata徑下
vim file.conf 修改模式為db 修改數據庫連接信息
store { ## store mode: file、db mode = "db" ## file store property file { ## store location dir dir = "sessionStore" # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions maxBranchSessionSize = 16384 # globe session size , if exceeded throws exceptions maxGlobalSessionSize = 512 # file buffer size , if exceeded allocate new buffer fileWriteBufferCacheSize = 16384 # when recover batch read size sessionReloadReadSize = 100 # async, sync flushDiskMode = async } ## database store property db { ## 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://192.168.100.132:3306/seata" user = "root" password = "123456" minConn = 5 maxConn = 30 globalTable = "global_table" branchTable = "branch_table" lockTable = "lock_table" queryLimit = 100 maxWait = 5000 } }
vim registry.conf 將seata 注冊進nacos中
registry { # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "nacos" nacos { application = "seata-server" serverAddr = "192.168.100.132:80" namespace = "" cluster = "default" username = "" password = "" } eureka { serviceUrl = "http://localhost:8761/eureka" application = "default" weight = "1" } redis { serverAddr = "localhost:6379" db = 0 password = "" cluster = "default" timeout = 0 } zk { cluster = "default" serverAddr = "127.0.0.1:2181" sessionTimeout = 6000 connectTimeout = 2000 username = "" 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、etcd3 type = "file" nacos { serverAddr = "localhost" namespace = "" group = "SEATA_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 = 6000 connectTimeout = 2000 username = "" password = "" } etcd3 { serverAddr = "http://localhost:2379" } file { name = "file.conf" } }
配置文件已經修改完了,我們將文件再復制到容器里面。
docker cp file.conf c02504e4eb14:/seata-server/resources/file.conf
docker cp registry.conf c02504e4eb14:/seata-server/resources/registry.conf
重啟容器
docker restart c02504e4eb14
查看啟動日志 看有沒有報錯
docker logs -f c02504e4eb14
查看nacos服務列表 注冊成功
tar包下載地址:https://github.com/seata/seata/releases
百度盤:https://pan.baidu.com/s/1vfxi1ozW8gxN3zFW4Sdofg 提取碼:acmo