1.配置網(wǎng)絡(luò)(復(fù)用已有網(wǎng)絡(luò))
1.1 創(chuàng)建docker虛擬網(wǎng)絡(luò)
# 創(chuàng)建一個(gè)名為tars的橋接(bridge)虛擬網(wǎng)絡(luò)暑脆,網(wǎng)關(guān)172.26.0.1留特,網(wǎng)段為172.25.0.0
docker network create -d bridge --subnet=172.26.0.0/16 --gateway=172.26.0.1 clickhouse
2.啟停命令
docker-compose.yml路徑下:
構(gòu)建開啟: docker-compose up -d
停止: docker-compose stop
開啟:docker-compose start
3. 依賴mysql
- 復(fù)用已有的mysql5.7容器,新建nacos數(shù)據(jù)庫甚淡,用戶演怎。mysql容器啟動(dòng)腳本如下:
sudo docker run -itd --net=clickhouse -e TZ="Asia/Shanghai" -e MYSQL_ROOT_PASSWORD="root" --ip="172.26.0.8" -p 3306:3306 -v /opt/DockerData/mysql:/var/lib/mysql --name=docker_mysql mysql:5.7
- 導(dǎo)入數(shù)據(jù)表:https://github.com/alibaba/nacos/tree/develop/distribution/conf/nacos-mysql.sql
MYSQL_SERVICE_HOST=172.26.0.8
MYSQL_SERVICE_DB_NAME=nacos_devtest
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=nacos
MYSQL_SERVICE_PASSWORD=nacos
#登錄mysql
mysql -uroot -proot
#創(chuàng)建數(shù)據(jù)庫
create database nacos_devtest;
use mysql;
#創(chuàng)建用戶
CREATE USER 'nacos'@'%' identified by 'nacos';
#賦予權(quán)限
grant all privileges on nacos_devtest.* to 'nacos'@'%' with GRANT OPTION;
flush privileges;
4. 集群規(guī)劃
容器ip | 端口 | 節(jié)點(diǎn)類型 | 節(jié)點(diǎn)名 |
---|---|---|---|
172.26.0.130 | 8848匕争、9555 | nacos | nacos1 |
172.26.0.131 | 8848 | nacos | nacos2 |
172.26.0.132 | 8848 | nacos | nacos3 |
172.26.0.8 | 3306 | mysql | docker_mysql,復(fù)用已有容器 |
5. 編寫 docker-compose.yml
version: "3.7"
services:
nacos1:
image: nacos/nacos-server:latest
container_name: nacos1
networks:
clickhouse:
ipv4_address: 172.26.0.130
volumes:
- /f/DockerData/nacos1:/home/nacos/logs
ports:
- "8848:8848"
- "9555:9555"
environment:
NACOS_AUTH_ENABLE: 'true'
NACOS_SERVERS: 172.26.0.130:8848,172.26.0.131:8848,172.26.0.132:8848
MYSQL_SERVICE_HOST: 172.26.0.8
MYSQL_SERVICE_DB_NAME: nacos_devtest
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: nacos
MYSQL_SERVICE_PASSWORD: nacos
# restart: on-failure
nacos2:
image: nacos/nacos-server:latest
container_name: nacos2
networks:
clickhouse:
ipv4_address: 172.26.0.131
volumes:
- /f/DockerData/nacos2:/home/nacos/logs
ports:
- "8849:8848"
environment:
NACOS_AUTH_ENABLE: 'true'
NACOS_SERVERS: 172.26.0.130:8848,172.26.0.131:8848,172.26.0.132:8848
MYSQL_SERVICE_HOST: 172.26.0.8
MYSQL_SERVICE_DB_NAME: nacos_devtest
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: nacos
MYSQL_SERVICE_PASSWORD: nacos
# restart: always
nacos3:
image: nacos/nacos-server:latest
container_name: nacos3
networks:
clickhouse:
ipv4_address: 172.26.0.132
volumes:
- /f/DockerData/nacos3:/home/nacos/logs
ports:
- "8850:8848"
environment:
NACOS_AUTH_ENABLE: 'true'
NACOS_SERVERS: 172.26.0.130:8848,172.26.0.131:8848,172.26.0.132:8848
MYSQL_SERVICE_HOST: 172.26.0.8
MYSQL_SERVICE_DB_NAME: nacos_devtest
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: nacos
MYSQL_SERVICE_PASSWORD: nacos
# restart: always
networks:
clickhouse:
external: true
7. 登錄ui配置
- 登錄 http://127.0.0.1:8848/nacos/ nacos/nacos
- 服務(wù)地址:127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850
- 開啟了鑒權(quán)爷耀,參考:https://nacos.io/zh-cn/docs/auth.html