• Docker三剑客之docker-swarm


    Docker Swarm

    介绍

    swarm集群存在manager节点和worker节点

    初始化

    # docker swarm init
    $ docker swarm  --help
    Usage:  docker swarm COMMAND
    Manage Swarm
    Commands:
      ca          Display and rotate the root CA
      init        Initialize a swarm
      join        Join a swarm as a node and/or manager
      join-token  Manage join tokens
      leave       Leave the swarm
      unlock      Unlock swarm
      unlock-key  Manage the unlock key
      update      Update the swarm
     
    $ docker swarm init --help
    Usage:  docker swarm init [OPTIONS]
    Initialize a swarm
    Options:
          --advertise-addr string                  Advertised address (format: <ip|interface>[:port])
          ................
          
    $ docker swarm init --advertise-addr 192.168.11.130(自己服务器ip,也可不加参数)
    Swarm initialized: current node (dothxr6f0ymzn3r5dg9lmzojq) is now a manager.
    
    To add a worker to this swarm, run the following command:
    
        docker swarm join --token SWMTKN-1-24vl1ouqra0lgpvwfj2ykxkcnu3gopz25qdk4vl00hoazlak4k-ae6one7gfny40o6mqt377k1kg 192.168.11.130:2377
    
    To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
    
    #副机想要加入该节点,两种方法
      1、将上面的令牌复制到副机上执行
      2、主机上执行docker swarm join-token worker 命令,会生成副机的令牌,复制到副机上执行
         docker swarm join-token manager #生成主机的令牌
         docker swarm join-token worker  #生成副机的令牌
     #在副机上执行,副机节点就已经加入主机
    $ docker swarm join --token SWMTKN-1-24vl1ouqra0lgpvwfj2ykxkcnu3gopz25qdk4vl00hoazlak4k-ae6one7gfny40o6mqt377k1kg 192.168.11.130:2377
    This node joined a swarm as a worker.
    
    #主机使用docker node ls命令查看
    $ docker node ls
    ID                            HOSTNAME                STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    dothxr6f0ymzn3r5dg9lmzojq *   localhost.localdomain   Ready               Active              Leader              19.03.12
    qf9fjw89grd9n1gpr5rey39ra     localhost.localdomain   Ready               Active                                  19.03.12
    
    • 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

    扩展:如果想要删除节点,可以使用命令 docker swarm leave 命令 主机上执行,需要加入参数 --force

    RFAT协议

    总结,至少要存在三个主节点,如果是双主,如果其中一台主机挂了,另外一台主机是不能够使用的。所以必须保证存在三个主节点,且必须保证1台主节点以上存活。

    动态扩缩容

    #两种方式
    1、docker service scale SERVICE=num
    2、docker service update --replicas num  SERVICE
    
    • 1
    • 2
    • 3

    集群网络

    初始化群集或将Docker主机加入现有群集时,将在该Docker主机上创建两个新网络:

    • 一个称为的覆盖网络ingress,用于处理与群体服务有关的控制和数据流量。创建群集服务并且不将其连接到用户定义的覆盖网络时,ingress 默认情况下它将连接到网络。
    • 一个名为的网桥网络docker_gwbridge,它将各个Docker守护程序连接到集群中的其他守护程序。

    overlay:保证各个集群之间的通信(相当于之前的自定义网络保证容器之间的通信)

    ingress:特殊的overlay,具有负载均衡的功能

    $ docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    4d17786474f7        bridge              bridge              local
    b7a75c830776        docker_gwbridge     bridge              local
    30eaddd942a9        host                host                local
    zqij3ylcinhg        ingress             overlay             swarm
    383f7401900a        none                null                local
    $ docker network inspect ingress
    [
          ................
            "Peers": [
                {
                    "Name": "5506fdcbd9ee",
                    "IP": "192.168.11.130"
                },
                {
                    "Name": "557944014f92",
                    "IP": "192.168.11.131"
                }
            ]
        }
    ]
    cbd9ee",
                    "IP": "192.168.11.130"
                },
                {
                    "Name": "557944014f92",
                    "IP": "192.168.11.131"
                }
            ]
        }
    ]
    
    • 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
  • 相关阅读:
    性价比较高的无线蓝牙耳机,300以内高音质蓝牙耳机推荐
    EBS JVM 内存优化攻略
    联邦学习中的差分隐私与同态加密
    js 迭代器iterator 和 生成器Generator 10
    Python 教程之如何使用 Streamlit 在 Python 中编写 SaaS(软件即服务)Web 应用程序
    经纬高坐标转东北天坐标
    25. Python 字符串的切片方法
    WebStorm 运行 nodejs 脚本 路径不对
    2023年7月工作经历三
    游戏电竞蓝牙耳机推荐
  • 原文地址:https://blog.csdn.net/m0_37642477/article/details/125530491