docker

docker swarm集群

2019-08-13  本文已影响0人  胸口砕大石
官方教程传送门

https://docs.docker.com/engine/swarm/swarm-tutorial/

查看主机名
$ hostname
修改主机名
$ hostnamectl set-hostname manager01
$ hostnamectl set-hostname node01
$ hostnamectl set-hostname node02
开放相关端口
TCP port 2377为集群管理通信
TCP and UDP port 7946 为节点间通信
UDP port 4789 为网络间流量
本次内网直接关闭防火墙
创建一个新的swarm
$ docker swarm init --advertise-addr 192.168.7.50

Swarm initialized: current node (ibb5uph6vqzndlfnhp5y2kede) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-0*************8a 192.168.7.50:2377

To add a manager to this swarm, run:
    'docker swarm join-token manager' 
and follow the instructions.

doker通过token区分加入的是worker节点还是manager节点,
如果忘记加入命令 可以输入下面命令找回token:

$ docker swarm join-token manager
$ docker swarm join-token worker
查看集群状态
$ docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 1
Server Version: 18.03.0-ce
...
....
查看集群节点
$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
ibb5uph6vqzndlfnhp5y2kede *   manager01           Ready               Active              Leader              18.03.0-ce
在其它机器上运行加入swarm命令,如果忘记通过运行下面命令找回
$ docker swarm join-token worker
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
ibb5uph6vqzndlfnhp5y2kede *   manager01           Ready               Active              Leader              18.03.0-ce
74ftsfudbu0kh1aa3pbuz1hf2     node01              Ready               Active                                  18.03.0-ce
qwgp66f8nubephbiqo5lm24zh     node02              Ready               Active                                  18.03.0-ce
搭建docker swarm的UI Portainer
$ docker images |grep portainer
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
portainer/portainer   latest              2b4ddf654e1c        2 weeks ago         77.7MB
创建卷
$ docker volume create portainer_data

此处需要在所有管理节点上创建 volume
建议 使用普通方式挂载!!!!!!!!!

创建服务(管理节点上运行)
$ docker service create \
--name portainer \
--publish 9000:9000 \
--replicas=1 \
--constraint 'node.role == manager' \
--mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \
--mount type=volume,src=portainer_data,dst=/data \
portainer/portainer \
-H unix:///var/run/docker.sock
icsom57ekg8zoae6o2jr6qrs6
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 
查看集群服务列表
$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                        PORTS
icsom57ekg8z        portainer           replicated          1/1                 portainer/portainer:latest   *:9000->9000/tcp
输入IP+PORT进入页面,第一次登录设置密码
http://192.168.7.50:9000
上一篇下一篇

猜你喜欢

热点阅读