Docker Swarm ÈÃÄãÊ°빦±¶

À´Ô´:¡¶Linux¾Í¸ÃÕâôѧ¡· ×÷Õß:daocloud
¡¡¡¡

 

2016 Äê DockerCon £¨Ìì°¡……ÎÒ¶àôϣÍûÎÒµ±Ê±ÔÚ³¡£©ÉÏչʾµÄ×îÖØ´óµÄ±ä¸ïÖ®Ò»¾ÍÊÇ 1.12 °æ±¾ÒýÇæµÄ Swarm ģʽ¡£ËüÒâζ×ÅʲôÄØ£¿ËüÒâζ×Å£ºÈç¹ûÄãÔÚÔËÐÐ Docker 1.12ʱ £¬Äã¾Í¿ÉÒÔÔ­Éú´´½¨Ò»¸ö Swarm ¼¯Èº¡£
´´½¨Ò»¸ö swarm ¼¯Èº

ÓÃÕâÑùÒ»Ìõ¼òµ¥µÄÃüÁ

$ docker swarm init

¾Í×ã¹»´´½¨Ò»¸ö Swarm ÁË£¨ËäÈ»ÊÇÒ»¸öÖ»ÓмòÒ×¹ÜÀí½ÚµãµÄ Swarm£¬µ«ÒѾ­ÊÇ Swarm ¼¯ÈºµÄ×î¼ò¼¯ºÏ£©¡£

$ docker node ls
ID                           HOSTNAME  MEMBERSHIP  STATUS  AVAILABILITY  MANAGER STATUS
7sytb3zk0yswdfky6mbh7nzk2 *  moby      Accepted    Ready   Active        Leader

À´¿´¿´¶à½Úµã°É£¡Ö»ÓÐÒ»¸ö½ÚµãµÄ Swarm£¬ÓÃ;ÊÇÓÐÏ޵ģ¬ËùÒÔÈÃÎÒÃÇÀ´´´½¨Ò»¸öÓÐÁ½¸ö¹ÜÀí½Úµã£¨manager nodes£©ºÍÁ½¸ö¹¤×÷½Úµã£¨worker nodes£©µÄ Swarm¡£ Ê×ÏÈ£¬ÎÒÃÇÀ´´´½¨ 4 ¸ö Docker Ö÷»ú¡£Docker Machine ÊÇÍê³É´ËÈÎÎñµÄÀíÏ빤¾ß£¬ËùÒÔÎÒÃǾÍÓÃËü¡£

$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
manager1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.0-rc3
manager2 - virtualbox Running tcp://192.168.99.101:2376 v1.12.0-rc3
worker1 - virtualbox Running tcp://192.168.99.102:2376 v1.12.0-rc3
worker2 - virtualbox Running tcp://192.168.99.103:2376 v1.12.0-rc3

Èç¹ûÄãÊÖÍ·ÉÏûÓбðµÄÓà Machine ´´½¨µÄÖ÷»ú£¬ÄÇôÔÚÏÔʾ¼¯Èº½Úµãʱ£¬ÄãµÄÏÔʾÐÅÏ¢¾ÍÐèÒªÓëÏÂÎĸø³öµÄ·¶Àý±È½Ï½Ó½ü¡£

$ docker-machine ls
NAME              ACTIVE   DRIVER         STATE     URL                         SWARM   DOCKER        ERRORS
manager1          -        virtualbox     Running   tcp://192.168.99.100:2376           v1.12.0-rc3
manager2          -        virtualbox     Running   tcp://192.168.99.101:2376           v1.12.0-rc3
worker1           -        virtualbox     Running   tcp://192.168.99.102:2376           v1.12.0-rc3
worker2           -        virtualbox     Running   tcp://192.168.99.103:2376           v1.12.0-rc3
³õʼ»¯ Swarm

ÉÏÎĽéÉÜÁËÒ»ÖÖÓà 1.12 °æÒýÇæÀ´´´½¨ Swarm µÄ×î¼òµ¥µÄÃüÁÌáʾ£º“docker swarm init”£©£¬µ«ÎÒÃÇÔÚÕâÀﻹ½«µ÷Óü¸ÖÖ¸½¼ÓÑ¡ÏÈü¯ÈºÖ÷»ú¿ÉÒÔ»¥ÏàͨÐÅ£¬²¢ÔÚÎÞÐèÐí¿ÉµÄÇé¿öϼÓÈ뼯Ⱥ¡£

$ MANAGER1_IP=$(docker-machine ip manager1)
$ docker-machine ssh manager1 docker swarm init --auto-accept manager --auto-accept worker --listen-addr $MANAGER1_IP:2377

×¢Ò⣺–listen-addr ÊÇ Swarm ÄÚ²»Í¬½Úµã»¥Ïà·ÃÎʵĵØÖ·

Ìí¼ÓµÚ¶þ¹ÜÀí½Úµã

Docker Swarm ÃüÁîÖл¹ÐèÒªÌí¼ÓһЩѡÏ

* join£º±íÃ÷Ò»¸öеĽڵ㽫±»Ìí¼Ó½ø Swarm

* –manager£º±íÃ÷½ÚµãµÄÐÔÖÊ£¨manager vs worker£©

* –listen-addr£ºÈÃÒ»¸öÐÂÌí¼ÓµÄ½Úµã¿ÉÒÔ·ÃÎÊ Swarm ÄÚµÄÆäËû½Úµã

* ×îºóµÄ²ÎÊý¾ÍÊǵÚÒ»¹ÜÀí½ÚµãµÄµØÖ·£¨¼´ÕâÒ»ÃüÁ±»Ë͵½µÄÄǸö½Úµã£©

×¢Ò⣺ÓÉÓÚ –auto-accept manager Ñ¡Ïî»áÔÚ Swarm ³õʼ»¯µÄ¹ý³ÌÖб»Ìṩ£¬ËùÒÔµÚ¶þ¹ÜÀí½Úµã»á±»×Ô¶¯½ÓÊÜ¡£Èç¹ûûÓÐÕâһѡÏÄÇôµÚ¶þ¹ÜÀí½ÚµãÐèÒª±»µÚÒ»¹ÜÀí½ÚµãÊÖ¶¯½ÓÊÜ¡£

$ MANAGER2_IP=$(docker-machine ip manager2)
docker-machine ssh manager2 docker swarm join --manager --listen-addr $MANAGER2_IP:2377 $MANAGER1_IP:2377
Ìí¼Ó¹¤×÷½Úµã

Íù¼¯ÈºÄÚÌí¼Ó¹¤×÷½ÚµãµÄ·½Ê½£¬¸úÌí¼Ó¹ÜÀí½Úµã¼¸ºõÏàͬ£º

$ WORKER1_IP=$(docker-machine ip worker1)
$ docker-machine ssh worker1 docker swarm join --listen-addr $WORKER1_IP:2377 $MANAGER1_IP:2377
$ WORKER2_IP=$(docker-machine ip worker2)
$ docker-machine ssh worker2 docker swarm join --listen-addr $WORKER2_IP:2377 $MANAGER1_IP:2377

×¢Ò⣺ÓÉÓÚ –auto-accept worker Ñ¡Ïî»áÔÚ Swarm ³õʼ»¯µÄ¹ý³ÌÖб»Ìṩ£¬ËùÒÔ¹¤×÷½Úµã»á±»×Ô¶¯½ÓÊÜ¡£Èç¹ûûÓÐÕâһѡÏÄÇô¹¤×÷½ÚµãÐèÒª±»¹ÜÀí½ÚµãÊÖ¶¯½ÓÊÜ¡£

ÎÒÃÇµÄ Swarm ¿´ÆðÀ´ÏñʲôÄØ£¿ÈÃÎÒÃÇÀ´¿´¿´¡£

$ docker-machine ssh manager1 docker node ls
ID                           HOSTNAME  MEMBERSHIP  STATUS  AVAILABILITY  MANAGER STATUS
109a5ufy8e3ey17unqa16wbj7    manager2  Accepted    Ready   Active        Reachable
4chbn8uphm1tidr93s64zknbq *  manager1  Accepted    Ready   Active        Leader
8nw7g1q0ehwq1jrvid1axtg5n    worker2   Accepted    Ready   Active
8rrdjg4uf9jcj0ma2uy8rkw5v    worker1   Accepted    Ready   Active

ÏÖÔÚÿ¸ö½Úµã¶¼¹éÊôÓÚ Swarm£¬²¢¶¼´¦ÔÚÁË´ý»ú״̬¡£¹ÜÀí½Úµã 1 ÊÇÁìµ¼Õߣ¬Ò»Çж¼¸÷¾ÓÆä룬¾®¾®ÓÐÌõ,ÊÇʲôʹËüÈç´ËÌرðÄØ£¿
Õâ¸ö Swarm Êǵõ½°²È«´«Êä²ãЭÒ飨TLS£©±£Ö¤µÄ£¬ÄÜÔÚÉ豸Íâ×Ô¶¯ÈÏÖ¤Éý¼¶¡£
Docker Swarm ÈÃÄãÊ°빦±¶Docker Swarm ÈÃÄãÊ°빦±¶

ͬÑù£¬ËüÒ²²»ÔÙÐèÒª Consul¡¢Zookeeper Ö®ÀàµÄ¼üÖµ´æ´¢£¬ËùÓж«Î÷¶¼ÔÚÕÆ¿ØÖ®ÖС£
Docker Swarm ÈÃÄãÊ°빦±¶Docker Swarm ÈÃÄãÊ°빦±¶

Ô­ÎĵØÖ·£ºhttp://www.linuxprobe.com/docker-swarm-more-with-less.html±à¼­£ºÔÀ¹ú˧£¬ÉóºËÔ±£º·ëÕñ»ª


ʱ¼ä:2016-08-03 08:48 À´Ô´:¡¶Linux¾Í¸ÃÕâôѧ¡· ×÷Õß:daocloud Ô­ÎÄÁ´½Ó

ºÃÎÄ,¶¥Ò»ÏÂ
(0)
0%
ÎÄÕÂÕæ²î,²ÈÒ»ÏÂ
(0)
0%
------·Ö¸ôÏß----------------------------


°Ñ¿ªÔ´´øÔÚÄãµÄÉí±ß-¾«ÃÀlinuxС¼ÍÄîÆ·
ÎÞÃÙÏà¹ØÎÄÕ²å¼þ£¬¿ìËÙÌáÉýÁ÷Á¿