设为首页 收藏本站
查看: 950|回复: 0

[经验分享] docker(2) 三剑客 docker-machine安装&管理swarm

[复制链接]

尚未签到

发表于 2017-12-6 19:36:12 | 显示全部楼层 |阅读模式
ubuntu     系统类型

test                       docker管理操作用户

192.168.1.73   swarm-node

192.168.1.80   swarm-master

修改使用国内镜像




curl -sSL https://get.daocloud.io/daotools/set_mirror.sh |sudo  sh -s http://abcd1234.m.daocloud.io
1、swarm-master 创建集群

1.1 切换切换活跃主机






test@bogon:~$ docker-machine ls
NAME   ACTIVE   DRIVER    STATE     URL                       SWARM   DOCKER        ERRORS
73     *        generic   Running   tcp://192.168.1.73:2376           v17.06.0-ce   
80     -        generic   Running   tcp://192.168.1.80:2376           v17.06.0-ce   
test@bogon:~$ docker-machine active
73
test@bogon:~$ eval $(docker-machine env 80)
test@bogon:~$ docker-machine active
80
  1.2创建swarn镜像





test@bogon:~$ docker run swarm create
Unable to find image 'swarm:latest' locally
latest: Pulling from library/swarm
248cc99c8148: Pull complete
0aeceddbda61: Pull complete
c90a34ed5817: Pull complete
Digest: sha256:02040b8e8292aacb6e30be8babd613f1c253a3ec665d2fbc178d1745810fdd29
Status: Downloaded newer image for swarm:latest
Token based discovery is now deprecated and might be removed in the future.
It will be replaced by a default discovery backed by Docker Swarm Mode.
Other mechanisms such as consul and etcd will continue to work as expected.
3e2a3fa482c1994ad5ee684f120e27c4
  #最后一行为CLUSTER_ID一定保留下好,下面增加节点都会用到


1.3增加主控节点swarm-master




test@bogon:~$ docker-machine create --driver generic  --generic-ip-address=192.168.1.80   --generic-ssh-key ~/.ssh/id_rsa  --generic-ssh-user=test --swarm --swarm-master --swarm-discovery token://3e2a3fa482c1994ad5ee684f120e27c4 swarm-master
Running pre-create checks...
Creating machine...
(swarm-master) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Configuring swarm...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env swarm-master
test@bogon:~$ docker-machine ls
NAME           ACTIVE   DRIVER    STATE     URL                       SWARM                   DOCKER        ERRORS
73             -        generic   Running   tcp://192.168.1.73:2376                           v17.06.0-ce   
80             *        generic   Running   tcp://192.168.1.80:2376                           v17.06.0-ce   
swarm-master   *        generic   Running   tcp://192.168.1.80:2376   swarm-master (master)   v17.06.0-ce
  1.4 增加swarm节点
  #普通节点没有--swarm-master选项



test@bogon:~$ docker-machine create --driver generic  --generic-ip-address=192.168.1.73   --generic-ssh-key ~/.ssh/id_rsa  --generic-ssh-user=test --swarm --swarm-discovery token://3e2a3fa482c1994ad5ee684f120e27c4 swarm-node1
Running pre-create checks...
Creating machine...
(swarm-node1) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Configuring swarm...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env swarm-node1
test@bogon:~$ docker-machine ls
NAME           ACTIVE   DRIVER    STATE     URL                       SWARM                   DOCKER        ERRORS
swarm-master   *        generic   Running   tcp://192.168.1.80:2376   swarm-master (master)   v17.06.0-ce   
swarm-node1    -        generic   Running   tcp://192.168.1.73:2376   swarm-master            v17.06.0-ce   
  1.5 查看swarm状态



test@bogon:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
0jmswkqce9cqjvri9awdm37ty     swarm-node1         Ready               Active              
69nkaqu3ivfmty5isz0ug0oiw *   swarm-master        Ready               Active              Leader
  2管理swarm
  2.1退出集群



test@bogon:~$ docker swarm  leave --force
Node left the swarm.
  #使用docker-machine切换环境分别在swarm-node1,swarn-master退出集群,以下仅涉及到切换环境不提供代码参见1.1
  2.2 swarm-master建立集群



test@bogon:~$ docker swarm  init
Swarm initialized: current node (69nkaqu3ivfmty5isz0ug0oiw) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1qj2mfe14jw2tzhg1fxpqiyhxpnm4bqhrhae0dtpp6ip9og4s3-btyj7t5304eyeuhrl4dw1vx1l 192.168.1.80:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
  #同样token很重要,不要丢失,docker代码提示很明白,加入集群命令摆在那里
  2.3 swarm-node1 加入集群



test@bogon:~$ docker swarm join --token SWMTKN-1-1qj2mfe14jw2tzhg1fxpqiyhxpnm4bqhrhae0dtpp6ip9og4s3-btyj7t5304eyeuhrl4dw1vx1l 192.168.1.80:2377
This node joined a swarm as a worker.
test@bogon:~$ eval $(docker-machine env swarm-master)
test@bogon:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
0jmswkqce9cqjvri9awdm37ty     swarm-node1         Ready               Active              
69nkaqu3ivfmty5isz0ug0oiw *   swarm-master        Ready               Active              Leader
  3 删除节点
  3.1管理节点删除



test@swarm-master:~$ docker node ls
ID                          HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
0jmswkqce9cqjvri9awdm37ty     swarm-node1         Ready               Active              
69nkaqu3ivfmty5isz0ug0oiw *   swarm-master        Ready               Active              Leader
#删除管理节点需要增加 --force
test@swarm-master:~$ docker swarm leave --force
Node left the swarm.
#删除完毕已经查不到swarm信息了
test@swarm-master:~$ docker node ls
Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
  3.2 删除普通节点



test@swarm-node1:~$ docker swarm leave --force
Node left the swarm.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421429-1-1.html 上篇帖子: 访问远程的docker 下篇帖子: 在Docker中运行asp.net core 跨平台应用程序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表