docker swarm集群部署nacos

docker stack-compose.yml



version: '3.7'
services:
  nacos-n1:
    hostname: nacos-n1
    image: nacos/nacos-server:1.4.2
    ports:
      - 8848:8848
    environment:
      - NACOS_SERVER_IP=nacos-n1
      - PREFER_HOST_MODE=hostname
      - EMBEDDED_STORAGE=embedded
      - NACOS_SERVERS=nacos-n1:8848 nacos-n2:8848 nacos-n3:8848
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_SERVICE_HOST=mysql-n1
      - MYSQL_SERVICE_DB_NAME=nacos_config
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=a123456
      - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
      - TIME_ZONE=Asia/Shanghai
    volumes:
       # 和docker-compose 不一样的是要提前创建,否则会报错,如果
      - ./data/nacos-n1/logs:/home/nacos/logs
      - ./data/nacos-n1/data:/home/nacos/data
      
    user: root
    restart: always
    networks:
    - test-overlay
    deploy:
      placement:
        constraints:
          - node.hostname == n1
          - node.role == manager

  nacos-n2:
    hostname: nacos-n2
    image: nacos/nacos-server:1.4.2
    environment:
      - NACOS_SERVER_IP=nacos-n2
      - PREFER_HOST_MODE=hostname
      - EMBEDDED_STORAGE=embedded
      - NACOS_SERVERS=nacos-n1:8848 nacos-n2:8848 nacos-n3:8848
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_SERVICE_HOST=mysql-n1
      - MYSQL_SERVICE_DB_NAME=nacos_config
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=a123456
      - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
      - TIME_ZONE=Asia/Shanghai
    volumes:
      - ./data/nacos-n2/logs:/home/nacos/logs
      - ./data/nacos-n2/data:/home/nacos/data
    user: root
    restart: always
    networks:
    - test-overlay
    deploy:
      placement:
        constraints:
          - node.hostname == n2
          - node.role == worker

  nacos-n3:
    hostname: nacos-n3
    image: nacos/nacos-server:1.4.2
    environment:
      - NACOS_SERVER_IP=nacos-n3
      - PREFER_HOST_MODE=hostname
      - EMBEDDED_STORAGE=embedded
      - NACOS_SERVERS=nacos-n1:8848 nacos-n2:8848 nacos-n3:8848
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_SERVICE_HOST=mysql-n1
      - MYSQL_SERVICE_DB_NAME=nacos_config
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=a123456
      - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
      - TIME_ZONE=Asia/Shanghai
    volumes:
      - ./data/nacos-n3/logs:/home/nacos/logs
      - ./data/nacos-n3/data:/home/nacos/data
    user: root
    restart: always

    networks:
      - test-overlay
    deploy:
      placement:
        constraints:
          - node.hostname == n3
          - node.role == worker

networks:
  test-overlay:
    driver: overlay
    #false-统自动创建网桥名,格式为: 目录名_网桥名,默认为false; true-使用外部创建的网桥,需需要自己手动创建
    external: true



node.hostname 代表宿主机的名称
node.role 代表节点的权限

启动 docker stack deploy --with-registry-auth -c stack-compose.yml nacos

你可能感兴趣的:(docker,容器,java)