云迈博客

您现在的位置是:首页 > 后端开发 > Java > 正文

Java

【Docker】 docker-compose 部署 seata-server 记录

wsinbol2022-05-28Java681
获取配置文件˃dockerrun–rm–nameseata-server-d-p8091:8091seataio/seata-server:1.4.0用–rm启动一个sea

获取配置文件

docker run –rm –name seata-server -d -p 8091:8091 seataio/seata-server:1.4.0

用 –rm 启动一个 seata 的临时容器,stop 时也能够自动销毁该容器。

cp 配置文件到宿主机

docker cp [seata-server]:/seata-server/resources/. /www/java/project/docker/seata-server/conf

将 resources 目录下的所有文件复制到宿主机指定配置目录下。

修改 registry.conf 配置,使用 nacos 做注册、配置中心

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos" # 修改为 nacos
  loadBalance = "RandomLoadBalance"
  loadBalanceVirtualNodes = 10

  nacos {
    application = "seata-server"
    serverAddr = "172.18.0.1:8848" # 配置注册中心地址,IP根据 docker inspect [nacos服务名称] 来确定,也可以配置成外网地址
    group = "SEATA_GROUP"
    namespace = "dev" # 命名空间
    cluster = "default"
    username = "nacos" # 用户名
    password = "nacos" # 密码
  }
  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 = "nacos"

  nacos {
    serverAddr = "172.18.0.1:8848"
    namespace = "dev"
    group = "SEATA_GROUP"
    username = "nacos"
    password = "nacos"
  }
  consul {
    serverAddr = "127.0.0.1:8500"
  }
  apollo {
    appId = "seata-server"
    apolloMeta = "http://192.168.1.204:8801"
    namespace = "application"
    apolloAccesskeySecret = ""
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    name = "file.conf"
  }
}

准备 docker-compose

version : '3.8'
services:
  seata-server:
    container_name: seata-server
    image: seataio/seata-server:1.3.0
    hostname: seata-server
    build:
      context: ./seata-server
    volumes:
      - ./seata-server/conf/registry.conf:/seata-server/resources/registry.conf
    ports:
      - 8091:8091
      - 7091:7091
    environment:
      - SEATA_PORT=8091
      - SEATA_IP=你的公网IP
    expose:
      - 8091

编写 dockfile

# 基础镜像
FROM seataio/seata-server:1.4.0
# author
MAINTAINER ruoyi

# 复制conf文件到路径
COPY ./conf/registry.conf /seata-server/resources/registry.conf

启动容器

docker-compose -f docker-compose.yml up –build -d seata-server

执行完毕后,可以在 Nacos 中看到

后续

  1. 由于 seata 使用 mysql 作为 db 高可用数据库,所以需要新建一个“seata”数据库,导入下述数据库脚本。[链接地址](https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql)

  2. 不要忘记在 Nacos 配置管理中添加 seata-server 服务的配置文件,上面的信息会写在此处的配置文件中

发表评论

评论列表

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~