首页 > 其他分享 >Docker swarm

Docker swarm

时间:2023-09-23 12:37:51浏览次数:58  
标签:default lft -- swarm ff Docker docker

Docker swarm

[Docker Swarm 介绍和工作原理]https://blog.csdn.net/qq1010267837/article/details/125003810

1. 初始化一个节点 docker swarm init​(docker-1)

[root@localhost ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
6090f5e5a6ee   bridge    bridge    local
ea337009fb83   host      host      local
e4d1ce606183   none      null      local
[root@localhost ~]# docker swarm -h
Flag shorthand -h has been deprecated, please use --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

Run 'docker swarm COMMAND --help' for more information on a command.
[root@localhost ~]# docker swarm init -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker swarm init [OPTIONS]

Initialize a swarm

Options:
      --advertise-addr string                  Advertised address (format: # 发布地址
                                               <ip|interface>[:port])
      --autolock                               Enable manager autolocking (requiring an
                                               unlock key to start a stopped manager)
      --availability string                    Availability of the node
                                               ("active"|"pause"|"drain") (default "active")
      --cert-expiry duration                   Validity period for node certificates
                                               (ns|us|ms|s|m|h) (default 2160h0m0s)
      --data-path-addr string                  Address or interface to use for data
                                               path traffic (format: <ip|interface>)
      --data-path-port uint32                  Port number to use for data path traffic
                                               (1024 - 49151). If no value is set or is
                                               set to 0, the default port (4789) is used.
      --default-addr-pool ipNetSlice           default address pool in CIDR format
                                               (default [])
      --default-addr-pool-mask-length uint32   default address pool subnet mask length
                                               (default 24)
      --dispatcher-heartbeat duration          Dispatcher heartbeat period
                                               (ns|us|ms|s|m|h) (default 5s)
      --external-ca external-ca                Specifications of one or more
                                               certificate signing endpoints
      --force-new-cluster                      Force create a new cluster from current state
      --listen-addr node-addr                  Listen address (format:
                                               <ip|interface>[:port]) (default 0.0.0.0:2377)
      --max-snapshots uint                     Number of additional Raft snapshots to retain
      --snapshot-interval uint                 Number of log entries between Raft
                                               snapshots (default 10000)
      --task-history-limit int                 Task history retention limit (default 5)
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:20:74:87 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.102/24 brd 192.168.1.255 scope global noprefixroute dynamic ens33
       valid_lft 6123sec preferred_lft 6123sec
    inet6 fe80::686a:cd80:2b45:7881/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:a7:c7:42:08 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:a7ff:fec7:4208/64 scope link 
       valid_lft forever preferred_lft forever
5: veth5ea21b5@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default 
    link/ether c6:73:7a:3c:f6:6d brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::c473:7aff:fe3c:f66d/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# docker swarm init --advertise-addr 192.168.1.102
Swarm initialized: current node (lxry278x1aixiyahh6lu6zfxx) is now a manager.

To add a worker to this swarm, run the following command:
    # 使用以下指令在其他节点中执行,加入到当前集群中
    docker swarm join --token SWMTKN-1-3tubipd5uic1iklj44smzgc3zaqtizrp7p1llvac4p1yxzf67b-afuzei64x988refyd7gmcxdh9 192.168.1.102:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

[root@localhost ~]# 

2. 生成 docker 加入集群命令 docker swarm join-token worker​(docker-1)

[root@localhost ~]# docker swarm join-token worker # 生成 docker 加入集群命令
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-3tubipd5uic1iklj44smzgc3zaqtizrp7p1llvac4p1yxzf67b-afuzei64x988refyd7gmcxdh9 192.168.1.102:2377

[root@localhost ~]# 

3. 生成一个设置主节点命令docker swarm join-token manager​(docker-1)

[root@localhost ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-3tubipd5uic1iklj44smzgc3zaqtizrp7p1llvac4p1yxzf67b-9k0nke0pk02o3ing6nbzingh4 192.168.1.102:2377

[root@localhost ~]# 

4. 加入一个节点 docker swarm join​(docker-2)

image

image

image

标签:default,lft,--,swarm,ff,Docker,docker
From: https://www.cnblogs.com/liuzonglin/p/17724176.html

相关文章

  • Docker 部署 redis 网络集群
    Docker部署redis网络集群##1.创建网卡dockernetworkcreateredis--subnet172.38.0.0/16#2.通过脚本创建六个redis配置forportin$(seq16);\do\mkdir-p/mydata/redis/node-${port}/conftouch/mydata/redis/node-${port}/conf/redis.confcat<<EOF>......
  • Dockerfile
    Dockerfile基础知识:每个保留关键字(指令)都是必须大写字母(约定俗成)执行从上到下顺序执行"#"表示注释每个指令都会创建提交一个新的镜像层,并提交!Dockerfile中引用的所有文件一定要和Dockerfile文件在同一级父目录下,可以为Dockerfile父目录的子目录Dockerfile中相对路径......
  • Docker 容器数据卷
    Docker容器数据卷1.方式一:直接使用命令来挂载-v#dockerrun-it-v主机目录:容器目录[root@home]#dockerrun-it-v/home/ceshi:/homecentos/bin/bash总结:容器运行时,挂载目录数据一直同步#获取镜像[root@home]#dockerpullmysql:5.7#运行容器,需要做数据......
  • Ubuntu 22.04 安装 Docker
    安装基础工具sudoapt-getinstallca-certificatescurlgnupglsb-release安装官方的GPGkeysudomkdir-p/etc/apt/keyringscurl-fsSLhttps://download.docker.com/linux/ubuntu/gpg|sudogpg--dearmor-o/etc/apt/keyrings/docker.gpg将Docker的库添加到apt资源......
  • Ubuntu(Ubuntu 22.04 操作系统) 安装 Docker
    Ubuntu(Ubuntu22.04操作系统)安装Docker首先安装一些工具:sudoapt-getinstallca-certificatescurlgnupglsb-release不过在Ubuntu22.04已经默认安装好了。接着安装官方的GPGkey:sudomkdir-p/etc/apt/keyringscurl-fsSLhttps://download.docker.com/linux/ubun......
  • docker跨平台构建镜像
    我们在开发环境构建的镜像在生产环境大多不可用,我们在开发中一般使用Windows或者MAC系统,部署多半是linux环境。那么这篇文章能帮到你。首先首先你需要有一个Dockerfile文件。举例:这里以一个python项目举例FROMpython:3.10-slimWORKDIR/appCOPYrequirements.tx......
  • Docker概念及操作
    1.镜像相关命令:查看本地镜像:dockerimages搜索镜像仓库:dockersearch<名称关键字>下载镜像:dockerpull<镜像名:tag版本>上传镜像:dockerpush <镜像名:tag版本>删除镜像:dockerrmi <镜像名:tag版本>打包本地镜像文件:dockersave-o<输出文件路径>导入本地......
  • Docker Swarm 与高可用性
    什么是DockerSwarm?DockerSwarm是Docker官方提供的容器编排工具,它可以将多个Docker节点组成一个集群,实现容器的自动化部署和管理。DockerSwarm采用了Raft算法来保证集群的一致性,同时支持多种调度策略,如随机调度、最少使用调度、节点标签调度等。DockerSwarm的高可用......
  • Docker缓存占有太大的磁盘空间
    Docker在不重建容器的情况下,日志文件默认会一直追加,时间一长会逐渐占满服务器的硬盘的空间,内存消耗也会一直增加。查出占用磁盘较大的文件Docker的日志文件存在/var/lib/docker/containers目录中,通过下面的命令可以将日志文件夹根据升序的方式罗列出来。sudodu-d1-h/var......
  • docker-compose简介
    1.docker-compose简介  实现docker容器集群的快速编排。管理分成三层:工程(project)、服务(service)、容器(container)  没有解决负载均衡的问题,因此需要借助其它工具实现服务发现及负载均衡,比如Consul  工程配置文件默认文件docker-compose.yml,也可自定义(通过环境变量COMP......