创建一个集群

[vagrant@node1 ~]$ docker swarm init --advertise-addr 192.168.9.101
Swarm initialized: current node (9fv7wb4zve235hltmchxprez7) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN--1wk8aduuxnay6ek866xaj31ixqnsib56b3p65hpzpcbbzo1qla-alcf8l1n7qpv7h7d6hg35scni 192.168.9.101: To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

查看网络

[vagrant@node1 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
83c5df0f97ac bridge bridge local
7d81897af218 docker_gwbridge bridge local
b13ca5d9c552 host host local
0vfhc5c85dwi ingress overlay swarm
c427f9d683f4 none null local

分别在另外两台上面执行

[vagrant@node2 ~]$ docker swarm join --token SWMTKN--1wk8aduuxnay6ek866xaj31ixqnsib56b3p65hpzpcbbzo1qla-alcf8l1n7qpv7h7d6hg35scni 192.168.9.101:
This node joined a swarm as a worker.
[vagrant@node3 ~]$ docker swarm join --token SWMTKN--1wk8aduuxnay6ek866xaj31ixqnsib56b3p65hpzpcbbzo1qla-alcf8l1n7qpv7h7d6hg35scni 192.168.9.101:
This node joined a swarm as a worker.

查看集群节点

[vagrant@node1 ~]$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
9fv7wb4zve235hltmchxprez7 * node1 Ready Active Leader 19.03.
lypcp8z6s2boi2897ni0g5oc5 node2 Ready Active 19.03.
o0hmpgi59tms2lt65wlgzivpn node3 Ready Active 19.03.

提升node2,node3 为备用master,高可用

[vagrant@node1 ~]$ docker node promote node2
[vagrant@node1 ~]$ docker node promote node3

查看效果:

[vagrant@node1 ~]$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
9fv7wb4zve235hltmchxprez7 * node1 Ready Active Leader 19.03.
lypcp8z6s2boi2897ni0g5oc5 node2 Ready Active Reachable 19.03.
o0hmpgi59tms2lt65wlgzivpn node3 Ready Active 19.03.

创建服务

[vagrant@node1 ~]$ docker service create --name test1 alpine ping www.baidu.com
i5lip5az4w5ehv28q2fn3jxji
overall progress: out of tasks
/: running [==================================================>]
verify: Service converged
[vagrant@node1 ~]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
i5lip5az4w5e test1 replicated / alpine:latest

创建nginx服务

vagrant@node1 ~]$ docker service create --name nginx nginx
m511a51xd6js4lflrrtr91vf7
overall progress: out of tasks
overall progress: out of tasks
overall progress: out of tasks
overall progress: out of tasks
overall progress: out of tasks
overall progress: out of tasks
/: running [==================================================>]
verify: Service converged

爆过 8080服务

[vagrant@node1 ~]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
m511a51xd6js nginx replicated / nginx:latest
i5lip5az4w5e test1 replicated / alpine:latest
[vagrant@node1 ~]$ docker service update --publish-add : nginx
nginx
overall progress: out of tasks
/: running [==================================================>]
verify: Service converged
[vagrant@node1 ~]$

扩容:

[vagrant@node1 ~]$ docker service scale nginx=
nginx scaled to
overall progress: out of tasks
/: running [==================================================>]
/: running [==================================================>]
/: running [==================================================>]

删除服务:

[vagrant@node1 ~]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
m511a51xd6js nginx replicated / nginx:latest *:->/tcp
i5lip5az4w5e test1 replicated / alpine:latest
[vagrant@node1 ~]$ docker service rm nginx
nginx
[vagrant@node1 ~]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
i5lip5az4w5e test1 replicated / alpine:latest

创建网络

[vagrant@node1 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
83c5df0f97ac bridge bridge local
7d81897af218 docker_gwbridge bridge local
b13ca5d9c552 host host local
0vfhc5c85dwi ingress overlay swarm
c427f9d683f4 none null local
meps4tilzidi test_tanzi-overlay overlay swarm
[vagrant@node1 ~]$ docker network
connect create disconnect inspect ls prune rm
[vagrant@node1 ~]$ docker network create -d overlay tanzi-overlay
p3ssr7hpilfr1k6qry6tp8nc5

创建服务并指定网络

[vagrant@node1 ~]$ docker service create --network tanzi-overlay --name nginx -p : nginx
p3b79k42mvex1op5mwk9zfg1z
overall progress: out of tasks
/: running [==================================================>]
verify: Service converged
[vagrant@node1 ~]$ docker service create --network tanzi-overlay --name alpine alpine ping www.baidu.com
34tkwuppcgb5pqppj1zx22hhr
overall progress: out of tasks
/: running [==================================================>]
verify: Service converged

定义一种不给外面访问的dnsrr的访问模式

[vagrant@node1 ~]$ docker service create --name nginx-b --endpoint-mode dnsrr nginx
u9snzqigr65x9xwb131jkm1ao
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged

更新一个服务

[vagrant@node1 ~]$ docker service update --network-add tanzi-overlay nginx-b
nginx-b
overall progress: out of tasks
/: running [==================================================>]
verify: Service converged

定一个组,确定依赖关系:

[vagrant@node1 ~]$ docker stack services
nginx test2
[vagrant@node1 ~]$ docker stack services nginx
ID NAME MODE REPLICAS IMAGE PORTS
7ti9w26od1i3 nginx_nginx replicated / nginx:latest *:->/tcp
cl1awlwzmxaq nginx_alpine replicated / alpine:latest
[vagrant@node1 ~]$ docker stack deploy -c test.yml nginx
Updating service nginx_alpine (id: cl1awlwzmxaqybwyz09a3sr5t)
Updating service nginx_nginx (id: 7ti9w26od1i3yec6jmxcalwfz)
[vagrant@node1 ~]$ docker stack services
"docker stack services" requires exactly argument.
See 'docker stack services --help'. Usage: docker stack services [OPTIONS] STACK List the services in the stack
[vagrant@node1 ~]$ docker stack services ls
Nothing found in stack: ls
[vagrant@node1 ~]$ docker stack services
nginx test2
[vagrant@node1 ~]$ docker stack services test2
ID NAME MODE REPLICAS IMAGE PORTS
celxgkxf3z31 test2_alpine replicated / alpine:latest
[vagrant@node1 ~]$ docker stack services nginx
ID NAME MODE REPLICAS IMAGE PORTS
7ti9w26od1i3 nginx_nginx replicated / nginx:latest *:->/tcp
cl1awlwzmxaq nginx_alpine replicated / alpine:latest
version: "3.7"
services:
nginx:
image: nginx
networks:
- "tanzi-overlay"
ports:
- "8080:80" alpine:
image: alpine
networks:
- "tanzi-overlay"
command:
- "ping"
- "nginx"
deploy:
replicas:
restart_policy:
condition: on-failure
resources:
limits:
cpus: "0.1"
memory: 50M
depends_on:
- nginx networks:
tanzi-overlay:
external: true

docker swarm 集群搭建的更多相关文章

  1. docker swarm集群搭建及使用Portainer、shipyard

    一.规划 1.swarm01作为manager节点,swarm02和swarm03作为worker节点. # cat /etc/hosts 127.0.0.1   localhost 192.168. ...

  2. 分享:docker swarm集群搭建

    [Y_H]实践原创 三台虚拟机:1台centOS , 2台ubuntu.   网上有用docker-machine创建虚拟机做的例子.   这里直接用VMware创建这三台虚拟机,然后用xshell连 ...

  3. docker swarm集群搭建以及使用滚动更新

    基础环境,三台虚拟机 172.17.3.70 172.17.3.71 172.17.3.72 系统配置:centos 7,关闭selinux 需要优化的基础配置: [root@sw1 ~]# vim ...

  4. Docker swarm集群搭建教程

    一.什么是Swarm Swarm这个项目名称特别贴切.在Wiki的解释中,Swarm behavior是指动物的群集行为.比如我们常见的蜂群,鱼群,秋天往南飞的雁群都可以称作Swarm behavio ...

  5. DOCKER 学习笔记8 Docker Swarm 集群搭建

    前言 在前面的文章中,已经介绍如何在本地通过Docker Machine 创建虚拟Docker 主机,以及也可以在本地Windows 创建虚拟主机,也是可以使用的.这一节,我们将继续学习 Docker ...

  6. docker swarm集群搭建

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: swarm是docker原生的集群管理软件,与kuberne ...

  7. 从零开始搭建Docker Swarm集群

    从零开始搭建Docker Swarm集群 检查节点Docker配置 1. 打开Docker配置文件(示例是centos 7)vim /etc/sysconfig/docker2. 添加-H tcp:/ ...

  8. Docker系列之swarm集群搭建

    学习Docker很久了,今天分享一下Docker的swarm集群的搭建过程很简单 首先第一步是 每台机器上面都要安装docker 本人使用的是centos7操作系统,使用3太虚拟机,3太虚拟机必须网络 ...

  9. Docker Swarm 集群环境搭建及弹性服务部署

    上一篇文章<Docker Swarm 集群管理利器核心概念扫盲>中我们把 Swarm 重要的概念性知识给大家讲解了一波,理论完事就该实战了,这篇文章带大家从零开始,搭建 Docker Sw ...

随机推荐

  1. iOS 关于NavigationController返回的一些笔记

    1.理解NavigationController返回机制 一般NavigationController下的子view只有一层或者有很多层,子view返回最顶层则可以直接用 [self.navigati ...

  2. Django下JWT的使用

    前言 JWT 是 json web token 的缩写, token的作用你应该已经了解,用于识别用户身份避免每次请求都需要验证 用来解决前后端分离时的用户身份验证 在传统的web项目中 我们会在fo ...

  3. JavaScript基础内容中的函数详解

    函数 函数:即方法 函数就是一段预先设置的功能代码块,可以反复调用,根据输入参数的不同,返回不同的值. 为什么使用函数: 1.方便调用 2.代码重用,利于维护 3.便于修改,便于重构 4.简化逻辑,利 ...

  4. win2003下安装python3.4 + pyspider

    昨天尝试了在win2003下安装python2.7.这个是文章地址:https://www.cnblogs.com/alpiny/p/11706606.html 但是程序跑了一晚上,发现有一点问题,是 ...

  5. 【Git版本控制】为什么要先commit,然后pull,最后再push?而不是commit然后直接push?

    情况是这样的,现在远程有一个仓库,分支就一个,是master.然后我本地的仓库是从远程的master上clone下来的.大家都是clone下来,再在自己本地改好,再commit然后pull然后push ...

  6. Odoo字段类型详解

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826099.html   一:基本字段类型 Binary:二进制类型,用于保存图片.视频.文件.附件等,在 ...

  7. LoarRunner脚本录制-Port Mapping

    使用LR录制脚本时经常会因为内外网访问限制,或浏览器兼容等问题,导致无法正常录制脚本. 这里简单介绍一下使用LR端口映射的方式进行脚本录制,与之前介绍的<Jmeter脚本录制--HTTP代理服务 ...

  8. Unity 渲染教程(二):着色器基础

    转载:https://www.jianshu.com/p/7db167704056 这是关于渲染基础的系列教程的第二部分.这个渲染基础的系列教程的第一部分是有关矩阵的内容.在这篇文章中我们将编写我们的 ...

  9. Linux四剑客之awk命令

    AWK详解   awk简介 awk其名称得自于它的创始人 Alfred Aho .Peter Weinberger 和 Brian Kernighan 姓氏的首个字母.实际上 AWK 的确拥有自己的语 ...

  10. 201671030118 索郎卓玛 实验十四 团队项目评审&课程学习总结

    项目 内容 作业课程地址 任课教师首页链接 作业要求 团队项目评审&课程学习总结 课程学习目标 项目的验收以及课程的学习进行总结与反思 一 对<实验一 软件工程准备>的任务提出的问 ...