56.111.111.100 master
56.111.111.101 slave1
56.111.111.102 slave2
hostnamectl set-hostname 新的主机名
vim /lib/systemd/system/docker.service
# 可通过 find 命令 查找 docker.service 文件
# find / -name docker.service
## 在“ExecStart=/usr/bin/dockerd”后添加“-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock”
# 如下
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock -H fd:// --containerd=/run/containerd/containerd.sock
systemctl daemon-reload
systemctl restart docker
#56.111.111.100 本机ip
docker swarm init --advertise-addr 56.111.111.100
docker swarm join --token SWMTKN-1-3oovrzba9wjaf4fe5i3mbdnksmrdb0mjfw206qmxpsbiflmxw5-bcjueneetcbvgdhhtk3awkfno 56.111.111.100:2377
docker node ls
//要加入集群的主机
[root@localhost ~]# docker swarm join --token SWMTKN-1-3oovrzba9wjaf4fe5i3mbdnksmrdb0mjfw206qmxpsbiflmxw5-bcjueneetcbvgdhhtk3awkfno 56.111.111.100:2377
[root@master /]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
x2h88pu8237u0aqbqnmvy3vnc * master Ready Active Leader 19.03.5
uzwuj9aavrvw6fdcisoiigktm slave1 Ready Active 19.03.5
pdwlvvud2t08565njvw63ssuv slave2 Ready Active 19.03.4
mkdir portainer
//创建portainer-agent-stack.yml文件
vim portainer-agent-stack.yml yml文件
version: '3.2'
services:
agent:
image: portainer/agent:2.11.1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
networks:
- agent_network
deploy:
mode: global
placement:
constraints: [node.platform.os == linux]
portainer:
image: portainer/portainer-ce:2.11.1
command: -H tcp://tasks.agent:9001 --tlsskipverify
ports:
- "9443:9443"
- "9000:9000"
- "8000:8000"
volumes:
- portainer_data:/data
networks:
- agent_network
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
networks:
agent_network:
driver: overlay
attachable: true
volumes:
portainer_data:
##直接创建服务
docker stack deploy -c portainer-agent-stack.yml portainer
docker stack ls
docker stack ps portainer