搭建單節(jié)點(diǎn)nacos 請(qǐng)看這里
以下是nacos 集群搭建方法一
# 節(jié)點(diǎn)一
docker run -d \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_SERVER_PORT=8948 \
-e NACOS_SERVER_IP=192.168.0.105 \
-e NACOS_SERVERS="192.168.0.105:8948 192.168.0.103:8948 192.168.0.103:8949" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.0.105 \
-e MYSQL_SERVICE_PORT=4002 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=admin \
-e MYSQL_SERVICE_DB_NAME=nacos \
-p 8948:8848 --net=swarm_test \
--name nacos1 \
nacos/nacos-server:latest
# 節(jié)點(diǎn)二
docker run -d \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_SERVER_PORT=8948 \
-e NACOS_SERVERS="192.168.0.105:8948 192.168.0.103:8948 192.168.0.103:8949" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.0.105 \
-e MYSQL_SERVICE_PORT=4002 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=admin \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e NACOS_SERVER_IP=192.168.0.103 \
-p 8948:8848 --net=swarm_test \
--name nacos2 \
nacos/nacos-server:latest
# 節(jié)點(diǎn)三
docker run -d \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_SERVER_PORT=8949 \
-e NACOS_SERVERS="192.168.0.105:8948 192.168.0.103:8948 192.168.0.103:8949" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.0.105 \
-e MYSQL_SERVICE_PORT=4002 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=admin \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e NACOS_SERVER_IP=192.168.0.103 \
-p 8949:8848 --net=swarm_test \
--name nacos3 \
nacos/nacos-server:latest
方法二
用戶密碼參考docker-compose-swarm-nacos.yml
nacos-mysql.sql
#docker-compose-swarm-nacos.yml
#node.id為docker swarm 節(jié)點(diǎn)id
version: "3.5"
services:
nacos1:
hostname: nacos1
container_name: nacos1
image: nacos/nacos-server:latest
ports:
- "8848:8848"
environment:
MODE: cluster
PREFER_HOST_MODE: hostname
NACOS_SERVERS: nacos1:8848 nacos2:8848 nacos3:8848
MYSQL_SERVICE_HOST: 192.168.0.105 #修改成實(shí)際的數(shù)據(jù)庫ip
MYSQL_SERVICE_DB_NAME: nacos #修改成實(shí)際的dbname
MYSQL_SERVICE_PORT: 4002 #修改成對(duì)應(yīng)的端口
MYSQL_SERVICE_USER: root #修改成對(duì)應(yīng)的用戶名
MYSQL_SERVICE_PASSWORD: admin #修改成對(duì)應(yīng)的密碼
restart: always
networks:
- swarm_test
deploy:
placement:
constraints:
- node.id == ultdmk211olun9ycczhnk3ttj #根據(jù)實(shí)際情況修改
nacos2:
hostname: nacos2
image: nacos/nacos-server:latest
container_name: nacos2
ports:
- "8849:8848"
environment:
MODE: cluster
PREFER_HOST_MODE: hostname
NACOS_SERVERS: nacos1:8848 nacos2:8848 nacos3:8848
MYSQL_SERVICE_HOST: 192.168.0.105 #修改成實(shí)際的數(shù)據(jù)庫ip
MYSQL_SERVICE_DB_NAME: nacos #修改成實(shí)際的dbname
MYSQL_SERVICE_PORT: 4002 #修改成對(duì)應(yīng)的端口
MYSQL_SERVICE_USER: root #修改成對(duì)應(yīng)的用戶名
MYSQL_SERVICE_PASSWORD: admin #修改成對(duì)應(yīng)的密碼
restart: always
networks:
- swarm_test
deploy:
placement:
constraints:
- node.id == m2lf0h6b2jjy3to5i5zsyeb1q #根據(jù)實(shí)際情況修改
nacos3:
hostname: nacos3
image: nacos/nacos-server:latest
container_name: nacos3
ports:
- "8850:8848"
environment:
MODE: cluster
PREFER_HOST_MODE: hostname
NACOS_SERVERS: nacos1:8848 nacos2:8848 nacos3:8848
MYSQL_SERVICE_HOST: 192.168.0.105 #修改成實(shí)際的數(shù)據(jù)庫ip
MYSQL_SERVICE_DB_NAME: nacos #修改成實(shí)際的dbname
MYSQL_SERVICE_PORT: 4002 #修改成對(duì)應(yīng)的端口
MYSQL_SERVICE_USER: root #修改成對(duì)應(yīng)的用戶名
MYSQL_SERVICE_PASSWORD: admin #修改成對(duì)應(yīng)的密碼
restart: always
networks:
- swarm_test
deploy:
placement:
constraints:
- node.id == m2lf0h6b2jjy3to5i5zsyeb1q #根據(jù)實(shí)際情況修改
networks:
swarm_test:
external: true
(三) 編輯nginx代理nacos的訪問烦周,
點(diǎn)波關(guān)注 系統(tǒng)搭建(docker)