【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.
### 配置 Docker Swarm 中的 Jenkins 使用 JaCoCo 实现自动化构建和代码覆盖报告 #### 安装并配置 Jenkins 和 JaCoCo 插件 为了使 Jenkins 能够处理 Java 项目的静态分析以及生成 JaCoCo 测试覆盖率报告,在启动 Jenkins 前需确保已安装了必要的插件。这可以通过在容器初始化脚本中指定 `install-plugin` 参数来完成。 ```bash docker run --name jenkins \ --restart always \ -p 8080:8080 \ -p 50000:5000 \ -v /var/jenkins_home:/var/jenkins_home \ -d jenkins/jenkins:2.387.1-lts \ java -jar /usr/share/jenkins/ref/plugins-manager-cli.jar install jacoco coverage-reporter-api[^3] ``` 上述命令不仅会拉取特定版本的 Jenkins 映像,还会自动安装 JaCoCo 及其依赖项之一——Coverage Reporter API 插件。 #### 创建多阶段管道定义文件 (Jenkinsfile) 对于 Spring Cloud 应用程序而言,推荐采用声明式的 Pipeline-as-code 方法编写 Jenkinsfile 来描述 CI/CD 工作流。下面是一个简单的例子: ```groovy pipeline { agent { label 'swarm-node' } stages { stage('Checkout') { steps { git branch: 'main', url: 'https://github.com/example/spring-cloud-app.git' } } stage('Build & Test with Maven') { environment { MAVEN_HOME = tool name: 'Maven_3.6.3', type: 'hudson.tasks.Maven$MavenInstallation' } steps { sh "${MAVEN_HOME}/bin/mvn clean verify" } post { always { junit '**/target/surefire-reports/*.xml' archiveArtifacts artifacts: '**/target/**/*.war,**/build/libs/*.jar', allowEmptyArchive: true } } } stage('Generate Code Coverage Report') { steps { step([$class: 'JacocoPublisher']) } } // 更多部署到 Docker Swarm 的逻辑... } } ``` 此 Groovy 脚本定义了一个完整的持续交付流程,其中包括检出源码仓库、编译打包应用程序、运行单元测试并将结果上传给 Jenkins,最后通过调用内置步骤生成 JaCoCo 报告。 #### 设置 Docker Swarm Service for Jenkins Master and Agents 为了让 Jenkins master 和 slave nodes 形成一个高可用的服务网格,可以按照如下方式设置服务: ```yaml version: "3" services: jenkins-master: image: jenkins/jenkins:2.387.1-lts ports: - "8080:8080" - "50000:50000" volumes: - ./jenkins-data:/var/jenkins_home deploy: replicas: 1 restart_policy: condition: on-failure jnlp-slave: image: jenkins/inbound-agent:latest depends_on: - jenkins-master command: ['jnlp'] deploy: mode: global labels: com.example.role: build-worker ``` 这段 YAML 文件用于创建两个独立但相互关联的服务实例:一个是作为主节点负责调度任务;另一个则是工作节点执行实际的任务操作。注意这里设置了全局模式下的 JNLP Slave 数量不受限于副本数目的约束[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值