【dcoker】swarm+volume 管理数据

1.创建卷

[root@es1 ~]# docker volume ls
DRIVER    VOLUME NAME
local     57e8c3f618dc65491e03d49c2891d6d3c2f9d5d2c19ec4b8a8e5ea2e0b4d8b6c
local     sspu_mysqlconfig
local     volume-nfs-tomcat

docker volume create nginxdata
[root@es1 ~]# docker volume create nginxdata
nginxdata
[root@es1 ~]# docker volume ls
DRIVER    VOLUME NAME
local     57e8c3f618dc65491e03d49c2891d6d3c2f9d5d2c19ec4b8a8e5ea2e0b4d8b6c
local     nginxdata
local     sspu_mysqlconfig
local     volume-nfs-tomcat

2.创建服务 

--192.168.1.7:
docker service create --replicas 3 --mount type=volume,src=nginxdata,dst=/usr/share/nginx/html \
-p 8011:80 --name mynginx2

[root@es1 ~]# docker service create --replicas 3 --mount type=volume,src=nginxdata,dst=/usr/share/nginx/html \
> -p 8011:80 --name mynginx2 192.168.1.11:443/myharbor/nginx:latest
qarid9y7hru13p0jw6y9sziyq
overall progress: 3 out of 3 tasks 
1/3: running   
2/3: running   
3/3: running   
verify: Service converged 

[root@es1 ~]# netstat -an |grep 8011
tcp6       0      0 :::8011                 :::*                    LISTEN 

--主机端口:8011,容器端口:80;创建3个容器实例。
[root@es1 ~]# docker service ls
ID             NAME       MODE         REPLICAS   IMAGE                                    PORTS
32d752myr4og   mynginx1   replicated   2/2        192.168.1.11:443/myharbor/nginx:latest   *:8010->80/tcp
qarid9y7hru1   mynginx2   replicated   3/3        192.168.1.11:443/myharbor/nginx:latest   *:8011->80/tcp

[root@es1 ~]# docker service ps mynginx2
ID             NAME         IMAGE                                    NODE      DESIRED STATE   CURRENT STATE                ERROR     PORTS
rh0tounjciej   mynginx2.1   192.168.1.11:443/myharbor/nginx:latest   es2       Running         Running about a minute ago             
f46p1ricylxb   mynginx2.2   192.168.1.11:443/myharbor/nginx:latest   es3       Running         Running about a minute ago             
qiqbyvd9yhel   mynginx2.3   192.168.1.11:443/myharbor/nginx:latest   es1       Running         Running about a minute ago  

3.查看数据卷 

[root@es1 ~]# docker volume inspect nginxdata
[
    {
        "CreatedAt": "2024-07-04T19:46:00+08:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/data/docker/data/volumes/nginxdata/_data",
        "Name": "nginxdata",
        "Options": {},
        "Scope": "local"
    }
]

--查看
[root@es1 ~]# docker service inspect mynginx2
[
    {
        "ID": "qarid9y7hru13p0jw6y9sziyq",
        "Version": {
            "Index": 231
        },
        "CreatedAt": "2024-07-04T11:46:00.390324105Z",
        "UpdatedAt": "2024-07-04T11:46:00.395043961Z",
        "Spec": {
            "Name": "mynginx2",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "192.168.1.11:443/myharbor/nginx:latest@sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3",
                    "Init": false,
                    "Mounts": [
                        {
                            "Type": "volume",
                            "Source": "nginxdata",
                            "Target": "/usr/share/nginx/html"
                        }
                    ],
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {},
                    "Isolation": "default"
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        }
                    ]
                },
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 3
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 80,
                        "PublishedPort": 8011,
                        "PublishMode": "ingress"
                    }
                ]
            }
        },
        "Endpoint": {
            "Spec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 80,
                        "PublishedPort": 8011,
                        "PublishMode": "ingress"
                    }
                ]
            },
            "Ports": [
                {
                    "Protocol": "tcp",
                    "TargetPort": 80,
                    "PublishedPort": 8011,
                    "PublishMode": "ingress"
                }
            ],
            "VirtualIPs": [
                {
                    "NetworkID": "ok60ir4yv3bsmbl8rvfn17qfy",
                    "Addr": "10.0.0.5/24"
                }
            ]
        }
    }
]

[root@es3 nginxdata]# ll  /data/docker/data/volumes/nginxdata/_data/
total 8
-rw-r--r-- 1 root root 497 Dec 28  2021 50x.html
-rw-r--r-- 1 root root 615 Dec 28  2021 index.html
[root@es2 volumes]# ll  /data/docker/data/volumes/nginxdata/_data/
total 8
-rw-r--r-- 1 root root 497 Dec 28  2021 50x.html
-rw-r--r-- 1 root root 615 Dec 28  2021 index.html
[root@es1 data]# ll  /data/docker/data/volumes/nginxdata/_data/
total 8
-rw-r--r-- 1 root root 497 Dec 28  2021 50x.html
-rw-r--r-- 1 root root 615 Dec 28  2021 index.html
--三个节点均有卷。

4.写入html 

7:
echo "nginxdata1" > /data/docker/data/volumes/nginxdata/_data/nginx.html
9:
echo "nginxdata2" > /data/docker/data/volumes/nginxdata/_data/nginx.html
10:
echo "nginxdata3" > /data/docker/data/volumes/nginxdata/_data/nginx.html

5.验证:



[root@es1 _data]# curl  http://192.168.1.7:8011/nginx.html 
nginxdata2
[root@es1 _data]# curl  http://192.168.1.7:8011/nginx.html 
nginxdata3
[root@es1 _data]# curl  http://192.168.1.7:8011/nginx.html 
nginxdata1
[root@es1 _data]# curl  http://192.168.1.7:8011/nginx.html 
nginxdata2
[root@es1 _data]# curl  http://192.168.1.7:8011/nginx.html 
nginxdata3
[root@es1 _data]# curl  http://192.168.1.7:8011/nginx.html 
nginxdata1

--由此可见,任意访问:7/9/10节点已经自动负载均衡。
[root@es1 _data]# curl  http://192.168.1.9:8011/nginx.html 
nginxdata1
[root@es1 _data]# curl  http://192.168.1.9:8011/nginx.html 
nginxdata3
[root@es1 _data]# curl  http://192.168.1.9:8011/nginx.html 
nginxdata2
[root@es1 _data]# curl  http://192.168.1.9:8011/nginx.html 
nginxdata1
[root@es1 _data]# curl  http://192.168.1.9:8011/nginx.html 
nginxdata3
[root@es1 _data]# curl  http://192.168.1.9:8011/nginx.html 
nginxdata2

Swarm Intelligence Volume 3: Applications by Ying Tan English | 2018 | ISBN: 1785616310 | 880 Pages | PDF | 116 MB Swarm Intelligence (SI) is one of the most important and challenging paradigms under the umbrella of computational intelligence. It focuses on the research of collective behaviours of a swarm in nature and/or social phenomenon to solve complicated and difficult problems which cannot be handled by traditional approaches. Thousands of papers are published each year presenting new algorithms, new improvements and numerous real world applications. This makes it hard for researchers and students to share their ideas with other colleagues; follow up the works from other researchers with common interests; and to follow new developments and innovative approaches. This complete and timely collection fills this gap by presenting the latest research systematically and thoroughly to provide readers with a full view of the field of swarm. Students will learn the principles and theories of typical swarm intelligence algorithms; scholars will be inspired with promising research directions; and practitioners will find suitable methods for their applications of interest along with useful instructions. Volume 3 includes 27 chapters presenting real-world applications of swarm intelligence algorithms and related evolutionary algorithms. With contributions from an international selection of leading researchers, Swarm Intelligence is essential reading for engineers, researchers, professionals and practitioners with interests in swarm intelligence.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值