docker部署安装nacos集群说明

docker部署安装nacos集群说明
subnet网段地址。
docker network ls
查看docker网卡
docker network inspect 网卡id
删除docker网卡
docker network rm 网卡id

docker network inspect mynetwork

查看docker网卡的相关详细信息
创建网络ip
docker network create --subnet=172.18.0.0/24 mynetwork

docker部署安装nacos集群说明
--安装mysql
docker pull mysql:8.0.18
docker exec -it mysql01 bash
mysql -uroot -padmin
- 这里用%是保证其他IP能够连上,否则只有本地才能连接。
ALTER USER 'root'@'%' IDENTIFIED BY 'admin' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'admin';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'admin' WITH GRANT OPTION;

 --刷新权限
FLUSH PRIVILEGES;

--注:完成安装需要建立数据库nacos_config,
执行官方脚本
docker run --name mysql01 --restart=always \
-p 3306:3306 \
--net mynetwork --ip 172.18.0.2 --privileged=true  \
-e TZ=Asia/Shanghai \
-v /kdata/mysql/conf:/etc/mysql/conf.d \
-v /kdata/mysql/logs:/logs \
-v /kdata/mysql/data:/var/lib/mysql \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=admin \
-d mysql:8.0.18

--安装nacos集群
docker pull nacos/nacos-server:1.4.1
--注:如果mysql安装在docker中需配置容器内部ip
如果是mysql8,需要调整nacos内部信息(jar)
# --配置数据库主机、用户名、密码、数据库名
--nacos01
docker run --name nacos01 --restart=always \
-p 8847:8847  \
--net mynetwork --ip 172.18.0.3 --privileged=true  \
-e JVM_XMS=256m -e JVM_XMX=256m \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e TIME_ZONE='Asia/Shanghai' \
-e NACOS_APPLICATION_PORT=8847 \
-e NACOS_SERVER_PORT=8847 \
-e NACOS_SERVER_IP=192.168.31.129 \
-e NACOS_SERVERS="192.168.31.129:8847 192.168.31.129:8848 192.168.31.129:8849" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.31.130 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=admin \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-v /kdata/nacos01/logs:/home/nacos/logs \
-d nacos/nacos-server:1.4.1

--nacos02
docker run --name nacos02  --restart=always  \
-p 8848:8848 \
--net mynetwork --ip 172.18.0.4 --privileged=true  \
-e JVM_XMS=256m -e JVM_XMX=256m \
-e TIME_ZONE='Asia/Shanghai' \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=8848 \
-e NACOS_SERVER_PORT=8848 \
-e NACOS_SERVER_IP=192.168.31.129 \
-e NACOS_SERVERS="192.168.31.129:8847 192.168.31.129:8848 192.168.31.129:8849" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.31.130 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=admin \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-v /kdata/nacos02/logs:/home/nacos/logs \
-d nacos/nacos-server:1.4.1


--nacos03
docker run --name nacos03  --restart=always  \
-p 8849:8848 \
--net mynetwork --ip 172.18.0.5 --privileged=true  \
-e JVM_XMS=256m -e JVM_XMX=256m \
-e TIME_ZONE='Asia/Shanghai' \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=8849 \
-e NACOS_SERVER_PORT=8849 \
-e NACOS_SERVER_IP=192.168.31.129 \
-e NACOS_SERVERS="192.168.31.129:8847 192.168.31.129:8848 192.168.31.129:8849" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.31.130 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=admin \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-v /kdata/nacos03/logs:/home/nacos/logs \
-d nacos/nacos-server:1.4.1

--安装nginx
--nginx01
--注:配置nacos负载均衡(nacos01,nacos02)
docker run  --name nginx01  --restart=always \
-p 8088:80  \
--net mynetwork --ip 172.18.0.13 --privileged=true \
-e TZ="Asia/Shanghai" \
-v /kdata/nginx/conf.d:/etc/nginx/conf.d \
-v /kdata/nginx/cert:/etc/nginx/cert \
-v /kdata/nginx/www:/usr/share/nginx/html \
-v /kdata/nginx/logs:/var/log/nginx \
-d nginx


docker run -d \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=8846 \
-e NACOS_SERVERS=192.168.100.132:8846,192.168.100.132:8847,192.168.100.132:8848 \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.100.132 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456 \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e NACOS_SERVER_IP=192.168.100.132 \
-p 8846:8846 \
--name nacos8846 \
nacos/nacos-server:1.3.2
 
docker run -d \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=8847 \
-e NACOS_SERVERS=192.168.100.132:8846,192.168.100.132:8847,192.168.100.132:8848 \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.100.132 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456 \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e NACOS_SERVER_IP=192.168.100.132 \
-p 8847:8847 \
--name nacos8847 \
nacos/nacos-server:1.3.2
 
docker run -d \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=8848 \
-e NACOS_SERVERS=192.168.100.132:8846,192.168.100.132:8847,192.168.100.132:8848 \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.100.132 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456 \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e NACOS_SERVER_IP=192.168.100.132 \
-p 8848:8848 \
--name nacos8848 \
nacos/nacos-server:1.3.2