标签:swa 添加 requested cas delay ttl host zed instr
Docker Swarm 是 Docker 的集群管理工具。它将 Docker 主机池转变为单个虚拟 Docker 主机。 Docker Swarm 提供了标准的 Docker API,所有任何已经与 Docker 守护程序通信的工具都可以使用 Swarm 轻松地扩展到多个主机。
支持的工具包括但不限于以下各项:
如上图所示,swarm 集群由管理节点(manager)和工作节点(work node)构成。
docker swarm
master主机 | node1主机 | node2主机 |
192.168.1.1 | 192.168.1.2 | 192.168.1.4 |
#初始化docker swarm集群 [root@master ~]# docker swarm init --advertise-addr 192.168.1.1 Swarm initialized: current node (iygbj3p7fy5r5iamh8vnmfiy9) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-27agu7b7s7uadjmenr0u4xjn8wq054g10thqrs6evx4tedry6v-438686bomufj7hux98opa5mmz 192.168.1.1:2377 To add a manager to this swarm, run ‘docker swarm join-token manager‘ and follow the instructions.
上边返回的结果告诉我们:初始化成功,并且,如果想要添加work节点运 行下面的命令:
docker swarm join --token SWMTKN-1-27agu7b7s7uadjmenr0u4xjn8wq054g10thqrs6evx4tedry6v-438686bomufj7hux98opa5mmz 192.168.1.1:2377
这里执行的节点只能在24小时有效!如需永久如下命令即可!
添加manager节点运行命令如下:
docker swarm join-token manager
#查看docker swarm加入的节点,此命令只能在manager节点执行! [root@master ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION iygbj3p7fy5r5iamh8vnmfiy9 * master Ready Active Leader 20.10.3 5fb4hsoxyl1sesv8rg8niya3n node1 Ready Active 18.06.1-ce 9ga8eol8vodhhodtlnad35s4u node2 Ready Active 18.06.1-ce
常用命令
#将节点离开集群 [root@node1 ~]# docker swarm leave Node left the swarm. [root@node2 ~]# docker swarm leave Node left the swarm. #在master查看 [root@master ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION iygbj3p7fy5r5iamh8vnmfiy9 * master Ready Active Leader 20.10.3 5fb4hsoxyl1sesv8rg8niya3n node1 Down Active 18.06.1-ce 9ga8eol8vodhhodtlnad35s4u node2 Down Active 18.06.1-ce
#在加入swarm集群,先生成join令牌 docker swarm join-token [manager | worker]:生成令牌,可以是 manager身份或worker身份。 [root@master ~]# docker swarm join-token worker To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-27agu7b7s7uadjmenr0u4xjn8wq054g10thqrs6evx4tedry6v-438686bomufj7hux98opa5mmz 192.168.1.1:2377 #复制到加入的节点即可。 #删除node节点,删除节点为down的状态才可以进行删除 [root@master ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION iygbj3p7fy5r5iamh8vnmfiy9 * master Ready Active Leader 20.10.3 5fb4hsoxyl1sesv8rg8niya3n node1 Down Active 18.06.1-ce ycfgtitwkdyo9gnh98uy4td4z node1 Down Active 18.06.1-ce pm3w9jfhntp2e7ft8psnk5wth node2 Down Active 18.06.1-ce [root@master ~]# docker node rm pm3w9jfhntp2e7ft8psnk5wth ycfgtitwkdyo9gnh98uy4td4z 5fb4hsoxyl1sesv8rg8niya3n pm3w9jfhntp2e7ft8psnk5wth ycfgtitwkdyo9gnh98uy4td4z 5fb4hsoxyl1sesv8rg8niya3n [root@master ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION iygbj3p7fy5r5iamh8vnmfiy9 * master Ready Active Leader 20.10.3
1 #overlay:覆盖型网络。 2 #创建一个类型为overlay的网络,network网卡名称为docker 3 [root@master ~]# docker network create -d overlay --attachable docker 4 qv2bik9lw7xv77kene9mi3vux 5 --attachable参数:必须加,否则容器不可以。 6 此网络在worker节点不可以查看,但可用,manager可以! 7 [root@master ~]# docker network ls 8 NETWORK ID NAME DRIVER SCOPE 9 c1ef1eb53a9a bridge bridge local 10 qv2bik9lw7xv docker overlay swarm 11 804db36d48a5 docker_gwbridge bridge local 12 b61e22116929 host host local 13 r0bvaffd6kuj ingress overlay swarm 14 8a24d0c21f6c none null local 15 #测试分别在3台主机开启容器,使用docker网络 16 #创建容器 17 [root@master ~]# docker run -it --name a --network docker busybox:latest 18 19 [root@node1 ~]# docker run -it --name a2 --network docker busybox:latest 20 21 [root@node2 ~]# docker run -it --name a3 --network docker busybox:latest 22 # 23 [root@master ~]# docker run -it --name a --network docker busybox:latest 24 docker: Error response from daemon: Invalid container name (a), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed. 25 See ‘docker run --help‘. 26 [root@master ~]# docker run -it --name a1 --network docker busybox:latest 27 / # 28 / # ping a2 29 PING a2 (10.0.1.4): 56 data bytes 30 64 bytes from 10.0.1.4: seq=0 ttl=64 time=0.823 ms 31 64 bytes from 10.0.1.4: seq=1 ttl=64 time=0.327 ms 32 ^C 33 --- a2 ping statistics --- 34 2 packets transmitted, 2 packets received, 0% packet loss 35 round-trip min/avg/max = 0.327/0.575/0.823 ms 36 / # ping a3 37 PING a3 (10.0.1.6): 56 data bytes 38 64 bytes from 10.0.1.6: seq=0 ttl=64 time=1.674 ms 39 64 bytes from 10.0.1.6: seq=1 ttl=64 time=0.535 ms 40 ^C 41 --- a3 ping statistics --- 42 2 packets transmitted, 2 packets received, 0% packet loss 43 round-trip min/avg/max = 0.535/1.104/1.674 ms
[root@master ~]# docker run -d -p 8080:8080 -e HOST=192.168.1.1 -e PORT=8080 -v /var/run/docker.sock:/var/run/docker.sock --name visualizer dockersamples/visualizer b793e13b3da9ab9f4c6a19c88a4274ba752b2e87c659294de6571d8d55884872 [root@master ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b793e13b3da9 dockersamples/visualizer "npm start" 5 seconds ago Up 4 seconds (health: starting) 0.0.0.0:8080->8080/tcp visualizer
搭建一个私有仓库,从私有仓库中进行下载镜像
#运行私有仓库服务 ]# docker pull registry:2 ]# docker run -itd --name registry --restart=always -p 5000:5000 -v /registry:/var/lib/registry registry:2 -v: 挂载目录。 宿主机的目录:容器内的目录。 #//因为我们使用的私有镜像,在上传或下载的时候,都需要我们将镜像的名 称直接重命名,要注明它私有仓库的IP地址:暴露端口。切记是必须,否则 将识别不到仓库而上传或下载失败。 docker tag 原有镜像 修改镜像名称 #编辑docker的配置文件,指定私有仓库地址 vim /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd --insecure-registry 192.168.1.1:5000 #修改完docker配置文件,重启docker //验证私有仓库是否配置成功 可以用如下命令: ]# docker info Insecure Registries: 192.168.1.1:5000 127.0.0.0/8
#节点操作一模一样
要求:基于httpd镜像,更改主访问界面内容。镜像tag版本为v1.v2.v3,对 应主机面内容为v1、v2、v3
FROM 683a7aad17d3 #基于683镜像(683为本机httpd的镜像) RUN echo v1 > /usr/local/apache2/htdocs/index.html #run运行的shell命令将v1写入到 /usr/local/apache2/htdocs/index.html #v2、v3修改即可
要求: 副本数量为3个。服务的名称为:web
#docker swarm运行httpd:v1镜像生成容器名称为web,replicas副本集为3个(相当于3个容器),映射容器内部80的端口 [root@master ~]# docker service create --replicas 3 --name web -p 80 192.168.1.1:5000/httpd:v1 elfsbdlxbnyrxq326863m1vq9 overall progress: 3 out of 3 tasks 1/3: running 2/3: running 3/3: running verify: Service converged #不写network默认使用ingress,ingress网卡提供为后端的的container的统一入口。
扩容与缩容直接直接通过scale进行设置副本数量。 [root@master ~]# docker service scale web=6 web scaled to 6 overall progress: 6 out of 6 tasks 1/6: running 2/6: running 3/6: running 4/6: running 5/6: running 6/6: running verify: Service converged
#将镜像更新为 192.168.1.1:5000/httpd:v2 更新的副本集是web [root@master ~]# docker service update --image 192.168.1.1:5000/httpd:v2 web web overall progress: 6 out of 6 tasks 1/6: running 2/6: running 3/6: running 4/6: running 5/6: running 6/6: running verify: Service converged #平滑的升级 [root@master ~]# docker service update --image 192.168.1.1:5000/httpd:v3 --update-parallelism 2 --update-delay 1m web 解释: --update-parallelism:每一次更新副本集的数量 --update-delay:中间间隔时间 m分钟 s秒 #回滚,这是swarm不如k8s的一个点,回滚只能是上一层 [root@master ~]# docker service rollback web web rollback: manually requested rollback overall progress: rolling back update: 6 out of 6 tasks 1/6: running 2/6: running 3/6: running 4/6: running 5/6: running 6/6: running verify: Service converged
标签:swa 添加 requested cas delay ttl host zed instr
原文地址:https://www.cnblogs.com/lin-strive/p/14468952.html