创建一个集群

[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. Golang: 抓取网页内容

    今天写个简单的程序,根据指定的 URL 来抓取相应的网页内容,然后存入本地文件.这个程序会涉及到网络请求和文件操作等知识点,下面是实现代码: // fetch.go package main impo ...

  2. 【Nginx】使用certbot安装免费https证书使Nginx支持Https请求

    certbot官网:https://certbot.eff.org/lets-encrypt/centosrhel7-nginx 一.安装步骤 1)安装certbot,执行  sudo yum ins ...

  3. Httpd服务入门知识-正向代理和反向代理

    Httpd服务入门知识-正向代理和反向代理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.正向代理和反向代理 启用反向代理 ProxyPass "/" &q ...

  4. 计算机 KB,MB,GB,TB,PB,EB 计算

    ASCII码:一个英文字母(不分大小写)占一个字节的空间.一个二进制数字序列,在计算机中作为一个数字单元,一般为8位二进制数.换算为十进制,最小值-128,最大值127.如一个ASCII码就是一个字节 ...

  5. shell脚本攻略1

    换行符 \n echo -n 禁止换行 环境变量声明export export PATH="$PATH:/home/user/bin" 获取字符串的长度 length=${#var ...

  6. Game-Based Learning Is Changing How We Teach. Here's Why.

    https://www.edsurge.com/news/2019-02-04-game-based-learning-is-changing-how-we-teach-here-s-why This ...

  7. vue.js不仅是一种模式,也是一种工程组织方式

    vue.js不仅是一种模式,也是一种工程组织方式

  8. Linux正则表达式与通配符

    在linux中,有通配符和正则表达式,这是两个不同的概念通配符:它是由shell解析,并且一般用于匹配文件名.如:ls正则表达式:是一个字符匹配标准,可以匹配文本中的内容一些命令工具按此标准实现字符匹 ...

  9. [Algorithm] 122. Best Time to Buy and Sell Stock II

    Previous one: https://www.cnblogs.com/Answer1215/p/11974453.html Say you have an array for which the ...

  10. MySQL binlog2sql实现MySQL误操作的恢复

    对于MySQL数据库中的误操作删除数据的恢复问题,可以使用基于MySQL中binlog做到类似于闪回或者生成反向操作的SQL语句来实现,是MySQL中一个非常实用的功能.原理不难理解,基于MySQL的 ...