创建一个集群

[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. linux 如何修改默认的FTP帐号或密码

    wdlinux_lamp,wdlinux_lnmp的系统安装好后,默会创建一个FTP用户用户名是:wdlinux密码是:wdlinux.cn 如想修改密码或用户名,先找个ssh工具,有关ssh客户端的 ...

  2. linux的bash特性

    Shell本身是应用程序,是用户与操作系统之间完成交互式操作的一个接口程序,为用户提供简化的操作. Bourne Again Shell,简称bash,是Linux系统中默认的shell程序. Bas ...

  3. 使用SAP CRM中间件XIF(External Interface)一步步创建服务订单

    tcode WE19, choose an existing IDOC in the system: Just change the existing IDOC Service Order ID to ...

  4. Java集合学习(5):LinkedHashMap

    一.概述 HashMap是无序的,HashMap在put的时候是根据key的hashcode进行hash然后放入对应的地方.所以在按照一定顺序put进HashMap中,然后遍历出HashMap的顺序跟 ...

  5. vue element-ui tree 根节点固定子节点懒加载 首次加载根节点并展开

    关键代码: <el-tree ref="foldTree" node-key="id" :highlight-current="true&quo ...

  6. SpringBoot解决跨域请求拦截

    前言 同源策略:判断是否是同源的,主要看这三点,协议,ip,端口. 同源策略就是浏览器出于网站安全性的考虑,限制不同源之间的资源相互访问的一种政策. 比如在域名https://www.baidu.co ...

  7. 【转载】【凯子哥带你学Framework】Activity启动过程全解析

    It's right time to learn Android's Framework ! 前言 一个App是怎么启动起来的? App的程序入口到底是哪里? Launcher到底是什么神奇的东西? ...

  8. React源码 Hooks

    我们先初步了解下 hooks,使用 useState 和 useEffect. /** * 必须要react和react-dom 16.7以上 */ import React, { useState, ...

  9. Pytorch数据读取详解

    原文:http://studyai.com/article/11efc2bf#%E9%87%87%E6%A0%B7%E5%99%A8%20Sampler%20&%20BatchSampler ...

  10. rhel6.2配置在线yum源

    由于 redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装,再配置其他源. 本文包括配置本地源及第三方源.第三方源包括:网易,epel, ...