In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Manage Docker Swarm clusters
1. Node state change management
[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
At this time, manager can only manage nodes and cannot assign tasks.
2. Add tag metadata
[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":
... .. Omitted part
3. The lifting / lowering right of the node
For example: upgrade worker01,worker02 to management node
[root@manager ~] # docker node promote worker01 worker02
Node 6p4qed1dyurk81nuxs2b3s72p is already a manager.
Node zegtd8sspiw0lsctzc98cc0g4 is already a manager.
For example: reduce the weight of worker01,worker02 to a normal node
[root@manager ~] # docker node demote worker01 worker02
Manager worker01 demoted in the swarm.
Manager worker02 demoted in the swarm.
4. Exit the cluster
Management node exit
[root@manager ~] # docker swarm leave-force
Normal node exit
[root@worker01 ~] # docker swarm leave
Docker Swarm service management
Example: create a service named web from the Docker mirror httpd, with a specified copy of 2. 0.
[root@manager ~] # docker pull httpd # # download image
Note: the httpd service should comment out '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
Show details of the service (omitted)
[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"
...
Delete a service
[root@manager ~] # docker service rm web
two。 Rejoin the cluster and deploy web for nginx
Special note: each node must have an image of nginx before it can be deployed.
9 docker load-- input mynginx # # load the image and do it on each station
10 docker images
11 docker tag 848ea241199d nginx
12 docker images
13 clear
14 docker service create-- replicas 2-- name web nginx # # specify a copy of 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 # # View information
... .
ContainerSpec:
Image: nginx:latest
Init: false
Resources:
Endpoint Mode: vip
Expansion / reduction of services
20 docker service scale web=3 # # Service expansion
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
Reduction of service capacity
[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
Add Overlay Network
In the Swarm cluster. When you add an Overlay network, you can connect one or more services. Then all containers in the network can communicate with each other!
1. Manage Node creation
[root@manager] # docker network create-- driver overlay my-network
0c5k9xirc0pp1a9qqgoksvyf5
two。 Create a service using the my-network network
[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
Creation and Application of data Volume
Create a data volume
[root@manager _ data] # docker volume create product-kgc
Product-kgc
View the created data volume
[root@manager _ data] # docker volume ls
DRIVER VOLUME NAME
Local product-kgc
Create a directory on this machine
[root@manager _ data] # mkdir-p / usr/share/nginx/html
Create a container
[root@manager _ data] # docker service create-- mount type=volume,src=product-kgc,dst=/usr/share/nginx/html-- replicas 1-- name kgc-web-01 nginx # # Image
View the created container
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
Bbqd215gwlog kgc-web-01.1 nginx:latest manager Running Running 11 minutes ago
View the details of the data volume
[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"
}
]
Check whether the data is synchronized
[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
Enter the container and view # # the directory created under the local directory, which also exists in the container
[root@manager _ data] # docker exec-it 32f426b2a047 bash
[root@32f426b2a047 nginx] # ls / usr/share/nginx/html/
Test01 test02
Additional:: the second way to create a data volume, you can use the bind type
[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
Verified successfully!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.