• 关于部署docker swarm一些知识


    解决并发现的问题

    1、docker container can ping but not curl or wget

    2、container之间不能通信

    准备机器

    IP节点主机名称
    192.168.0.10mastern1
    192.168.0.11workern2
    192.168.0.12workern3

    安装docker

    yum install -y yum-utils device-mapper-persistent-data lvm2 vim lsof telnet
    
    yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
    yum makecache fast
    
    yum -y install docker-ce
    
    service  docker start
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    docker 配置

    1、 修改配置 vim /etc/docker/daemon.json [10.0.0.4:8089自己安装的镜像私服]

    {
        "registry-mirrors": [
            "https://pmyvcr6n.mirror.aliyuncs.com",
            "https://docker.mirrors.ustc.edu.cn",
            "https://hub-mirror.c.163.com"
        ],
        "max-concurrent-downloads": 10,
        "max-concurrent-uploads": 10,
        "log-driver": "json-file",
        "log-level": "warn",
        "log-opts": {
        "max-size": "10m",
        "max-file": "3"
        },
        "data-root": "/var/lib/docker",
        "insecure-registries": ["10.0.0.4:8089"]
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    2、修改配置 vim /lib/systemd/system/docker.service

    找到 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 并注释并修改

    修改示例: ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --mtu=1450

    备注:1450 一般是指eth0下的网卡,根据自己的需求定制,集群环境下一定要配置,否则 docker container can ping but not curl or wget

    3、 stop docker

        service docker stop
    
    • 1

    4、删除虚拟网卡docker_gwbridge

        ifconfig docker_gwbridge down
    
    • 1

    6、start docker

        service docker start
    
    • 1

    7、删除并重置docker_gwbridge

    #查看原有的网卡 一定要执行并记录 Subnet 和Gateway参数
    docker network inspect docker_gwbridge
    [
        {
            "Name": "docker_gwbridge",
            "Id": "41827fa89d9f763a1b482fafa47d89108adb4dd0d4b07d7954b2cb5bf54fcd39",
            "Created": "2022-07-17T18:19:32.378353487+08:00",
            "Scope": "local",
            "Driver": "bridge",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": null,
                "Config": [
                    {
                        "Subnet": "172.18.0.0/16",
                        "Gateway": "172.18.0.1"
                    }
                ]
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {},
            "Options": {
                "com.docker.network.bridge.enable_icc": "false",
                "com.docker.network.bridge.enable_ip_masquerade": "true",
                "com.docker.network.bridge.name": "docker_gwbridge"
            },
            "Labels": {}
        }
    ]
    # 查看MTU [ifconfig 一般是eth0 的mtu值]
    ifconfig
    # 删除
    docker network rm docker_gwbridge
    #重置网卡 ,注意 记得设置之前得到的Subnet [network inspect docker_gwbridge 获取]参数和正确的MTU值
    docker network create
    --subnet 172.18.0.0/16
    --opt com.docker.network.bridge.name=docker_gwbridge
    --opt com.docker.network.bridge.enable_icc=false
    --opt com.docker.network.bridge.enable_ip_masquerade=true
    --opt com.docker.network.driver.mtu=1450
    docker_gwbridge
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    8、以上步骤必须在每一台机器上执行

    todo 以上步骤必须在每一台机器上执行,如未执行,一下步骤不能操作

    9、 出计划集群 docker swarm init join 每一台机器

        docker swarm init
    
    • 1

    10、 重置 ingress network

    #查看原有的网卡 一定要执行并记录 Subnet 和Gateway参数
    docker network inspect ingress
    
    # 删除
    docker network rm ingress
    #重新创建,根据自己的实际参数创建
     docker network create --driver overlay  --ingress --subnet=10.255.0.0/16 --gateway=10.255.0.1 --opt com.docker.network.driver.mtu=1450  ingress
     
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    11、 测试

    #启动一个swarm service,
    docker service create -td --name busybox busybox
    
    # 观察MTU 已经和eth0一样了
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    12 创建自定义网络

    docker network create  -d overlay  --opt com.docker.network.driver.mtu=1450   --attachable custom-overlay
    
    
    • 1
    • 2

    13 docker 登录私服镜像

    #域名或IP 每一台都要登录
    docker login xxx.xxx.xxx.xxx
    
    
    • 1
    • 2
    • 3

    14 参考资料 docker 官网

    Docker MTU issues and solutions
    Use overlay networks
    docker network create

    关于部署方面

    集群启动私服问题 要带上 --with-registry-auth 否则无法找到镜像,以下举例是stack-compose 启动
    docker stack deploy --with-registry-auth -c docker-compose.yml xxx

  • 相关阅读:
    Python中的一些有趣的内置函数
    Android—AMS启动
    【算法】树状数组数据结构
    8.10模拟赛总结
    部署Vue项目到githubPage中
    「软件推荐」Mac 平台生产力小工具推荐
    MySQL 日志管理、备份与恢复
    数据结构— —哈希表顺序实现
    【机器学习基础】——另一个视角解释SVM
    day-44 代码随想录算法训练营(19) 动态规划 part 06
  • 原文地址:https://blog.csdn.net/helenyqa/article/details/125887761