测试开发技术网站
博客
设计
设计
开发
Python
测试
unittest
运维
Linux基础应用
CI/CD
CI/CD
数据库
数据库
云计算
云计算
云原生
云原生
爬虫
爬虫
数据分析
数据分析
人工智能
人工智能
登录
注册
Docker----DockerSwarm集群环境搭建
收藏本文
作者:redrose2100 类别: 日期:2022-05-03 14:29:09 阅读:834 次 消耗积分:0 分
![](https://redrose2100.oss-cn-hangzhou.aliyuncs.com/img/06c9f19c-9517-11ee-b9ec-0242ac110004.png) [TOC] ### (1)创建四个虚拟机(1核2G即可) 这里四个虚拟机ip分别为: * 192.168.145.128 * 192.168.145.129 * 192.168.145.130 * 192.168.145.131 ### (2)每个虚拟机安装docker 参照 [Docker----CentOS7系统上Docker的安装与卸载](http://blog.redrose2100.com/article/59) 为四个虚拟机安装docker ### (3)查看docker swarm 帮助文档 ```bash [root@localhost ~]# 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@localhost ~]# ``` ### (4)查看docker swarm init 的帮助文档 ```bash [root@localhost ~]# docker swarm init --help Usage: docker swarm init [OPTIONS] Initialize a swarm Options: --advertise-addr string Advertised address (format:
[: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:
) --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:
[: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 ~]# ``` ### (5)在192.168.145.128上创建一个swarm集群 ```bash [root@localhost ~]# docker swarm init --advertise-addr 192.168.145.128 Swarm initialized: current node (wsqaq4isrzhlgphnnaqxucy6r) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-50iq7p13l75w9oken3xqgqpnr 192.168.145.128:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. [root@localhost ~]# ``` ### (6)查看当前集群中的节点信息 如下,表示当前集群中只有一个leader主节点 ```bash [root@localhost ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Leader 20.10.10 [root@localhost ~]# ``` ### (7)在192.168.145.128 上查看增加manager节点的方法 ```bash [root@localhost ~]# docker swarm join-token manager To add a manager to this swarm, run the following command: docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-5n9bpvj1v64wb9cvg7l2fitaj 192.168.145.128:2377 [root@localhost ~]# ``` ### (8)增加节点 将上述(7)中查询到的增加manager节点的命令复制一下,然后分别在192.168.145.129和192.168.145.130节点上执行 注意:需要在每个虚拟机上关闭防火墙 ```bash systemctl stop firewalld ``` 如下,在192.168.145.129节点上: ```bash [root@localhost ~]# docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-5n9bpvj1v64wb9cvg7l2fitaj 192.168.145.128:2377 This node joined a swarm as a manager. [root@localhost ~]# ``` 如下,在192.168.145.130节点上: ```bash [root@localhost ~]# docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-5n9bpvj1v64wb9cvg7l2fitaj 192.168.145.128:2377 This node joined a swarm as a manager. [root@localhost ~]# ``` ### (9)此时,查看集群中节点信息 如下已经有三个manager节点了 ```bash [root@localhost ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION fhpe4p0m4gb47pxh48kf9psp8 localhost.localdomain Ready Active Reachable 20.10.10 p1cfiyfyxgkhupjj03tvq40ph localhost.localdomain Ready Active Reachable 20.10.10 wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Leader 20.10.10 [root@localhost ~]# ``` ### (10)在manager节点查看加入worker节点的命令 如,在192.168.145.128上查看 ```bash [root@localhost ~]# docker swarm join-token worker To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-50iq7p13l75w9oken3xqgqpnr 192.168.145.128:2377 [root@localhost ~]# ``` ### (11)增加worker节点 将上述(10)中查询到的命令复制拷贝到192.168.145.131上执行,增加worker节点 如下:在192.168.145.131上 ```bash [root@localhost ~]# docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-50iq7p13l75w9oken3xqgqpnr 192.168.145.128:2377 This node joined a swarm as a worker. [root@localhost ~]# ``` ### (12)查看集群节点信息 再次在192.168.145.128上查看当前集群节点信息,在任意manager节点上均可查看, ```bash [root@localhost ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION fhpe4p0m4gb47pxh48kf9psp8 localhost.localdomain Ready Active Reachable 20.10.10 p1cfiyfyxgkhupjj03tvq40ph localhost.localdomain Ready Active Leader 20.10.10 wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Reachable 20.10.10 xlgi99te9cchyz9n3ydkycf6k localhost.localdomain Ready Active 20.10.10 ``` 此时集群环境已经搭建OK了 ### (13)验证一下集群环境的高可用 将192.168.145.129环境上的docker服务停掉,模拟节点挂了 ```bash [root@localhost ~]# systemctl stop docker Warning: Stopping docker.service, but it can still be activated by: docker.socket [root@localhost ~]# ``` ### (14)查看节点状态 再次回到192.168.145.128节点上查看节点状态,如下。集群整体状态仍然OK ```bash [root@localhost ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION fhpe4p0m4gb47pxh48kf9psp8 localhost.localdomain Ready Active Reachable 20.10.10 p1cfiyfyxgkhupjj03tvq40ph localhost.localdomain Down Active Unreachable 20.10.10 wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Leader 20.10.10 xlgi99te9cchyz9n3ydkycf6k localhost.localdomain Ready Active 20.10.10 [root@localhost ~]# ```
始终坚持开源开放共享精神,同时感谢您的充电鼓励和支持!
版权所有,转载本站文章请注明出处:redrose2100, http://blog.redrose2100.com/article/71
上一篇:
Docker----docker-compose初体验
下一篇:
Docker----DockerSwarm集群环境弹性服务动态扩缩容
搜索
个人成就
出版书籍
《Pytest企业级应用实战》
测试开发技术全栈公众号
测试开发技术全栈公众号
DevOps技术交流微信群
加微信邀请进群
常用网站链接
开源软件洞察
云原生技术栈全景图
Python语言官方文档
Golang官方文档
Docker官方文档
Jenkins中文用户手册
Scrapy官方文档
VUE官方文档
Harbor官方文档
openQA官方文档
云原生开源社区
开源中国
Kubernetes中文文档
Markdown语法官方教程
Kubernetes中文社区
Kubersphere官方文档
BootStrap中文网站
JavaScript中文网
NumPy官方文档
Pandas官方文档
GitLink确实开源网站
数据库排名网站
编程语言排名网站
SEO综合查询网站
数学加减法练习自动生成网站
Kickstart Generator
文章分类
最新文章
最多阅读
特别推荐
×
Close
登录
注册
找回密码
登录邮箱:
登录密码:
图片验证码:
注册邮箱:
注册密码:
邮箱验证码:
发送邮件
注册邮箱:
新的密码:
邮箱验证码:
发送邮件