sudo yum install -y yum-utils
1)安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce //由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0
sudo systemctl start docker
sudo systemctl enable docker
docker version
sudo docker pull nacos/nacos-server:2.0.2
2)单机部署nacos
sudo docker run -it \
-e PREFER_HOST_MODE=ip \
-e MODE=standalone \
-p 9999:8848 \
--name nacos \
--restart=always nacos/nacos-server:2.0.2
注:Nacos2.0增加了9848,9849端口来进行GRPC通信,这两个端口在Nacos2.0内部是通过8848+1000以及8848+1001这种偏移量方式计算出来的,不需要用户额外在配置文件中配置。但如果使用的是docker或存在端口转发方式启动,需要把这两个端口进行配置。
sudo docker pull nacos/nacos-server:2.0.2
节点一:(-d 后台运行)
sudo docker run -itd \
-e PREFER_HOST_MODE=ip \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=9999 \
-e NACOS_SERVERS="10.30.4.48:9999 10.30.4.49:9999" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=10.30.4.47 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=** \
-e MYSQL_SERVICE_PASSWORD=*** \
-e MYSQL_SERVICE_DB_NAME=*** \
-e NACOS_SERVER_IP=10.30.4.47 \
-p 9999:9999 \
-p 10999:10999 \
-p 11000:11000 \
--name my-nacos1 \
--restart=always \
--privileged=true \
nacos/nacos-server:2.0.2
节点二:
sudo docker run -itd \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=9999 \
-e NACOS_SERVERS="10.30.4.47:9999 10.30.4.49:9999" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=10.30.4.47 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=*** \
-e MYSQL_SERVICE_PASSWORD=*** \
-e MYSQL_SERVICE_DB_NAME=*** \
-e NACOS_SERVER_IP=10.30.4.48 \
-p 9999:9999 \
-p 10999:10999 \
-p 11000:11000 \
--restart=always \
--privileged=true \
--name my-nacos2 \
nacos/nacos-server:2.0.2
节点三:
sudo docker run -itd \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_APPLICATION_PORT=9999 \
-e NACOS_SERVERS="10.30.4.47:9999 10.30.4.48:9999" \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=10.30.4.47 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=*** \
-e MYSQL_SERVICE_PASSWORD=*** \
-e MYSQL_SERVICE_DB_NAME=*** \
-e NACOS_SERVER_IP=10.30.4.49 \
-p 9999:9999 \
-p 10999:10999 \
-p 11000:11000 \
--name my-nacos3 \
--restart=always \
--privileged=true \
nacos/nacos-server:2.0.2
sudo docker pull nacos/nacos-server:2.0.2
sudo docker save nacos/nacos-server:2.0.2 -o /data/appadmjjkj/images/nacos-docker-2.0.2.tar
或 sudo docker save IMAGE ID -o /data/appadmjjkj/images/nacos-docker-2.0.2.tar
sudo docker load -i nacos-docker-2.0.2.tar
目的是:为了进行挂载启动,以后修改配置文件、查看日志时更加方便。
mkdir -p /data/appadmjjkj/docker/cloud/nacos
直接启动:
sudo docker run --name nacos-server -d nacos/nacos-server:2.0.2
拷贝目录:
sudo docker cp nacos-server:/home/nacos/conf /data/appadmjjkj/docker/cloud/nacos
sudo docker cp nacos-server:/home/nacos/logs /data/appadmjjkj/docker/cloud/nacos
删除容器:
sudo docker stop nacos-server
sudo docker rm nacos-server
在application.properties文件中,我们直接将原有采用环境变量方式的配置根据实际情况进行修改。
sudo vi /data/appadmjjkj/docker/cloud/nacos/conf/application.properties
修改内容如下:
# 端口
server.port=8848
spring.datasource.platform=mysql
# 数据库数量,如果mysql配置了主从就设置为 2
db.num=1
# mysql连接
db.url.0=jdbc:mysql://10.30.4.47:3306/ls_nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai
# 如果db.num=1,则将db.url.1屏蔽;反之则配置db.url.1
#db.url.1=
# mysql用户名
db.user=user_ls
# mysql密码
db.password=aeTHO5jqLRfP1c_W
sudo docker run -itd \
--name nacos-server \
--privileged=true \
--restart=always \
-p 9999:8848 \
-e MODE=standalone \
-v /data/appadmjjkj/docker/cloud/nacos/logs:/home/nacos/logs \
-v /data/appadmjjkj/docker/cloud/nacos/conf:/home/nacos/conf \
nacos/nacos-server:2.0.2
容器1:
sudo docker run -itd \
--name my-nacos1 \
--restart=always \
--privileged=true \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-v /data/appadmjjkj/docker/cloud/nacos/logs:/home/nacos/logs \
-v /data/appadmjjkj/docker/cloud/nacos/conf:/home/nacos/conf \
-e NACOS_SERVER_IP=10.30.4.49 \
-e NACOS_SERVERS="10.30.4.47:8848 10.30.4.48:8848 10.30.4.49:8848" \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
nacos/nacos-server:2.0.2
容器2:
sudo docker run -itd \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_SERVERS="10.30.4.47:8848 10.30.4.48:8848 10.30.4.49:8848" \
-e NACOS_APPLICATION_PORT=9998 \
-v /data/appadmjjkj/docker/cloud/nacos/logs:/home/nacos/logs \
-v /data/appadmjjkj/docker/cloud/nacos/conf:/home/nacos/conf \
-p 9998:8848 \
-p 10998:9848 \
-p 10999:9849 \
--name my-nacos2 \
--restart=always \
--privileged=true \
nacos/nacos-server:2.0.2
容器3:
sudo docker run -itd \
-e PREFER_HOST_MODE=hostname \
-e MODE=cluster \
-e NACOS_SERVERS="10.30.4.47:8848 10.30.4.48:8848 10.30.4.49:8848" \
-v /data/appadmjjkj/docker/cloud/nacos/logs:/home/nacos/logs \
-v /data/appadmjjkj/docker/cloud/nacos/conf:/home/nacos/conf \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
--name my-nacos3 \
--restart=always \
--privileged=true \
nacos/nacos-server:2.0.2