Docker进阶Swarm、Stack、Secret、Config

x33g5p2x  于2022-02-14 转载在 Docker  
字(3.4k)|赞(0)|评价(0)|浏览(286)

1 Swarm介绍

安装docker
https://blog.csdn.net/zx77588023/article/details/122652560

1.1 Warm文档

https://docs.docker.com/config/daemon/prometheus/

Run your app in production -> Configure containers -> Scale your app

1.2 工作模式


Raft:一致性算法

1.3 购买服务器

集群
2主2从

2 搭建集群

[root@VM-0-14-centos ~]# 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

Run 'docker swarm COMMAND --help' for more information on a command.
[root@VM-0-14-centos ~]# docker swarm init --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)
# 初始化主节点
docker swarm init
# 加入一个节点(管理者、worker)
docker swarm join

# 获取令牌
docker swarm join-token manager	# 生成加入 manager节点 命令
docker swarm join-token worker	# 生成加入 worker 节点 命令

将dokcer1设置为主节点

docker swarm init --advertise-addr 172.27.0.6

docker2加入1节点

docker swarm join --token SWMTKN-1-6b1kbshfye331k4d86az2ohqvdwlj1bijsbka6hvb8h5ha4n28-e61bl5kpo7c1jbaj4hj8nizv1 172.27.0.6:2377

主节点查看所有节点

docker node ls

3 Raft协议

双主双从:假设一个节点挂了!其他节点是否可以用: 不可用
Raft协议:保证大多数接待存货才可以用、只要>1,集群至少大于3台

关闭docker:测试挂机

systemctl stop docker

退出集群

docker swarm leave

故:至少3个主节点 多于1台机器存货

4 弹性、扩缩容、集群

docker-compose up:启动一个项目。单机

集群:swarm docker service

容器 => 服务 => 副本

帮助

[root@VM-0-6-centos ~]# docker service --help

Usage:  docker service COMMAND

Manage services

Commands:
  create      创建一个 new service
  inspect     查看services细节
  logs        查看service日志
  ls          List services
  ps          List the tasks of one or more services
  rm          Remove one or more services
  rollback    Revert changes to a service's configuration
  scale       动态扩缩容 Scale one or multiple replicated services
  update      更行service

Run 'docker service COMMAND --help' for more information on a command.

启动服务

docker service create -p 8888:80 --name my-nginx nginx
docker run 容器启动!不具有扩缩容
docker service 服务!具有扩缩容,滚动更新

查看服务

# REPLICAS:副本数目
docker service ps ls
docker service ps my-nginx

# 查看服务 元数据
docker service inspect my0nginx

更新副本数量

docker service update --replicas 5 my-nginx
或
docker service scale my-nginx=5

调整service 以什么方式运行

dcoker service create --mode replicated --name mytom tomcat:7 

docker service create --mode global --name haha alpine ping baidu.com

Docker Stack

# 单机
docker-compose up -d wordpress.yaml

# 集群
docker-stack deploy wordpress.yaml

Docker Secret

学习地址:
https://www.bilibili.com/video/BV1kv411q7Qc

相关文章

最新文章

更多