上一节我们成功将 nfs 的volume挂载到 Service上,本节验证 Failover时,数据会不会丢失。
 
Scale Up
 
增加副本,并验证数据是否能够同步到新启动的容器上
 
root@host03:~# docker service update --replicas 4 my_web
my_web
overall progress: 4 out of 4 tasks
1/4: running   [==================================================>]
2/4: running   [==================================================>]
3/4: running   [==================================================>]
4/4: running   [==================================================>]
verify: Service converged
root@host03:~# docker service ps my_web
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
a2v73m955o9j        my_web.1            httpd:latest        host01              Running             Running 13 minutes ago                       
uzdfouv3s2bz        my_web.2            httpd:latest        host02              Running             Running 13 minutes ago                       
f4tg54ze3hgg        my_web.3            httpd:latest        host02              Running             Running 14 seconds ago                       
znf4m0jpa0r5        my_web.4            httpd:latest        host01              Running             Running 14 seconds ago              
 
root@host01:~# docker inspect my_web.4.znf4m0jpa0r5p3fklp1hgdwhu | jq .[0].Mounts
[
  {
    "Type": "volume",
    "Name": "volume-nfs",
    "Source": "/var/lib/docker/volumes/volume-nfs/_data",
    "Destination": "/usr/local/apache2/htdocs",
    "Driver": "local",
    "Mode": "z",
    "RW": true,
    "Propagation": ""
  }
]
root@host01:~# docker exec my_web.4.znf4m0jpa0r5p3fklp1hgdwhu cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
 
root@host02:~# docker inspect my_web.3.f4tg54ze3hggppy96jldhtdxs | jq .[0].Mounts
[
  {
    "Type": "volume",
    "Name": "volume-nfs",
    "Source": "/var/lib/docker/volumes/volume-nfs/_data",
    "Destination": "/usr/local/apache2/htdocs",
    "Driver": "local",
    "Mode": "z",
    "RW": true,
    "Propagation": ""
  }
]
root@host02:~# docker exec my_web.3.f4tg54ze3hggppy96jldhtdxs cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
 
更新Volume内容,并进行验证
 
root@host03:~# echo "add test str" >> /var/nfs/index.html
root@host03:~# cat /var/nfs/index.html
docker swarm nfs volume test
add test str
                 
root@host03:~# curl http://10.12.31.211
docker swarm nfs volume test
add test str
root@host03:~# curl http://10.12.31.212
docker swarm nfs volume test
add test str
root@host03:~# curl http://10.12.31.213
docker swarm nfs volume test
add test str
 
root@host03:~# docker service ps my_web
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
a2v73m955o9j        my_web.1            httpd:latest        host01              Running             Running 17 minutes ago                       
uzdfouv3s2bz        my_web.2            httpd:latest        host02              Running             Running 17 minutes ago                       
f4tg54ze3hgg        my_web.3            httpd:latest        host02              Running             Running 4 minutes ago                        
znf4m0jpa0r5        my_web.4            httpd:latest        host01              Running             Running 4 minutes ago       
 
root@host01:~# docker exec my_web.1.a2v73m955o9js3fbihf0dwei6 cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
root@host01:~# docker exec my_web.4.znf4m0jpa0r5p3fklp1hgdwhu cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
 
root@host02:~# docker exec my_web.2.uzdfouv3s2bz0ohyahjeeyqao cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
root@host02:~# docker exec my_web.3.f4tg54ze3hggppy96jldhtdxs cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
 
Failover 验证,host01关机
 
root@host03:~# docker service ps my_web
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
a2v73m955o9j        my_web.1            httpd:latest        host01              Running             Running 9 seconds ago                        
uzdfouv3s2bz        my_web.2            httpd:latest        host02              Running             Running 21 minutes ago                       
f4tg54ze3hgg        my_web.3            httpd:latest        host02              Running             Running 8 minutes ago                        
znf4m0jpa0r5        my_web.4            httpd:latest        host01              Running             Running 9 seconds ago                        
root@host03:~# docker service ps my_web
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE                  ERROR               PORTS
i4j8tplkkq34        my_web.1            httpd:latest        host02              Ready               Ready less than a second ago                       
a2v73m955o9j         \_ my_web.1        httpd:latest        host01              Shutdown            Running 10 seconds ago                             
uzdfouv3s2bz        my_web.2            httpd:latest        host02              Running             Running 21 minutes ago                             
f4tg54ze3hgg        my_web.3            httpd:latest        host02              Running             Running 8 minutes ago                              
ve0j4of1m1ao        my_web.4            httpd:latest        host02              Ready               Ready less than a second ago                       
znf4m0jpa0r5         \_ my_web.4        httpd:latest        host01              Shutdown            Running 10 seconds ago                             
root@host03:~# docker service ps my_web
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
i4j8tplkkq34        my_web.1            httpd:latest        host02              Running             Ready 4 seconds ago                          
a2v73m955o9j         \_ my_web.1        httpd:latest        host01              Shutdown            Running 15 seconds ago                       
uzdfouv3s2bz        my_web.2            httpd:latest        host02              Running             Running 21 minutes ago                       
f4tg54ze3hgg        my_web.3            httpd:latest        host02              Running             Running 8 minutes ago                        
ve0j4of1m1ao        my_web.4            httpd:latest        host02              Running             Ready 4 seconds ago                          
znf4m0jpa0r5         \_ my_web.4        httpd:latest        host01              Shutdown            Running 15 seconds ago                    
 
root@host02:~# docker ps | grep my_web
e46bd42b6fda        httpd:latest        "httpd-foreground"   About a minute ago   Up About a minute   80/tcp              my_web.4.ve0j4of1m1aosbmpg9yew8dxr
5338df22fc68        httpd:latest        "httpd-foreground"   About a minute ago   Up About a minute   80/tcp              my_web.1.i4j8tplkkq348ae0tcdcrl38r
426a79228471        httpd:latest        "httpd-foreground"   10 minutes ago       Up 10 minutes       80/tcp              my_web.3.f4tg54ze3hggppy96jldhtdxs
5c5fffec6de6        httpd:latest        "httpd-foreground"   23 minutes ago       Up 23 minutes       80/tcp              my_web.2.uzdfouv3s2bz0ohyahjeeyqao
root@host02:~# docker exec my_web.1.i4j8tplkkq348ae0tcdcrl38r cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
root@host02:~# docker exec my_web.4.ve0j4of1m1aosbmpg9yew8dxr cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
 
root@host03:~# curl http://10.12.31.211    #    因为host01 关机了,所有host01的ip也访问不了了
curl: (7) Failed to connect to 10.12.31.211 port 80: No route to host
root@host03:~# curl http://10.12.31.212
docker swarm nfs volume test
add test str
root@host03:~# curl http://10.12.31.213
docker swarm nfs volume test
add test str
 
 
 

104、验证Swarm数据持久性 (Swarm11)的更多相关文章

  1. 验证 Swarm 数据持久性 - 每天5分钟玩转 Docker 容器技术(104)

    上一节我们成功将 Rex-Ray Volume 挂载到了 Service.本节验证 Failover 时,数据不会丢失. Scale Up 增加一个副本: docker service update ...

  2. 使用JSON Schema来验证接口数据

    最近在做一些关于JSON Schema的基建,JSON Schema可以描述一个JSON结构,那么反过来他也可以来验证一个JSON是否符合期望的格式. 如果之前看我写的<使用joi来验证数据模型 ...

  3. PHP正则自动验证传入数据

    本文出至:新太潮流网络博客 /** * [is_string_regular_type 正则自动验证传入数据] * @E-mial wuliqiang_aa@163.com * @TIME 2017- ...

  4. 04: Form 验证用户数据 & 生成html

    目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...

  5. vue学习记录:vue引入,validator验证,数据信息,vuex数据共享

    最近在学习vue,关于学习过程中所遇到的问题进行记录,包含vue引入,validator验证,数据信息,vuex数据共享,传值问题记录 1.vue 引入vue vue的大致形式如下: <temp ...

  6. 基于Volley,Gson封装支持JWT无状态安全验证和数据防篡改的GsonRequest网络请求类

    这段时间做新的Android项目的client和和REST API通讯框架架构设计.使用了非常多新技术,终于的方案也相当简洁优雅.client仅仅须要传Java对象,server端返回json字符串, ...

  7. Android Studio 之 SharedPrefences 数据持久性保存

    SharedPreferences 会在应用包目录中生成一个xml文件,将数据保存在里面 可以实现数据持久性保存. 创建的数据,保存在 Data -> Data -> 包名 -> s ...

  8. Ruby Rails学习中:User 模型,验证用户数据

    用户建模 一. User 模型 实现用户注册功能的第一步是,创建一个数据结构,用于存取用户的信息. 在 Rails 中,数据模型的默认数据结构叫模型(model,MVC 中的 M).Rails 为解决 ...

  9. 使用System.ComponentModel.DataAnnotations验证字段数据正确性

    在.NET MVC 中,当页面提交model到Action的时候,自动填充ModelState.使用ModelState.IsValid进行方便快捷的数据验证,其验证也是调用命名空间System.Co ...

随机推荐

  1. 【黑马JavaWeb】.1.2反射机制

    文章目录 反射:框架设计的灵魂 获取Class类对象的方式 学习视频:https://www.bilibili.com/video/av47886776?p=10 本来一万行的代码,使用框架以后简化到 ...

  2. JS编程规范

    在第一家公司用C++时,公司有着严格的代码规范,甚至到了严苛的地步,现在回想起来,对它充满感激.一个好的习惯让你收益终身. 之后使用JS/TS却没有为自己定一套编程规范,所幸为时不晚,在这里参考air ...

  3. Hadoop : MapReduce中的Shuffle和Sort分析

    地址 MapReduce 是现今一个非常流行的分布式计算框架,它被设计用于并行计算海量数据.第一个提出该技术框架的是Google 公司,而Google 的灵感则来自于函数式编程语言,如LISP,Sch ...

  4. leetcode 100. Same Tree、101. Symmetric Tree

    100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...

  5. 强大的BeautifulSoup

    Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库·它能够通过你喜欢的转换器实现惯用的文档导航 安装BeautifulSoup 推荐使用Beautiful Sou ...

  6. win10相机打不开,显示错误代码0xA00F4246(0x800706D9)

    有时我们在不知道什么情况下电脑便会变成这个样子,当我们以为是驱动问题的时候,或许我们可以使用下面的办法解决这个问题 方法: 1.WIN键+R打开命令端,输入regedit运行 2.进入 计算机\HKE ...

  7. FTP简单搭建(一)

    一.FTP服务介绍 vsftp(very security ftp file transfer protocol 非常文件传输协议) FTP分为主动模式和被动模式. 主动模式:(不安全,传数据的端口是 ...

  8. 云计算共享组件--时间同步服务NTP(2)

    一.标准时间讲解 地球分为东西十二个区域,共计 24 个时区 格林威治作为全球标准时间即 (GMT 时间 ),东时区以格林威治时区进行加,而西时区则为减. 地球的轨道并非正圆,在加上自转速度逐年递减, ...

  9. vue 导出JSON数据为Excel

    1. 安装三个依赖 npm install file-saver --save npm install xlsx --save npm install script-loader --save-dev ...

  10. java,mysql触发器,redis生成流水号(yyyyMM000)

    最近又遇到需要根据日期生成流水号的业务,然后记录了几种生成方法,一个是通过java代码,一个是数据库的触发器,还有是通过redis.下面是代码: 通过java生成简易流水: /** * 通过日期和生成 ...