1、创建docker集群manger(要保存初始化后token,因为在节点加入时要使用token作为通讯的密钥)
docker swarm init --advertise-addr 10.1.62.59
上面命令执行后,加入swarm集群,输出的信息中包含了节点加入集群的方式:
[root@hadoop1 ~]# docker swarm init --advertise-addr 10.1.62.59 Swarm initialized: current node (ukjug2s28r3caynv8s22x4pg4) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-2im04kswll0i7iuc7tvgzmsxtgcs14amoecc12ho5i0kvc0csl-5a10y5vwpacqevdbuomc29ke4 10.1.62.59:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
2、把节点添加到swarm集群
docker swarm join --token SWMTKN-1-3fzyz5knfbhw9iqlzxhb6dmzdtr0izno9nr7iqc5wid09uglh8-0mocmawzvm3xge6s37n5a48fw 10.1.62.59:2377
若不记得token了, 可以用命令查询
docker swarm join-token manager
3、离开swarm集群
在节点执行命令,让节点处于down状态
docker swarm leave
加上--force,强制离开集群
docker swarm leave --force
4、docker node命令
[root@hadoop1 ~]# docker node --help Usage: docker node COMMAND Manage Swarm nodes Options: Commands: demote Demote one or more nodes from manager in the swarm inspect Display detailed information on one or more nodes ls List nodes in the swarm promote Promote one or more nodes to manager in the swarm ps List tasks running on one or more nodes, defaults to current node rm Remove one or more nodes from the swarm update Update a node # demote 将管理节点降级为普通节点 # inspect 查看节点的详细信息 # ls 列出节点 # promote 将普通节点升级为管理节点 # ps 查看运行的任务 # rm 从swarm集群中删除节点 # update 改变集群节点状态
4、docker node update 命令
[root@hadoop1 ~]# docker node update --help Usage: docker node update [OPTIONS] NODE Update a node Options: --availability string Availability of the node ("active"|"pause"|"drain") --label-add list Add or update a node label (key=value) --label-rm list Remove a node label if exists --role string Role of the node ("worker"|"manager") # 主要使用availability string # active 节点状态正常 # pause 节点挂起、暂停 # drain 排除节点,比如将master节点排除,不分配任务,只作为管理节点
5、docker service 命令
[root@master ~]# docker service --help Usage: docker service COMMAND Manage services Options: Commands: create Create a new service inspect Display detailed information on one or more services logs Fetch the logs of a service or task 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 service
标签:node,--,swarm,集群,docker,节点,more From: https://www.cnblogs.com/shenh/p/16008319.html