ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅÅƽ̨£¨ÈçDocker Swarm£©
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅÅƽ̨£¨Èçdocker swarm£©
СÐò£º
Ëæ×ÅÔÆÅÌËãºÍÈÝÆ÷ÊÖÒÕµÄѸÃÍÉú³¤£¬Ô½À´Ô½¶àµÄÆóҵѡÔñʹÓÃÈÝÆ÷À´¹¹½¨ºÍÖÎÀíÓ¦ÓóÌÐò¡£DockerÊÇÄ¿½ñ×îÊ¢ÐеÄÈÝÆ÷ÊÖÒÕÖ®Ò»£¬¶øDocker Swarm×÷ΪDocker¹Ù·½ÌṩµÄÈÝÆ÷±àÅŹ¤¾ß£¬¿ÉÒÔ×ÊÖúÎÒÃÇ¿ìËÙ¹¹½¨ºÍÖÎÀí¶à¸öÈÝÆ÷µÄ¼¯Èº¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅÅƽ̨£¬ÒÔ¼°ÔõÑùʹÓÃDocker SwarmÀ´¾ÙÐÐÈÝÆ÷µÄ±àÅźÍÖÎÀí¡£
ÉèÖÃÇéÐΣº
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚLinuxЧÀÍÆ÷ÉÏ×°ÖÃDocker¡£ÒÔUbuntuΪÀý£¬¿ÉÒÔÖ´ÐÐÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
$ sudo apt-get update $ sudo apt-get install docker.io
µÇ¼ºó¸´ÖÆ
ÉèÖÃDocker Swarm£º
³õʼ»¯Docker Swarm
Ê×ÏÈ£¬ÎÒÃÇÐèÒª½«Ò»Ì¨Ö÷»ú³õʼ»¯ÎªSwarmÖÎÀí½Úµã¡£ÔÚÖ÷»úÉÏÖ´ÐÐÒÔÏÂÏÂÁ
$ sudo docker swarm init
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÀֳɺ󣬻᷵»ØÒ»¸öÏÂÁÀàËÆÓÚ£º
Swarm initialized: current node (xxxx) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token xxxxxxxx
µÇ¼ºó¸´ÖÆ
½«¸ÃÏÂÁîÉúÑÄÏÂÀ´£¬×÷ΪÉèÖÃÆäËû½ÚµãʱʹÓá£
Ìí¼ÓSwarm½Úµã
½ÓÏÂÀ´£¬ÎÒÃÇ¿ÉÒÔ½«ÆäËû½Úµã¼ÓÈëµ½Swarm¼¯ÈºÖС£ÔÚнڵãÉÏÖ´ÐÐÉúÑĵÄÏÂÁÀàËÆÓÚ£º
$ sudo docker swarm join --token xxxxxxxx
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÀֳɺó£¬Ð½ڵã¾Í»áÀֳɼÓÈëµ½Swarm¼¯ÈºÖС£
Éó²éSwarm½Úµã
¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÉó²éSwarmÖеĽڵ㣺
$ sudo docker node ls
µÇ¼ºó¸´ÖÆ
Ö´ÐÐЧ¹ûÀàËÆÓÚ£º
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION xxxxx node1 Ready Active Reachable 19.03.13 xxxxx node2 Ready Active Leader 19.03.13
µÇ¼ºó¸´ÖÆ
ͨ¹ý״̬ºÍ¿ÉÓÃÐÔ£¬ÎÒÃÇ¿ÉÒÔÏàʶµ½Swarm¼¯ÈºÖи÷¸ö½ÚµãµÄÐÅÏ¢¡£
±àÅÅÈÝÆ÷£º
ÎÒÃÇÒѾÀֳɵØÉèÖÃÁËDocker Swarm¼¯Èº£¬½ÓÏÂÀ´¿ÉÒÔʹÓÃSwarmÀ´¾ÙÐÐÈÝÆ÷µÄ±àÅźÍÖÎÀí¡£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄʾÀý£¬ÓÃÓÚ½¨Éè²¢ÔËÐÐÒ»¸öNginxЧÀÍ¡£
½¨ÉèÒ»¸öÍøÂç
ÔÚSwarm¼¯ÈºÖУ¬±£´æoverlayÍøÂ磬ÓÃÓÚÈÝÆ÷Ö®¼äµÄͨѶ¡£ÎÒÃÇ¿ÉÒÔ½¨ÉèÒ»¸öoverlayÍøÂ磬ÀýÈ磺
$ sudo docker network create -d overlay my_network
µÇ¼ºó¸´ÖÆ
½¨ÉèÒ»¸öЧÀÍ
ʹÓÃÒÔÏÂÏÂÁÉèÒ»¸öNginxЧÀÍ£º
$ sudo docker service create --name my_nginx --network my_network --publish 8080:80 nginx
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁÔÚSwarm¼¯ÈºÖн¨ÉèÒ»¸öÃûΪmy_nginxµÄЧÀÍ£¬Ê¹ÓÃmy_networkÍøÂ磬²¢½«ÈÝÆ÷µÄ80¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ8080¶Ë¿Ú¡£
Éó²éЧÀÍ״̬
¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÉó²éЧÀ͵Ä״̬£º
$ sudo docker service ls
µÇ¼ºó¸´ÖÆ
Ö´ÐÐЧ¹ûÀàËÆÓÚ£º
ID NAME MODE REPLICAS IMAGE PORTS xxxxx my_nginx replicated 1/1 nginx:latest *:8080->80/tcp
µÇ¼ºó¸´ÖÆ
ͨ¹ýREPLICASÁУ¬ÎÒÃÇ¿ÉÒÔÏàʶµ½Ä¿½ñÔËÐеÄÈÝÆ÷ʵÀýÊýÄ¿¡£
À©Õ¹Ð§ÀÍ
ÈôÊÇÐèÒªÔöÌíÈÝÆ÷ʵÀýÊýÄ¿£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐÐÀ©Õ¹£º
$ sudo docker service scale my_nginx=3
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁmy_nginxЧÀ͵ÄʵÀýÊýÄ¿À©Õ¹µ½3¸ö¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅÅƽ̨£¨Èçdocker swarm£©£¬²¢ÇÒͨ¹ýÒ»¸ö¼òÆÓµÄʾÀýÑÝʾÁËÔõÑùʹÓÃDocker Swarm¾ÙÐÐÈÝÆ÷µÄ±àÅźÍÖÎÀí¡£ËäÈ»£¬³ýÁËÉÏÊöʾÀýÖ®Í⣬Docker SwarmÉÐÓиü¶àµÄ¹¦Ð§ºÍÓ÷¨£¬¶ÁÕß¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó¾ÙÐÐÉîÈëѧϰºÍÑо¿¡£Ï£Íû±¾ÎÄÄܹ»×ÊÖúµ½¶ÁÕߣ¬Îª¸÷ÈËÔÚLinuxÇéÐÎÖд¸ß¿ÉÓõÄÈÝÆ÷±àÅÅƽ̨ÌṩһЩ²Î¿¼¡£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅÅƽ̨£¨ÈçDocker Swarm£©µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡