Nacos

HOSTNAME IP
node1 192.168.2.11
node2 192.168.2.12

Docker

node1

  • docker-compose.yml

    services:
      nacos:
        image: nacos/nacos-server:v2.3.2
        container_name: nacos
        env_file:
          - /opt/nacos/conf/nacos.env
        volumes:
          - /etc/localtime:/etc/localtime:ro
          - /opt/nacos/conf:/home/nacos/conf
          - /opt/nacos/logs:/home/nacos/logs
        network_mode: host
        restart: always
    
  • 获取 nacos 配置

    从临时的容器中复制出来 临时容器名称 xxx 随机通过 docker ps 查看

    docker run -it --entrypoint bash nacos/nacos-server:v2.3.2
    
    docker cp xxx:/home/nacos/conf /opt/nacos
    
  • nacos.env

    PREFER_HOST_MODE=hostname
    MODE=cluster # standalone 单机模式 cluster 集群
    NACOS_SERVERS="node-1:8848 node-2:8848"
    SPRING_DATASOURCE_PLATFORM=mysql
    MYSQL_SERVICE_HOST=node-17
    MYSQL_SERVICE_PORT=3316
    MYSQL_SERVICE_DB_NAME=nacos
    MYSQL_SERVICE_USER=root
    MYSQL_SERVICE_PASSWORD=xxx
    
  • 初始化数据库

  • 启动

    docker compose -f docker-compose.yml up -d
    

node2

重复 node1