LinuxºÍDocker£ºÔõÑùʵÏÖÈÝÆ÷µÄ×Ô¶¯À©ËõÈݺ͸ºÔØƽºâ£¿
linuxºÍdocker£ºÔõÑùʵÏÖÈÝÆ÷µÄ×Ô¶¯À©ËõÈݺ͸ºÔØƽºâ£¿
СÐò£º
ÔÚÏÖ´úÈí¼þ¿ª·¢Àú³ÌÖУ¬ÈÝÆ÷»¯ÊÖÒÕÒѾ³ÉΪÁ˺ÜÊÇÊ¢ÐеĽâ¾ö¼Æ»®¡£¶øÆäÖÐ×îÊܽӴýµÄÈÝÆ÷ƽ̨֮һ¼´ÊÇDocker¡£DockerµÄʹÓÿÉÒÔ´øÀ´Ðí¶àÓÅÊÆ£¬Èç¸ü¸ßµÄ¿ÉÒÆÖ²ÐÔ¡¢¸ü¿ìµÄ°²ÅÅËÙÂʺ͸ü¸ßµÄ×ÊԴʹÓÃÂʵȡ£È»¶ø£¬ÔÚÏÖʵ°²ÅźÍÖÎÀí´ó¹æÄ£Ó¦ÓóÌÐòʱ£¬ÈÝÆ÷µÄ×Ô¶¯À©ËõÈݺ͸ºÔØƽºâ±äµÃÓÈΪÖ÷Òª¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃLinuxºÍDockerʵÏÖÈÝÆ÷µÄ×Ô¶¯À©ËõÈݺ͸ºÔØƽºâ¡£
Ò»¡¢ÈÝÆ÷×Ô¶¯À©ËõÈÝ
ÈÝÆ÷µÄ×Ô¶¯À©ËõÈÝ¿ÉÒÔƾ֤ӦÓóÌÐòµÄ¸ºÔØÇéÐÎÀ´¶¯Ì¬µØÔöÌí»òïÔÌÈÝÆ÷µÄÊýÄ¿£¬´Ó¶ø¸üºÃµØÓ¦¶ÔÁ÷Á¿á¯Áë»òµÍ¹ÈµÄÇéÐΡ£
ÔÚDockerÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃDocker ComposeºÍDocker SwarmÀ´ÊµÏÖÈÝÆ÷µÄ×Ô¶¯À©ËõÈÝ¡£Docker ComposeÊÇÒ»¸ö½ç˵ºÍÔËÐжà¸öÈÝÆ÷Ó¦ÓõŤ¾ß£¬¶øDocker SwarmÊÇÒ»¸öÓÃÓÚÔÚ¶à¸öDockerÖ÷»úÉϾÙÐÐÈÝÆ÷±àÅźÍÖÎÀíµÄ¹¤¾ß¡£
ÏÂÃæÊÇÒ»¸öʹÓÃDocker ComposeºÍDocker SwarmʵÏÖÈÝÆ÷×Ô¶¯À©ËõÈݵÄʾÀý£º
version: '3' services: web: build: . image: myapp deploy: replicas: 3 resources: limits: cpus: '0.5' memory: 512M restart_policy: condition: on-failure
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪwebµÄЧÀÍ£¬Ö¸¶¨ÁËÓ¦ÓóÌÐòµÄ¾µÏñ¡¢¸±±¾ÊýÒÔ¼°×ÊÔ´ÏÞÖƵȡ£Í¨¹ýʹÓÃreplicas: 3²ÎÊý£¬ÎÒÃÇÖ¸¶¨Á˳õʼµÄÈÝÆ÷¸±±¾ÊýΪ3¸ö¡£µ±ÐèҪƾ֤¸ºÔØÇéÐξÙÐÐÀ©ËõÈÝʱ£¬ÎÒÃÇ¿ÉÒÔʹÓùٷ½ÌṩµÄdocker service scaleÏÂÁîÀ´ÐÞ¸ÄÈÝÆ÷µÄ¸±±¾Êý¡£
ÀýÈ磬Ҫ½«¸±±¾ÊýÀ©´óµ½5¸ö£¬ÎÒÃÇ¿ÉÒÔÔËÐÐÒÔÏÂÏÂÁ
$ docker service scale web=5
µÇ¼ºó¸´ÖÆ
ÕâÑù£¬Docker Swarm¾Í»áƾ֤Ŀ½ñµÄ¸ºÔØÇéÐÎ×Ô¶¯ÔöÌí»òïÔÌÈÝÆ÷µÄÊýÄ¿£¬´Ó¶øʵÏÖÈÝÆ÷µÄ×Ô¶¯À©ËõÈÝ¡£
¶þ¡¢¸ºÔØƽºâ
ÔÚDockerÖУ¬¸ºÔØƽºâ¿ÉÒÔͨ¹ý¶àÖÖ·½·¨À´ÊµÏÖ£¬ÈçʹÓÃDocker SwarmµÄÄÚÖøºÔØƽºâÆ÷¡¢Ê¹ÓõÚÈý·½¸ºÔØƽºâÆ÷ÈçNginx»òHAProxyµÈ¡£
ÏÂÃæÊÇÒ»¸öʹÓÃDocker SwarmÄÚÖøºÔØƽºâÆ÷ʵÏÖ¸ºÔØƽºâµÄʾÀý£º
version: '3' services: web: build: . image: myapp deploy: replicas: 3 resources: limits: cpus: '0.5' memory: 512M restart_policy: condition: on-failure ports: - target: 80 published: 8080 protocol: tcp mode: host
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪwebµÄЧÀÍ£¬²¢½«Ó¦ÓóÌÐòµÄÈÝÆ÷¼àÌý¶Ë¿ÚÓ³Éäµ½ÁËËÞÖ÷»úµÄ8080¶Ë¿Ú¡£ÕâÑù£¬ËÞÖ÷»ú¾Í¿ÉÒÔͨ¹ý»á¼û8080¶Ë¿ÚÀ´»á¼ûÓ¦ÓóÌÐò¡£
Docker Swarm»á×Ô¶¯½«ÇëÇóͨ¹ý¸ºÔØƽºâÆ÷·Ö·¢µ½¶à¸öÈÝÆ÷ʵÀýÖУ¬´Ó¶øʵÏÖ¸ºÔØƽºâ¡£ÈôÊÇij¸öÈÝÆ÷ʵÀý±¬·¢¹ÊÕÏ£¬Docker Swarm»á×Ô¶¯½«ÇëÇóת·¢µ½ÆäËûÕý³£ÔËÐеÄÈÝÆ÷ʵÀýÉÏ£¬´Ó¶øÌá¸ßÁËÓ¦ÓóÌÐòµÄ¿ÉÓÃÐԺͿɿ¿ÐÔ¡£
ËäÈ»£¬ÎÒÃÇÒ²¿ÉÒÔʹÓõÚÈý·½¸ºÔØƽºâÆ÷ÈçNginx»òHAProxyÀ´ÊµÏÖ¸üÖØ´óµÄ¸ºÔØƽºâÕ½ÂÔ¡£ÔÚÕâÖÖÇéÐÎÏ£¬ÎÒÃÇÐèÒªµ¥¶À°²ÅźÍÉèÖøºÔØƽºâÆ÷£¬²¢½«ÇëÇóת·¢µ½¶à¸öDockerÈÝÆ÷ʵÀýÉÏ¡£
½áÂÛ£º
ʹÓÃLinuxºÍDocker£¬ÎÒÃÇ¿ÉÒÔºÜÀû±ãµØʵÏÖÈÝÆ÷µÄ×Ô¶¯À©ËõÈݺ͸ºÔØƽºâ¡£Í¨¹ýʹÓÃDocker ComposeºÍDocker Swarm£¬ÎÒÃÇ¿ÉÒÔÇáËɵؽç˵ºÍÖÎÀí¶à¸öÈÝÆ÷Ó¦Ó᣶øͨ¹ýʹÓÃDocker SwarmÄÚÖõĸºÔØƽºâÆ÷»òÕßµÚÈý·½¸ºÔØƽºâÆ÷£¬ÎÒÃÇ¿ÉÒÔΪӦÓóÌÐòÌṩ¸ß¿ÉÓÃÐԺͿɿ¿ÐÔ¡£
ÕÆÎÕÁËÈÝÆ÷µÄ×Ô¶¯À©ËõÈݺ͸ºÔØƽºâµÄÊÖÒÕ£¬ÎÒÃÇÄܹ»¸üºÃµØÓ¦¶Ô²î±ð¹æÄ£ºÍ¸ºÔØÇéÐÎϵÄÓ¦ÓóÌÐòÐèÇ󣬴ӶøÌá¸ßÕûÌåµÄÐÔÄܺͿÉÓÃÐÔ¡£
ÒÔÉϾÍÊÇLinuxºÍDocker£ºÔõÑùʵÏÖÈÝÆ÷µÄ×Ô¶¯À©ËõÈݺ͸ºÔØƽºâ£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡