1. 程式人生 > 實用技巧 >docker搭建seata-server 1.2.0環境

docker搭建seata-server 1.2.0環境

seata官網:http://seata.io/zh-cn/docs/user/registry/nacos.html

本次採用,將容器的檔案複製到容器外,在容器外修改完成後,再複製進去。這裡要修改的檔案有:registry.conf和file.conf。

在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 -h 192.168.100.132 -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服務列表 註冊成功