centos使用portainer部署nacos集群
[TOC]
所有服务器安装docker和dcoker-compose
安装docker
[root@master ~]# wget "http://kodbox.jishuliu.cn/?explorer/share/fileDownload&shareID=75qriMgg&path=%7BshareItemLink%3A75qriMgg%7D%2Fdocker%2Fdocker-24.0.4.tgz&s=l0Qqa"
[root@master ~]# ls
anaconda-ks.cfg docker-24.0.4.tgz
[root@master ~]# tar xf docker-24.0.4.tgz
[root@master ~]# cp docker/* /usr/bin/
[root@master ~]# docker version
Client: Docker Engine - Community
Version: 19.03.9
API version: 1.40
Go version: go1.13.10
Git commit: 9d988398e7
Built: Fri May 15 00:22:47 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.9
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 9d988398e7
Built: Fri May 15 00:28:17 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
[root@master ~]# vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
[root@master ~]# service docker start
Redirecting to /bin/systemctl start docker.service
安装docker-compose
[root@master ~]# wget "http://kodbox.jishuliu.cn/?explorer/share/fileDownload&shareID=75qriMgg&path=%7BshareItemLink%3A75qriMgg%7D%2Fdocker%2Fdocker-compose&s=CTaW0"
[root@master ~]# ls
anaconda-ks.cfg docker-compose
[root@master ~]# chmod +x docker-compose
[root@master ~]# cp docker-compose /usr/bin/
[root@master ~]# docker-compose -v
docker-compose version 1.23.2, build 1110ad01
[root@master ~]#
主节点安装harbor并推送镜像
[root@master ~]# setenforce 0
[root@master ~]# systemctl stop firewalld.service
[root@master ~]# iptables -F
[root@master ~]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@master ~]# wget "http://kodbox.jishuliu.cn/?explorer/share/fileDownload&shareID=75qriMgg&path=%7BshareItemLink%3A75qriMgg%7D%2Fharbor%2Fharbor-offline-installer-v2.3.4.tgz&s=LLsrA"
[root@master ~]# rz -E
rz waiting to receive.
[root@master ~]# ls
anaconda-ks.cfg harbor-offline-installer-v2.3.4.tgz
[root@master ~]# tar xf harbor-offline-installer-v2.3.4.tgz
cd ha [root@master ~]# cd harbor
[root@master harbor]# cp harbor.yml.tmpl harbor.yml
[root@master harbor]# vim harbor.yml
#编辑harbor.yml修改以下内容:
port: 修改为你想使用的端口
hostname: 改为你自己的主机名
harbor_admin_password: 登录harbor的密码
注释掉以下几行:
#https:
# https port for harbor, default is 443
# port: 443
# # The path of cert and key files for nginx
# certificate: /your/certificate/path
# private_key: /your/private/key/path
[root@master harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 19.03.9
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.23.2
[Step 2]: loading Harbor images ...
103405848fd2: Loading layer [==================================================>] 37.24MB/37.24MB
bab588f83459: Loading layer [==================================================>] 8.75MB/8.75MB
5f0fc8804b08: Loading layer [==================================================>] 11.64MB/11.64MB
c28f2daf5359: Loading layer [==================================================>] 1.688MB/1.688MB
Loaded image: goharbor/harbor-portal:v2.3.4
e1768f3b0fc8: Loading layer [==================================================>] 8.75MB/8.75MB
Loaded image: goharbor/nginx-photon:v2.3.4
80c494db90e8: Loading layer [==================================================>] 6.82MB/6.82MB
f7c774b190f5: Loading layer [==================================================>] 6.219MB/6.219MB
3f9238d93e31: Loading layer [==================================================>] 15.88MB/15.88MB
357454838775: Loading layer [==================================================>] 29.29MB/29.29MB
bbdcee8bdadb: Loading layer [==================================================>] 22.02kB/22.02kB
ac89f4dce657: Loading layer [==================================================>] 15.88MB/15.88MB
Loaded image: goharbor/notary-server-photon:v2.3.4
305b24ea374e: Loading layer [==================================================>] 7.363MB/7.363MB
55dcab863ae7: Loading layer [==================================================>] 4.096kB/4.096kB
4832b43b9049: Loading layer [==================================================>] 3.072kB/3.072kB
c5065fd5a724: Loading layer [==================================================>] 31.52MB/31.52MB
c1732b627bc6: Loading layer [==================================================>] 11.39MB/11.39MB
84e3371d6d71: Loading layer [==================================================>] 43.7MB/43.7MB
Loaded image: goharbor/trivy-adapter-photon:v2.3.4
0bda5dd4507f: Loading layer [==================================================>] 9.918MB/9.918MB
9b8b0a75131b: Loading layer [==================================================>] 3.584kB/3.584kB
8a27a2e44308: Loading layer [==================================================>] 2.56kB/2.56kB
c2d79ade2e58: Loading layer [==================================================>] 73.36MB/73.36MB
a7efb206c673: Loading layer [==================================================>] 5.632kB/5.632kB
a0151a9b651b: Loading layer [==================================================>] 94.72kB/94.72kB
077455b7a6e9: Loading layer [==================================================>] 11.78kB/11.78kB
77235bb05a07: Loading layer [==================================================>] 74.26MB/74.26MB
d55c045b5185: Loading layer [==================================================>] 2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.3.4
1dcd2f87d99c: Loading layer [==================================================>] 1.096MB/1.096MB
5991768c62a8: Loading layer [==================================================>] 5.888MB/5.888MB
4cbb6847a67d: Loading layer [==================================================>] 173.7MB/173.7MB
437252ecb71f: Loading layer [==================================================>] 15.73MB/15.73MB
324517377bf0: Loading layer [==================================================>] 4.096kB/4.096kB
4697090444de: Loading layer [==================================================>] 6.144kB/6.144kB
19cb7f4e8295: Loading layer [==================================================>] 3.072kB/3.072kB
eb573ba4e927: Loading layer [==================================================>] 2.048kB/2.048kB
a30648a5fa3e: Loading layer [==================================================>] 2.56kB/2.56kB
65ab99d7c381: Loading layer [==================================================>] 2.56kB/2.56kB
9395849bf38f: Loading layer [==================================================>] 2.56kB/2.56kB
23a2711d2570: Loading layer [==================================================>] 8.704kB/8.704kB
Loaded image: goharbor/harbor-db:v2.3.4
2fcbfe43743b: Loading layer [==================================================>] 9.918MB/9.918MB
71f1cf1a21e7: Loading layer [==================================================>] 3.584kB/3.584kB
a5fd6aea12f3: Loading layer [==================================================>] 2.56kB/2.56kB
5d286dafbc99: Loading layer [==================================================>] 82.47MB/82.47MB
421d40a4b24e: Loading layer [==================================================>] 83.27MB/83.27MB
Loaded image: goharbor/harbor-jobservice:v2.3.4
a95079faecd9: Loading layer [==================================================>] 6.825MB/6.825MB
baf6f07b0d35: Loading layer [==================================================>] 4.096kB/4.096kB
5021c842bb8d: Loading layer [==================================================>] 3.072kB/3.072kB
964d95b989da: Loading layer [==================================================>] 19.02MB/19.02MB
f75de434d758: Loading layer [==================================================>] 19.81MB/19.81MB
Loaded image: goharbor/registry-photon:v2.3.4
6451d64104a0: Loading layer [==================================================>] 165.1MB/165.1MB
00794002f84b: Loading layer [==================================================>] 57.03MB/57.03MB
760f43153bcd: Loading layer [==================================================>] 2.56kB/2.56kB
4920fd15af6e: Loading layer [==================================================>] 1.536kB/1.536kB
d337336c9729: Loading layer [==================================================>] 12.29kB/12.29kB
5f17a57a5e01: Loading layer [==================================================>] 2.884MB/2.884MB
05ecc6b370ea: Loading layer [==================================================>] 297kB/297kB
Loaded image: goharbor/prepare:v2.3.4
b370aa55f6bb: Loading layer [==================================================>] 6.825MB/6.825MB
c40e1854804c: Loading layer [==================================================>] 4.096kB/4.096kB
62c713c68f94: Loading layer [==================================================>] 19.02MB/19.02MB
067cb9d13dc2: Loading layer [==================================================>] 3.072kB/3.072kB
da711fd41a09: Loading layer [==================================================>] 25.43MB/25.43MB
61af5bc5684d: Loading layer [==================================================>] 45.24MB/45.24MB
Loaded image: goharbor/harbor-registryctl:v2.3.4
1fce02e2f0b2: Loading layer [==================================================>] 9.918MB/9.918MB
90182ef8d6af: Loading layer [==================================================>] 17.71MB/17.71MB
30cf2783eb4e: Loading layer [==================================================>] 4.608kB/4.608kB
c8fa87f0c432: Loading layer [==================================================>] 18.5MB/18.5MB
Loaded image: goharbor/harbor-exporter:v2.3.4
1bbdf18315cc: Loading layer [==================================================>] 6.82MB/6.82MB
332423af2705: Loading layer [==================================================>] 6.219MB/6.219MB
a2024685b4fa: Loading layer [==================================================>] 14.47MB/14.47MB
a04184f058e2: Loading layer [==================================================>] 29.29MB/29.29MB
8fec5d89081c: Loading layer [==================================================>] 22.02kB/22.02kB
da3e11c34f87: Loading layer [==================================================>] 14.47MB/14.47MB
Loaded image: goharbor/notary-signer-photon:v2.3.4
01d27e9ffb2b: Loading layer [==================================================>] 125.5MB/125.5MB
dc823a6e78ed: Loading layer [==================================================>] 3.584kB/3.584kB
65b4a979ece5: Loading layer [==================================================>] 3.072kB/3.072kB
bd00d96da856: Loading layer [==================================================>] 2.56kB/2.56kB
5270920b2bb1: Loading layer [==================================================>] 3.072kB/3.072kB
9c736a3f305b: Loading layer [==================================================>] 3.584kB/3.584kB
e3053dfef34c: Loading layer [==================================================>] 19.97kB/19.97kB
Loaded image: goharbor/harbor-log:v2.3.4
56dfaad4f3ae: Loading layer [==================================================>] 121.4MB/121.4MB
1e54038c4760: Loading layer [==================================================>] 3.072kB/3.072kB
3283554b0538: Loading layer [==================================================>] 59.9kB/59.9kB
607e2816db21: Loading layer [==================================================>] 61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.3.4
a18bcd8df6d3: Loading layer [==================================================>] 6.824MB/6.824MB
0dcfc4641990: Loading layer [==================================================>] 67.47MB/67.47MB
88be11c9e4c9: Loading layer [==================================================>] 3.072kB/3.072kB
3a99925cf064: Loading layer [==================================================>] 4.096kB/4.096kB
a426fee0fb8a: Loading layer [==================================================>] 68.26MB/68.26MB
Loaded image: goharbor/chartmuseum-photon:v2.3.4
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /root/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-db ... done
Creating registry ... done
Creating registryctl ... done
Creating harbor-portal ... done
Creating redis ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
# 到此及为部署成功,可访问IP+配置文件内的端口进行访问
常见报错
- 1
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"write /proc/self/attr/keycreate: permission denied\"": unknown.
说明selinux没有关闭,参考链接https://blog.csdn.net/xinluke/article/details/51925293
- 2
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-382ff0dfef6d -j RETURN: iptables: No chain/target/match by that name.(exit status 1))
说明防火墙没有关闭或关闭后没有重启依次执行如下命令:
systemctl stop firewalld.service
iptables -F
service docker restart
推送镜像
登录harbor
- 所有服务器执行修改/etc/docker/daemon.json文件
[root@node1 ~]# vim /etc/docker/daemon.json
{
"insecure-registries": ["http://192.168.9.136:8080"]
}
- 所有服务器重启docker及登录harbor
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@node1 ~]# docker login 192.168.9.136:8080
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@node1 ~]#
推送nginx镜像
- 在harbor创建项目命名为nginx
- 查看推送命令
- 下载nginx镜像
[root@master harbor]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
eff15d958d66: Pull complete
1e5351450a59: Pull complete
2df63e6ce2be: Pull complete
9171c7ae368c: Pull complete
020f975acd28: Pull complete
266f639b35ad: Pull complete
Digest: sha256:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226e
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@master harbor]#
- 推送nginx镜像
[root@master harbor]# docker tag nginx:latest 192.168.9.136:8080/nginx/nginx:latest
[root@master harbor]# docker push 192.168.9.136:8080/nginx/nginx:latest
The push refers to repository [192.168.9.136:8080/nginx/nginx]
8525cde30b22: Pushed
1e8ad06c81b6: Pushed
49eeddd2150f: Pushed
ff4c72779430: Pushed
37380c5830fe: Pushed
e1bbcf243d0e: Pushed
latest: digest: sha256:2f14a471f2c2819a3faf88b72f56a0372ff5af4cb42ec45aab00c03ca5c9989f size: 1570
[root@master harbor]#
推送nacos镜像
- 在harbor新建项目命名为nacos
- 查看推送命令
- 下载nacos镜像由于镜像比较大可以选择下载镜像源文件导入
[root@master harbor]# docker pull nacos/nacos-server
Using default tag: latest
latest: Pulling from nacos/nacos-server
5ad559c5ae16: Pull complete
5746ca7cf180: Pull complete
d709fe221c89: Pull complete
e88fdcf257b1: Pull complete
eb573b28173c: Pull complete
a71625257ced: Pull complete
26e7e7836838: Pull complete
30f7d6851c4a: Pull complete
d565cd94c625: Pull complete
Digest: sha256:87a3d8b78ec24c253a4db7c093097a7b256327eb5117cd9498e289b896918153
Status: Downloaded newer image for nacos/nacos-server:latest
docker.io/nacos/nacos-server:latest
[root@master harbor]#
- 推送nacos镜像
[root@master ~]# docker tag nacos/nacos-server:latest 192.168.9.136:8080/nacos/nacos-server:latest
[root@master ~]# docker push 192.168.9.136:8080/nacos/nacos-server:latest
The push refers to repository [192.168.9.136:8080/nacos/nacos-server]
8587801db641: Pushed
09b8574bfbcd: Pushed
4184df53b4d6: Pushed
685f018a6ca3: Pushed
31304023555e: Pushed
d2a0ffedc13b: Pushed
99befb4b157d: Pushed
b57f145112c9: Pushed
4826cdadf1ef: Pushed
latest: digest: sha256:90675cc79bc83ef9cd4c613a87f30cd96c174a668bc1ad099b5923d897678c20 size: 2209
[root@master ~]#
主节点安装portainer
- 下载镜像
[root@master ~]# docker pull portainer/portainer
Using default tag: latest
latest: Pulling from portainer/portainer
94cfa856b2b1: Pull complete
49d59ee0881a: Pull complete
a2300fd28637: Pull complete
Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f
Status: Downloaded newer image for portainer/portainer:latest
docker.io/portainer/portainer:latest
[root@master ~]#
- 启动镜像
[root@master ~]# docker run -d -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
54ec4aa9cf385cc962fe70b080fe59652f642855a3bf68809afd6c92eb21ec16
[root@master ~]#
在portainer内创建labels
创建swarm集群
- 主节点执行
[root@master ~]# docker swarm init
Swarm initialized: current node (jfqjbhcaebm799get8g95wvxj) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1wnaudzcscv1z4u1nu0veki3sdri2lw17g4w2jdpkq25urzu40-6dokydwx7bj0f2ks706v2zvzr 192.168.9.136:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[root@master ~]#
- 其他节点操作
[root@node1 ~]# docker swarm join --token SWMTKN-1-1wnaudzcscv1z4u1nu0veki3sdri2lw17g4w2jdpkq25urzu40-6dokydwx7bj0f2ks706v2zvzr 192.168.9.136:2377
This node joined a swarm as a worker.
[root@node1 ~]#
[root@node2 sbin]# docker swarm join --token SWMTKN-1-1wnaudzcscv1z4u1nu0veki3sdri2lw17g4w2jdpkq25urzu40-6dokydwx7bj0f2ks706v2zvzr 192.168.9.136:2377
This node joined a swarm as a worker.
[root@node2 sbin]#
- 主节点查看集群信息
[root@master ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
jfqjbhcaebm799get8g95wvxj * master Ready Active Leader 19.03.9
oyhoqm4bmn3qfy0x6h5pddodr node1 Ready Active 19.03.9
xax6inxf0oa9hk1bfw63hq7ev node2 Ready Active 19.03.9
[root@master ~]#
登录portainer并添加harbor及swarm集群
- 访问主节点IP+9000端口登录portainer
- 添加swarm集群信息
- 添加harbor
在集群对应服务器添加labels
- 在master添加nocas1=true和nginx=true
- 在node1添加nacos2=true
- 在node2添加nacos3=ture
部署nacos集群
- 所有服务器执行
[root@master ~]# mkdir -p /home/nacos/cluster-logs/nacos-server01
[root@master ~]# mkdir -p /home/nacos/init.d
[root@master ~]# chmod -R 750 /home/nacos/
[root@master ~]#
- 添加stack
参数说明:
hostname:主机名
image:镜像下载地址
MODE:启动模式
PREFER_HOST_MODE:主机IP
NACOS_SERVERS:集群主机信息
SPRING_DATASOURCE_PLATFORM:数据库类型
MYSQL_SERVICE_HOST:MySQL链接IP
MYSQL_SERVICE_PORT:MySQL链接端口
MYSQL_SERVICE_USER:MySQL用户名
MYSQL_SERVICE_PASSWORD:MySQL用户名的对应密码
MYSQL_SERVICE_DB_NAME:数据库名
编排文件内容
version: '3.7'
services:
nacos1:
hostname: nacos-server01
restart: always
image: 192.168.9.136:8080/nacos/nacos-server@sha256:90675cc79bc83ef9cd4c613a87f30cd96c174a668bc1ad099b5923d897678c20
environment:
- MODE=cluster
- PREFER_HOST_MODE=192.168.9.136
- NACOS_SERVERS=192.168.9.136:8848 192.168.9.137:8848 192.168.9.138:8848
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=101.201.223.213
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=
- MYSQL_SERVICE_DB_NAME=nacos_config
volumes:
- /home/nacos/cluster-logs/nacos-server01:/home/nacos/logs
- /home/nacos/init.d:/home/nacos/init.d
networks:
- host
deploy:
mode: global
placement:
constraints: [node.labels.nacos1 == true]
nacos2:
hostname: nacos-server02
restart: always
image: 192.168.9.136:8080/nacos/nacos-server@sha256:90675cc79bc83ef9cd4c613a87f30cd96c174a668bc1ad099b5923d897678c20
environment:
- MODE=cluster
- PREFER_HOST_MODE=192.168.9.137
- NACOS_SERVERS=192.168.9.136:8848 192.168.9.137:8848 192.168.9.138:8848
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=101.201.223.213
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=root
- MYSQL_SERVICE_DB_NAME=nacos_config
volumes:
- /home/nacos/cluster-logs/nacos-server01:/home/nacos/logs
- /home/nacos/init.d:/home/nacos/init.d
networks:
- host
deploy:
mode: global
placement:
constraints: [node.labels.nacos2 == true]
nacos3:
hostname: nacos-server03
restart: always
image: 192.168.9.136:8080/nacos/nacos-server@sha256:90675cc79bc83ef9cd4c613a87f30cd96c174a668bc1ad099b5923d897678c20
environment:
- MODE=cluster
- PREFER_HOST_MODE=192.168.9.138
- NACOS_SERVERS=192.168.9.136:8848 192.168.9.137:8848 192.168.9.138:8848
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=101.201.223.213
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=root
- MYSQL_SERVICE_DB_NAME=nacos_config
volumes:
- /home/nacos/cluster-logs/nacos-server01:/home/nacos/logs
- /home/nacos/init.d:/home/nacos/init.d
networks:
- host
deploy:
mode: global
placement:
constraints: [node.labels.nacos3 == true]
networks:
host:
external: true
部署nginx负载均衡
- 创建nginx配置文件及日志路径
[root@master data]# mkdir -p /data/nginx/conf/conf1
[root@master data]# mkdir -p /data/nginx/logs/logs1
- 写入nginx配置文件
[root@master data]# vim /data/nginx/conf/conf1/nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 5;
upstream nacos {
server 192.168.9.136:8848 weight=1 max_fails=2 fail_timeout=10s; #weight为配置的权重,在fail_timeout内检查max_fails次数,失败则剔除均衡。权重越大转发的请求次数越多
server 192.168.9.137:8848 weight=1 max_fails=2 fail_timeout=10s;
server 192.168.9.138:8848 weight=1 max_fails=2 fail_timeout=10s;
}
server {
listen 80; #此处使用80端口
server_name localhost;
location / {
root html;
index index.html index.htm;
proxy_pass http://nacos/; #此处配置为nacos为上面的负载均衡配置的upstream后面的名称
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
}
}
}
- 创建nginx编排文件
version: '3.7'
services: #表示下面都是服务
nginx-proxy: #表示服务名为nginx-proxy
image: 192.168.9.136:8080/nginx/nginx@sha256:2f14a471f2c2819a3faf88b72f56a0372ff5af4cb42ec45aab00c03ca5c9989f #镜像链接
volumes: #把本地路径挂载到容器
- /data/nginx/conf/conf1/nginx.conf:/etc/nginx/nginx.conf
- /data/nginx/logs/logs1:/var/log/nginx/
networks: #指定网卡
- host
deploy:
mode: global
placement:
constraints: [node.labels.nginx == true]
networks:
host:
external: true
扫描二维码,在手机上阅读
版权所有:小破站
文章标题:centos使用portainer部署nacos集群
文章链接:https://www.jishuliu.cn/?post=9
本站文章均为原创,未经授权请勿用于任何商业用途
文章标题:centos使用portainer部署nacos集群
文章链接:https://www.jishuliu.cn/?post=9
本站文章均为原创,未经授权请勿用于任何商业用途