Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
44:ce:a9:46:24:60:d8:06:60:d9:df:5d:b4:33:1b:03 root@node1
The key's randomart image is:
+--[ RSA 2048]----+
|+==.. . .E.. |
|ooo. o + .... |
| . . o * .* |
| o + . * |
| o S . |
| . |
| |
| |
| |
+-----------------+
发布sshkey到各个节点
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-2fmdoue8fnqf26yp5m3quoxav33nxrjwbogwhcftpnlpjgoy16-7c3tgluhurunkdy9y9fc0ei65 \
192.168.1.107:2377
在node2和node3上面执行(直接将红色代码复制粘贴到节点服务器即可)
[iyunv@node2 ~]#docker swarm join \
> --token SWMTKN-1-2fmdoue8fnqf26yp5m3quoxav33nxrjwbogwhcftpnlpjgoy16-7c3tgluhurunkdy9y9fc0ei65 \
> 192.168.1.107:2377
This node joined a swarm as a worker.
[iyunv@node3 ~]# docker swarm join \
> --token SWMTKN-1-2fmdoue8fnqf26yp5m3quoxav33nxrjwbogwhcftpnlpjgoy16-7c3tgluhurunkdy9y9fc0ei65 \
> 192.168.1.107:2377
This node joined a swarm as a worker.
如果想让服务器以manager节点加入swar集群在node1上面查询(直接将红色代码复制粘贴到节点服务器即可)
1
[iyunv@node1 ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:
8s3cxo00phorkfjb1qhr9iu05 node2 Ready Active
9boy0msaa19b67z4ssp8yc32d * node1 Ready Active Leader
cigtp3x969rcsjzlh5cp2g7s7 node3 Ready Active
不过现在集群只有一个manager节点node1, 为了swarm集群的高可用,和避免单点故障. 我们希望建立多个manager节点集群.
只需要通过如下命令, 将node2worker节点提升成为manager节点:
1
[iyunv@node1 ~]# docker node promote node2
Node node2 promoted to a manager in the swarm.
1
[iyunv@node1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
8s3cxo00phorkfjb1qhr9iu05 node2 Ready Active Reachable
9boy0msaa19b67z4ssp8yc32d * node1 Ready Active Leader
cigtp3x969rcsjzlh5cp2g7s7 node3 Ready Active
查看node2的docker info
1
[iyunv@node2~]# docker info
查看主要内容
Swarm: active
NodeID: 8s3cxo00phorkfjb1qhr9iu05
Is Manager: true
ClusterID: 4536wglalec5c489ul0gd8dhn
Managers: 2
Nodes: 3
查看node3的docker info
1
[iyunv@node3 ~]# docker info
查看主要内容
Swarm: active
NodeID: cigtp3x969rcsjzlh5cp2g7s7
Is Manager: false
Node Address: 192.168.1.130
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
8s3cxo00phorkfjb1qhr9iu05 * node2 Ready Active Reachable
9boy0msaa19b67z4ssp8yc32d node1 Ready Active Leader
cigtp3x969rcsjzlh5cp2g7s7 node3 Ready Active
使用命令让node3下线
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
8s3cxo00phorkfjb1qhr9iu05 * node2 Ready Active Reachable
9boy0msaa19b67z4ssp8yc32d node1 Ready Active Leader
cigtp3x969rcsjzlh5cp2g7s7 node3 Ready Drain
使用命令让node3上线
1
[iyunv@node2 ~]# docker node update --availability active cigtp3x969rcsjzlh5cp2g7s7