docker swarm集群部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker swarm集群部署相关的知识,希望对你有一定的参考价值。
docker swarm 集群构建:
swarm 在docker 1.12 版本后内置
#h官方文档tps://docs.docker.com/engine/swarm/#feature-highlights
系统环境:
centos7.3
docker17.06
1、初始化manager节点:
docker swarm init
为实现高可用,manager节点需要有奇数个,类似zookerper选举制度。
2、复制生成的命令,在node节点运行。
#docker swarm join-token manager
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1hwdongcnsvzh92s1wnd33w9p08k1o18vobvkzu7z509xoduif-2ezofrbnkaamwuuby9d1w0wn5 10.39.3.25:2377
# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1hwdongcnsvzh92s1wnd33w9p08k1o18vobvkzu7z509xoduif-1j43vxwnsrc3cyz2y7ips3d3g 10.39.3.25:2377
示例:
如目前有 10.39.3.25--29 集群, 选其中3个25、26、27 做为manager节点,用于管理swarm集群和实现高可用。
# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
dga3oelektv4tbofub2ii9d36 cephnode5 Ready Active
j0hmbmvn9pwnpr1n9zm20j67k * cephnode3 Ready Active Reachable
k7pb8msn85c6xzflbe4r57itd cephnode1 Ready Active Reachable
mmlszdi5lcr0zt2nk44pcjvya cephnode4 Ready Active
t9f91au60k3cgf406cqe1pn2t cephnode2 Ready Active Leader
2个manager是无法实现高可用的,主节点异常后,备用节点运行命令将报错如下:
#docker node ls
Error response from daemon: rpc error: code = 2 desc = The swarm does not have a leader. It‘s possible that too few managers are online. Make sure more than half of the managers are online.
以上是关于docker swarm集群部署的主要内容,如果未能解决你的问题,请参考以下文章