一、新建数据库zj_nacos_config(持久化nacos配置

数据库名字自己取,建表sql去nacos官方找 

二、创建目录

cd /

mkdir docker/alibaba/nacos

cd docker/alibaba/nacos

三、docker-compose.yml

172.50.2.40:

version: "3.9"
 
services:
  nacos:
    container_name: nacos-server01
    hostname: nacos-server01
    image: nacos/nacos-server:v2.2.0
    environment:
      - MODE=cluster
      - PREFER_HOST_MODE=hostname
      - NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_SERVICE_HOST=172.50.2.139
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=123456
      - MYSQL_SERVICE_DB_NAME=zj_nacos_config
      - JVM_XMS=512m
      - JVM_XMX=512m
      - JVM_XMN=256m
      - JVM_MS=64m
      - JVM_MMS=128m
    volumes:
      - ./logs:/home/nacos/logs
      - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
    ports:
      - 8848:8848
      - 9848:9848
      - 9849:9849
      - 9555:9555
    extra_hosts:
       # master_1容器可以使用的host访问nacos-server02 nacos-server03
      - nacos-server02:172.50.2.41
      - nacos-server03:172.50.2.42
    privileged: true
    network_mode: "host"
    restart: always

172.50.2.41:

version: "3.9"
 
services:
  nacos:
    container_name: nacos-server02
    hostname: nacos-server02
    image: nacos/nacos-server:v2.2.0
    environment:
      - MODE=cluster
      - PREFER_HOST_MODE=hostname
      - NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_SERVICE_HOST=172.50.2.139
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=123456
      - MYSQL_SERVICE_DB_NAME=zj_nacos_config
      - JVM_XMS=512m
      - JVM_XMX=512m
      - JVM_XMN=256m
      - JVM_MS=64m
      - JVM_MMS=128m
    volumes:
      - ./logs:/home/nacos/logs
      - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
    ports:
      - 8848:8848
      - 9848:9848
      - 9849:9849
      - 9555:9555
    extra_hosts:
       # master_1容器可以使用的host访问nacos-server02 nacos-server03
      - nacos-server01:172.50.2.40
      - nacos-server03:172.50.2.42
    privileged: true
    network_mode: "host"
    restart: always

172.50.2.42:

version: "3.9"
 
services:
  nacos:
    container_name: nacos-server03
    hostname: nacos-server03
    image: nacos/nacos-server:v2.2.0
    environment:
      - MODE=cluster
      - PREFER_HOST_MODE=hostname
      - NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_SERVICE_HOST=172.50.2.139
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=123456
      - MYSQL_SERVICE_DB_NAME=zj_nacos_config
      - JVM_XMS=512m
      - JVM_XMX=512m
      - JVM_XMN=256m
      - JVM_MS=64m
      - JVM_MMS=128m
    volumes:
      - ./logs:/home/nacos/logs
      - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
    ports:
      - 8848:8848
      - 9848:9848
      - 9849:9849
      - 9555:9555
    extra_hosts:
       # master_1容器可以使用的host访问nacos-server02 nacos-server03
      - nacos-server01:172.50.2.40
      - nacos-server02:172.50.2.41
    privileged: true
    network_mode: "host"
    restart: always

注意:一定要开放- 9849:9849端口,因为nacos2.x之后集群靠这个端口通信,不开启的画,你的服务就会随机注册到某一台机子,不会复制

​​​​​​​

 

启动:

docker-compose up -d

四、防火墙

# 查看防火墙
systemctl status firewalld
 
# 查看8848端口是否打开【no/yes】
firewall-cmd --zone=public --query-port=8848/tcp
 
#批量添加多个端口
firewall-cmd --permanent --add-port=8848/tcp --add-port=9848/tcp --add-port=9849/tcp --add-port=9555/tcp
 
# 防火墙重载
firewall-cmd --reload
 
# 再次查看8848状态 【yes】
firewall-cmd --zone=public --query-port=8848/tcp

五、访问验证

172.50.2.40:8848/nacos (此时还没用nginx做代理,所以三个网址需要分别访问)

六、集成nginx集群+keepalived

GitHub 加速计划 / compose / compose
33.27 K
5.15 K
下载
compose - Docker Compose是一个用于定义和运行多容器Docker应用程序的工具,通过Compose文件格式简化应用部署过程。
最近提交(Master分支:2 个月前 )
501b5acd Add `jhrotko` to Core Maintainers. Signed-off-by: Laura Brehm <laurabrehm@hey.com> 9 天前
f51bc4cd Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> 9 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐