swarm
This commit is contained in:
5
docker-swarm/nacos/README
Normal file
5
docker-swarm/nacos/README
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
# crm1环境下 部署单机nacos
|
||||
|
||||
env $(cat ./env_crm1 | xargs) envsubst < ./standalone-derby.yml | docker stack deploy --compose-file - crm1_nacos
|
||||
|
155
docker-swarm/nacos/cluser.yml
Normal file
155
docker-swarm/nacos/cluser.yml
Normal file
@ -0,0 +1,155 @@
|
||||
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
|
5
docker-swarm/nacos/env_crm1
Normal file
5
docker-swarm/nacos/env_crm1
Normal file
@ -0,0 +1,5 @@
|
||||
NAMESPACE=crm1
|
||||
NACOS_VERSION=v2.2.2
|
||||
NODE_PORT=8848
|
||||
NODE_PORT_2=9848
|
||||
NACOS_SERVER_IP=192.168.1.209
|
38
docker-swarm/nacos/standalone-derby.yml
Normal file
38
docker-swarm/nacos/standalone-derby.yml
Normal file
@ -0,0 +1,38 @@
|
||||
version: '3.8'
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: ${NAMESPACE}
|
||||
external: true
|
||||
services:
|
||||
server:
|
||||
hostname: ${NAMESPACE}_nacos_server
|
||||
image: nacos/nacos-server:${NACOS_VERSION}
|
||||
environment:
|
||||
- PREFER_HOST_MODE=hostname
|
||||
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
|
||||
- MODE=standalone
|
||||
- NACOS_AUTH_ENABLE=true
|
||||
- NACOS_AUTH_IDENTITY_KEY=bndmsdsad
|
||||
- NACOS_AUTH_IDENTITY_VALUE=wepqweq#dasld
|
||||
- NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456587012345678901234567890123456789
|
||||
ports:
|
||||
- target: 8848
|
||||
published: ${NODE_PORT}
|
||||
protocol: tcp
|
||||
mode: host # 解析:默认是ingress就是通过swarm的负载均衡模式,无论通过集群节点的映射端口都能访问到业务容器,此种方式类似于k8s的NodePort的svc服务暴露方式,而host则属于,业务容器运行在哪个节点,则就通过节点地址+映射端口访问对应的业务容器。
|
||||
- target: 9848
|
||||
published: ${NODE_PORT_2}
|
||||
protocol: tcp
|
||||
mode: host
|
||||
volumes:
|
||||
- data_server:/home/nacos/
|
||||
deploy:
|
||||
update_config:
|
||||
order: stop-first
|
||||
placement:
|
||||
constraints:
|
||||
- node.labels.${NAMESPACE}_nacos_server==1
|
||||
volumes:
|
||||
data_server:
|
||||
driver: local
|
Reference in New Issue
Block a user