104、驗證Swarm數據持久性 (Swarm11)
阿新 • • 發佈:2019-05-16
ima failed usr 丟失 成功 inspect radius mode col 參考https://www.cnblogs.com/CloudMan6/p/8016994.html
上一節我們成功將 nfs 的volume掛載到 Service上,本節驗證 Failover時,數據會不會丟失。
Scale Up
增加副本,並驗證數據是否能夠同步到新啟動的容器上
[email protected]:~# 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
[email protected]:~# 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
[email protected]:~# 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": ""
}
]
[email protected]:~# docker exec my_web.4.znf4m0jpa0r5p3fklp1hgdwhu cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
[email protected]:~# 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": ""
}
]
[email protected]:~# docker exec my_web.3.f4tg54ze3hggppy96jldhtdxs cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
更新Volume內容,並進行驗證
[email protected]:~# echo "add test str" >> /var/nfs/index.html
[email protected]:~# cat /var/nfs/index.html
docker swarm nfs volume test
add test str
[email protected]:~# curl http://10.12.31.211
docker swarm nfs volume test
add test str
[email protected]:~# curl http://10.12.31.212
docker swarm nfs volume test
add test str
[email protected]:~# curl http://10.12.31.213
docker swarm nfs volume test
add test str
[email protected]:~# 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
[email protected]:~# docker exec my_web.1.a2v73m955o9js3fbihf0dwei6 cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
[email protected]:~# docker exec my_web.4.znf4m0jpa0r5p3fklp1hgdwhu cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
[email protected]:~# docker exec my_web.2.uzdfouv3s2bz0ohyahjeeyqao cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
[email protected]:~# docker exec my_web.3.f4tg54ze3hggppy96jldhtdxs cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
Failover 驗證,host01關機
[email protected]:~# 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
[email protected]:~# 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
[email protected]:~# 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
[email protected]:~# 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
[email protected]:~# docker exec my_web.1.i4j8tplkkq348ae0tcdcrl38r cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
[email protected]:~# docker exec my_web.4.ve0j4of1m1aosbmpg9yew8dxr cat /usr/local/apache2/htdocs/index.html
docker swarm nfs volume test
add test str
[email protected]:~# 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
[email protected]:~# curl http://10.12.31.212
docker swarm nfs volume test
add test str
[email protected]:~# curl http://10.12.31.213
docker swarm nfs volume test
add test str
104、驗證Swarm數據持久性 (Swarm11)