您好,登錄后才能下訂單哦!
管理Docker Swarm 集群
1 .節(jié)點狀態(tài)變更管理
[root@manager ~]# docker node update --availability drain manager
Manager
[root@manager ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
3ugwexq8el6e9ouj1iyguxtnq * manager Ready Drain Reachable 19.03.1
6p4qed1dyurk81nuxs2b3s72p worker01 Ready Active Leader 19.03.1
zegtd8sspiw0lsctzc98cc0g4 worker02 Ready Active Reachable 19.03.1
此時manager 只能時管理節(jié)點,不能指派任務(wù)
2 . 添加標(biāo)簽元數(shù)據(jù)
[root@manager ~]# docker node update --label-add GM-IDC-01 worker01
[root@manager ~]# docker node inspect worker01
"CreatedAt": "2019-08-22T07:09:10.403549405Z",
"UpdatedAt": "2019-08-22T08:16:14.952425008Z",
"Spec": {
"Labels": {
"GM-IDC-01": ""
…………………..省略了部分
3 . 節(jié)點的提權(quán)/降權(quán)
例如:將worker01,worker02都升級為管理節(jié)點
[root@manager ~]# docker node promote worker01 worker02
Node 6p4qed1dyurk81nuxs2b3s72p is already a manager.
Node zegtd8sspiw0lsctzc98cc0g4 is already a manager.
例如:將worker01,worker02都降權(quán)為普通節(jié)點
[root@manager ~]# docker node demote worker01 worker02
Manager worker01 demoted in the swarm.
Manager worker02 demoted in the swarm.
4 .退出集群
管理節(jié)點退出
[root@manager ~]# docker swarm leave –force
普通節(jié)點退出
[root@worker01 ~]# docker swarm leave
Docker Swarm 服務(wù)管理
示例:從Docker鏡像httpd 創(chuàng)建一個名稱為web 的服務(wù),指定副本為2.
[root@manager ~]# docker pull httpd ##下載鏡像
注意:httpd 服務(wù)要注釋掉 'ServerName'
[root@manager ~]# docker service create --replicas 2 --name web httpd
overall progress: 2 out of 2 tasks
1/2: running
2/2: running
verify: Service converged
[root@manager ~]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
edfomyazxto9 web replicated 2/2 httpd:latest
顯示服務(wù)的詳細(xì)信息 (省略了部分)
[root@manager ~]# docker service inspect web
[
{
"ID": "edfomyazxto9f7t7kbau2h453",
"Version": {
"Index": 1524
},
"CreatedAt": "2019-08-22T09:38:04.259651137Z",
"UpdatedAt": "2019-08-22T09:38:04.259651137Z",
"Spec": {
"Name": "web",
"Labels": {},
"TaskTemplate": {
"ContainerSpec": {
"Image": "httpd:latest@sha256:98caed3e3a90ed9db8d25dcbb98eebe0ce56358a9dbbc940d7eb66a8e2b88252",
……………………………………………
刪除服務(wù)
[root@manager ~]# docker service rm web
2.重新加入群集,部署nginx 的web
特別注意::每一臺節(jié)點上都要有nginx 的鏡像,才能部署。
9 docker load --input mynginx ##載入鏡像,每一臺上都做
10 docker images
11 docker tag 848ea241199d nginx
12 docker images
13 clear
14 docker service create --replicas 2 --name web nginx ##指定副本為2
15 docker service logs -f web
16 docker service ls
17 docker service ps web
[root@manager ~]# docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
pb3hw77bm022 web.1 nginx:latest manager Running Running 12 minutes ago
9f6u648z18gk web.2 nginx:latest worker01 Running Running 12 minutes ago
18 docker service inspect web
19 docker service inspect --pretty web ##查看信息
……………………………….
ContainerSpec:
Image: nginx:latest
Init: false
Resources:
Endpoint Mode: vip
服務(wù)的擴容/縮容
20 docker service scale web=3 ##服務(wù)擴容
21 docker service ps web
[root@manager ~]# docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
pb3hw77bm022 web.1 nginx:latest manager Running Running 15 minutes ago
9f6u648z18gk web.2 nginx:latest worker01 Running Running 15 minutes ago
an6nc2lyhet5 web.3 nginx:latest worker02 Running Running 10 minutes ago
服務(wù)的縮容
[root@manager ~]# docker service scale web=1
[root@manager ~]# docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
pb3hw77bm022 web.1 nginx:latest manager Running Running 17 minutes ago
添加Overlay網(wǎng)絡(luò)
在Swarm 集群中。添加Overlay網(wǎng)絡(luò)時,可以連接一個或多個服務(wù)。那么處于該網(wǎng)絡(luò)中的所有容器之間都可以進(jìn)行通信?。?br/>1.管理節(jié)點創(chuàng)建
[root@manager ~]# docker network create --driver overlay my-network
0c5k9xirc0pp1a9qqgoksvyf5
2.創(chuàng)建服務(wù),使用my-network 網(wǎng)絡(luò)
[root@manager ~]# docker service create --replicas 3 --network my-network --name myweb nginx
mm3gtfocd8dm63a2d3b4uivjq
overall progress: 3 out of 3 tasks
1/3: running
2/3: running
3/3: running
verify: Service converged
數(shù)據(jù)卷的創(chuàng)建與應(yīng)用
創(chuàng)建數(shù)據(jù)卷
[root@manager _data]# docker volume create product-kgc
product-kgc
查看創(chuàng)建的數(shù)據(jù)卷
[root@manager _data]# docker volume ls
DRIVER VOLUME NAME
local product-kgc
創(chuàng)建本機上的目錄
[root@manager _data]# mkdir -p /usr/share/nginx/html
創(chuàng)建容器
[root@manager _data]# docker service create --mount type=volume,src=product-kgc,dst=/usr/share/nginx/html --replicas 1 --name kgc-web-01 nginx ##鏡像的存在
查看創(chuàng)建的容器
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
bbqd215gwlog kgc-web-01.1 nginx:latest manager Running Running 11 minutes ago
查看數(shù)據(jù)卷的詳細(xì)信息
[root@manager ~]# docker volume inspect product-kgc
[
{
"CreatedAt": "2019-08-25T09:25:30+08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/product-kgc/_data",
"Name": "product-kgc",
"Options": {},
"Scope": "local"
}
]
查看數(shù)據(jù)是否同步
[root@manager ~]# cd /var/lib/docker/volumes/product-kgc/_data/
[root@manager ~]# mkdir test01 test02
[root@manager ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32f426b2a047 nginx:latest "/run.sh" 16 minutes ago Up 16 minutes 80/tcp, 443/tcp kgc-web-01.1.bbqd215gwlog1v4a5j2ck2nvq
進(jìn)入容器,查看 ##在本地目錄下創(chuàng)建的目錄,容器中也存在
[root@manager _data]# docker exec -it 32f426b2a047 bash
[root@32f426b2a047 nginx]# ls /usr/share/nginx/html/
test01 test02
附加::第二種方式創(chuàng)建數(shù)據(jù)卷,可以采用 bind 類型
[root@manager ~]# docker service create --replicas 3 --mount type=bind,src=/var/vhost/www/aa,dst=/usr/share/nginx/html --name kgc-web-02 nginx
d6c5iw9gxo980embkb7aas1ky
overall progress: 3 out of 3 tasks
1/3: running
2/3: running
3/3: running
verify: Service converged
[root@manager ~]# touch /var/vhost/www/aa/abcd
[root@manager ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
807ff87f1b2b nginx:latest "/run.sh" 40 minutes ago Up 40 minutes 80/tcp, 443/tcp kgc-web-02.2.pkwe5ql9oaf7994iv5qt44cke
32f426b2a047 nginx:latest "/run.sh" About an hour ago Up About an hour 80/tcp, 443/tcp kgc-web-01.1.bbqd215gwlog1v4a5j2ck2nvq
4f71487e7989 nginx:latest "/run.sh" About an hour ago Created myweb.2.j771vgcjzw0t3cne3fauz3ydf
d4c2cf0b0953 nginx:latest "/run.sh" About an hour ago Created myweb.1.hayst7oh5ck442xl9g51e54xl
[root@manager ~]# docker exec -it 807ff87f1b2b bash
[root@807ff87f1b2b nginx]# ls /usr/share/nginx/html/
abcd
驗證成功!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。