一、创建集群
1、初始化manager节点(xxx为manager的ip地址)
docker swarm init --advertise-addr xxx.xxx.xxx.xxx
会输出以下内容,注意加粗斜体命令,加入集群需要使用
Swarm initialized: current node (pk4p936t4e03cpse3izuws07s) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join –token xxx xxx.xxx.xxx.xxx:2377
To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
2、worker加入集群,在其他docker服务器运行上面命令
docker swarm join --token xxx xxx.xxx.xxx.xxx:2377
3、查看集群情况
docker node ls
二、安装Portainer
1、创建portainer-stack.yml文件
version: '3'
services:
portainer:
image: portainer/portainer
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/data/portainer:/data"
deploy:
placement:
constraints: [node.role == manager] # 控制管理界面部署在manager上
replicas: 1
restart_policy:
condition: on-failure
resources:
limits:
cpus: "0.2"
memory: 200M
labels: [svc=portainer]
ports:
- 9000:9000
2、启动portainer服务
docker stack deploy -c portainer-stack.yml portainer
3、访问portainer并修改密码(xxx为集群的任意一台ip,swarm会自动做负载均衡)
访问http://xxx.xxx.xxx.xxx:9000
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/184954.html