Files
sa-charts/docker-swarm/nacos/cluser.yml
marsal wang 1e5a703cce swarm
2023-07-26 10:07:34 +08:00

155 lines
3.8 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

version: '3.8'
services:
nacos1:
container_name: nacos1
image: nacos/nacos-server:latest
hostname: nacos1
restart: always
ports:
- target: 8848
published: 8848
protocol: tcp
mode: host #采用host模式默认为ingress配置较灵活根据自己的需求也可调整为ingress本案例防止nacos 采用 swarm集群调度所以改为host模式两台服务器之间通过内网及nacos端口访问通过nginx配置对外服务
volumes:
- cluster1_logs:/home/nacos/logs #配置docker存储日志的卷
environment:
MODE: cluster
PREFER_HOST_MODE: hostname
NACOS_SERVERS: 192.168.3.75:8848 192.168.3.94:8848 192.168.3.142:8848
NACOS_SERVER_IP: 192.168.3.75
NACOS_SERVER_PORT: 8848
NACOS_AUTH_ENABLE: 'true' #1.2.0版本默认关闭登陆界面
MYSQL_SERVICE_HOST: mysql
MYSQL_SERVICE_DB_NAME: nacos_devtest
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: nacos
MYSQL_SERVICE_PASSWORD: 123456
deploy:
replicas: 1 #部署时,指定部署一个副本
placement:
constraints:
- node.labels.env==docker-server-1
restart_policy:
condition: on-failure
depends_on:
- mysql
networks:
- srm
nacos2:
container_name: nacos2
image: nacos/nacos-server:latest
restart: always
hostname: nacos2
ports:
- target: 8848
published: 8848
protocol: tcp
mode: host
volumes:
- cluster2_logs:/home/nacos/logs
environment:
MODE: cluster
PREFER_HOST_MODE: hostname
NACOS_SERVERS: 192.168.3.75:8848 192.168.3.94:8848 192.168.3.142:8848
NACOS_SERVER_IP: 192.168.3.94
NACOS_SERVER_PORT: 8848
NACOS_AUTH_ENABLE: 'true'
MYSQL_SERVICE_HOST: mysql
MYSQL_SERVICE_DB_NAME: nacos_devtest
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: nacos
MYSQL_SERVICE_PASSWORD: 123456
deploy:
replicas: 1
placement:
constraints:
- node.labels.env==docker-server-2
restart_policy:
condition: on-failure
depends_on:
- mysql
networks:
- srm
nacos3:
container_name: nacos3
image: nacos/nacos-server:latest
restart: always
hostname: nacos3
ports:
- target: 8848
published: 8848
protocol: tcp
mode: host
volumes:
- cluster3_logs:/home/nacos/logs
environment:
MODE: cluster
PREFER_HOST_MODE: hostname
NACOS_SERVERS: 192.168.3.75:8848 192.168.3.94:8848 192.168.3.142:8848
NACOS_SERVER_IP: 192.168.3.142
NACOS_SERVER_PORT: 8848
NACOS_AUTH_ENABLE: 'true'
MYSQL_SERVICE_HOST: mysql
MYSQL_SERVICE_DB_NAME: nacos_devtest
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: nacos
MYSQL_SERVICE_PASSWORD: 123456
deploy:
replicas: 1
placement:
constraints:
- node.labels.env==docker-server-3
restart_policy:
condition: on-failure
depends_on:
- mysql
networks:
- srm
mysql:
image: mysql:5.7.33
restart: always
container_name: mysql
hostname: mysql
ports:
- 3306:3306
volumes:
- /data/software/nacos/mysql/data:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
- /etc/my.cnf:/etc/mysql/mysql.conf.d/my.cnf
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: sonar
MYSQL_DATABASE: nacos_devtest
deploy:
replicas: 1
placement:
constraints:
- node.labels.env==docker-server-1
restart_policy:
condition: on-failure
networks:
- srm
volumes:
cluster1_logs:
cluster2_logs:
cluster3_logs:
networks:
srm:
external: true
#https://blog.51cto.com/u_12898848/4054447