docker swarm 集群搭建
创建一个集群
[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 集群搭建的更多相关文章
- docker swarm集群搭建及使用Portainer、shipyard
一.规划 1.swarm01作为manager节点,swarm02和swarm03作为worker节点. # cat /etc/hosts 127.0.0.1 localhost 192.168. ...
- 分享:docker swarm集群搭建
[Y_H]实践原创 三台虚拟机:1台centOS , 2台ubuntu. 网上有用docker-machine创建虚拟机做的例子. 这里直接用VMware创建这三台虚拟机,然后用xshell连 ...
- docker swarm集群搭建以及使用滚动更新
基础环境,三台虚拟机 172.17.3.70 172.17.3.71 172.17.3.72 系统配置:centos 7,关闭selinux 需要优化的基础配置: [root@sw1 ~]# vim ...
- Docker swarm集群搭建教程
一.什么是Swarm Swarm这个项目名称特别贴切.在Wiki的解释中,Swarm behavior是指动物的群集行为.比如我们常见的蜂群,鱼群,秋天往南飞的雁群都可以称作Swarm behavio ...
- DOCKER 学习笔记8 Docker Swarm 集群搭建
前言 在前面的文章中,已经介绍如何在本地通过Docker Machine 创建虚拟Docker 主机,以及也可以在本地Windows 创建虚拟主机,也是可以使用的.这一节,我们将继续学习 Docker ...
- docker swarm集群搭建
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: swarm是docker原生的集群管理软件,与kuberne ...
- 从零开始搭建Docker Swarm集群
从零开始搭建Docker Swarm集群 检查节点Docker配置 1. 打开Docker配置文件(示例是centos 7)vim /etc/sysconfig/docker2. 添加-H tcp:/ ...
- Docker系列之swarm集群搭建
学习Docker很久了,今天分享一下Docker的swarm集群的搭建过程很简单 首先第一步是 每台机器上面都要安装docker 本人使用的是centos7操作系统,使用3太虚拟机,3太虚拟机必须网络 ...
- Docker Swarm 集群环境搭建及弹性服务部署
上一篇文章<Docker Swarm 集群管理利器核心概念扫盲>中我们把 Swarm 重要的概念性知识给大家讲解了一波,理论完事就该实战了,这篇文章带大家从零开始,搭建 Docker Sw ...
随机推荐
- 为 Linux 应用程序编写 DLL
插件和 DLL 通常是用来无须编写整个新应用程序而添加功能的极好方法. 在 Linux 中,插件和 DLL 是以动态库形式实现的. 电子商务顾问兼设计师 Allen Wilson 介绍了动态库,并且向 ...
- kbmmw 5.10.00 发布
We are happy to announce v5.10.00 of the most complete development add on for Delphi and C++Builder ...
- Idea 热部署插件JRebel 安装与环境配置-上海尚学堂Java培训
在企业日常项目开发中,如果我们需要调试一个Java Web项目,就需要先将项目编译之后,放入Web容器或借助Maven web 插件来运行,如果对Java源代码进行修改,那么必须重新编译并重启Web容 ...
- (二)Kubernetes kubeadm部署k8s集群
kubeadm介绍 kubeadm是Kubernetes项目自带的及集群构建工具,负责执行构建一个最小化的可用集群以及将其启动等的必要基本步骤,kubeadm是Kubernetes集群全生命周期的管理 ...
- ImportError: No module named wx
先检查下Python中是否有此模块 $ python >>> import wx ImportError: No module named wx wx模块的确没有安装. 要安装wx ...
- ROS学习(更新中~)
1.一次把ROS环境变量都自动配置好(即添加到bash会话中)echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc ...
- C#各版本新增功能
本系列文章主要整理并介绍 C# 各版本的新增功能. C# 8.0 C#8.0 于 2019年4月 随 .NET Framework 4.8 与 Visual Studio 2019 一同发布,但是当前 ...
- Mysql复制一条或多条记录并插入表|mysql从某表复制一条记录到另一张表
Mysql复制一条或多条记录并插入表|mysql从某表复制一条记录到另一张表 一.复制表里面的一条记录并插入表里面 ① insert into article(title,keywords,de ...
- 下载文件的Restful接口的前端实现
背景介绍 后端是springboot框架,接口是restful风格接口,需求是异步实现一个文件下载,该文件是动态生成的,以流的方式返回给前端.存在的问题是,ajax不支持post方式传参数,并触发浏览 ...
- 二维码与json都是数据交换格式
二维码与json都是数据交换格式: UI数据是人机数据交换格式.