×ðÁú¿­Ê±

ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄˮƽÉìËõºÍ¸ºÔØƽºâ

Ëæ×ÅÔÆÅÌËãºÍÈÝÆ÷ÊÖÒÕµÄÆÕ¼°  £¬Ë®Æ½ÉìËõºÍ¸ºÔØƽºâÒѳÉΪÏÖ´úÓ¦ÓóÌÐòµÄ±Ø±¸¹¦Ð§¡£Docker×÷ΪһÖÖÊ¢ÐеÄÈÝÆ÷»¯ÊÖÒÕ  £¬ÌṩÁ˶àÖÖÒªÁìÀ´¾ÙÐÐÈÝÆ÷µÄˮƽÉìËõºÍ¸ºÔØƽºâ¡£ÔÚ±¾ÎÄÖÐ  £¬ÎÒÃǽ«ÏêϸÏÈÈÝÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄˮƽÉìËõºÍ¸ºÔØƽºâ  £¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

ÈÝÆ÷ˮƽÉìËõ

ÈÝÆ÷ˮƽÉìËõÊÇָƾ֤¸ºÔØÇéÐÎ×Ô¶¯ÔöÌí»òïÔÌ­ÈÝÆ÷µÄÊýÄ¿¡£DockerÌṩÁ˶àÖÖÒªÁìÀ´¾ÙÐÐÈÝÆ÷µÄˮƽÉìËõ  £¬ÆäÖаüÀ¨Ê¹ÓÃDocker Swarm¡¢Docker ComposeºÍKubernetesµÈ¹¤¾ß¡£

ÔÚ±¾ÎÄÖÐ  £¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃDocker SwarmÀ´¾ÙÐÐÈÝÆ÷µÄˮƽÉìËõ¡£Docker SwarmÊÇDockerÔ­ÉúµÄÈÝÆ÷±àÅŹ¤¾ß  £¬Ëü¿ÉÒÔ×Ô¶¯ÖÎÀí¶à¸öDocker½Úµã  £¬²¢ÒÔÈÝÆ÷Ϊµ¥Î»¾ÙÐÐˮƽÀ©Õ¹¡£

ÏÂÃæÊÇÒ»¸öʹÓÃDocker Swarm¾ÙÐÐÈÝÆ÷ˮƽÉìËõµÄʾÀý¡£ÎÒÃǽ«Ê¹ÓÃÒ»¸ö¼òÆÓµÄWebÓ¦ÓóÌÐò×÷ΪÑÝʾĿµÄ  £¬¸ÃÓ¦ÓóÌÐòʹÓÃNode.js±àд¡£ÎÒÃÇÊ×ÏȽ¨ÉèÒ»¸öDockerfileÀ´¹¹½¨WebÓ¦ÓóÌÐòµÄ¾µÏñ¡£

FROM node:12
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]

µÇ¼ºó¸´ÖÆ

ÔÚ¹¹½¨Õâ¸ö¾µÏñºó  £¬ÎÒÃǽ«Ê¹ÓÃDocker SwarmÀ´Æô¶¯¶à¸öÈÝÆ÷  £¬²¢¾ÙÐÐˮƽÉìËõ¡£ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄÏÂÁîÀ´³õʼ»¯Docker Swarm£º

docker swarm init

µÇ¼ºó¸´ÖÆ

½Ó×Å  £¬ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄÏÂÁîÀ´Æô¶¯Ò»¸öЧÀÍ  £¬²¢Ö¸¶¨ÐèÒªÆô¶¯µÄÈÝÆ÷ÊýÄ¿£º

docker service create --replicas 3 --name webapp -p 8080:8080 my-webapp

µÇ¼ºó¸´ÖÆ

Õ⽫Æô¶¯3¸öÃûΪ¡°webapp¡±µÄÈÝÆ÷  £¬²¢½«ËüÃÇÓ³Éäµ½Ö÷»úµÄ8080¶Ë¿Ú¡£ÈôÊÇÐèÒª¸ü¸ÄÈÝÆ÷ÊýÄ¿  £¬¿ÉÒÔʹÓÃÏÂÃæµÄÏÂÁ

docker service scale webapp=5

µÇ¼ºó¸´ÖÆ

Õ⽫½«ÈÝÆ÷ÊýÄ¿ÔöÌíµ½5¸ö¡£Docker Swarm»á×Ô¶¯¸ºÔØƽºâËùÓÐÈÝÆ÷Ö®¼äµÄÇëÇó  £¬²¢ÇÒµ±ÓÐÈÝÆ÷ʧ°Üʱ  £¬»á×Ô¶¯ÖØÆôеÄÈÝÆ÷ÒÔ»Ö¸´Ð§ÀÍ¡£

ÈÝÆ÷¸ºÔØƽºâ

ÈÝÆ÷¸ºÔØƽºâÊÇÖ¸½«ÇëÇó·Ö·¢µ½¶à¸öÈÝÆ÷ÖÐ  £¬²¢È·±£Ã¿¸öÈÝÆ÷¶¼¾ßÓÐÏàͬµÄ¸ºÔØ¡£DockerÌṩÁ˶àÖÖÒªÁìÀ´¾ÙÐÐÈÝÆ÷µÄ¸ºÔØƽºâ  £¬°üÀ¨Ê¹ÓÃDocker Swarm¡¢Docker ComposeºÍNginxµÈ¹¤¾ß¡£

ÔÚ±¾ÎÄÖÐ  £¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃNginxÀ´¾ÙÐÐÈÝÆ÷µÄ¸ºÔØƽºâ¡£NginxÊÇÒ»ÖÖÊ¢ÐеÄWebЧÀÍÆ÷Èí¼þ  £¬Ò²¿ÉÒÔ×÷Ϊ·´ÏòÊðÀíЧÀÍÆ÷ºÍ¸ºÔØƽºâÆ÷ʹÓá£

ÏÂÃæÊÇÒ»¸öʹÓÃNginx¾ÙÐÐÈÝÆ÷¸ºÔØƽºâµÄʾÀý¡£ÎÒÃǽ«Ê¹ÓÃÉÏÒ»½ÚÖн¨ÉèµÄWebÓ¦ÓóÌÐò  £¬²¢Æô¶¯¶à¸öÈÝÆ÷À´´¦Öóͷ£ÇëÇó¡£ÎÒÃÇÊ×ÏȽ¨ÉèÒ»¸öNginxÉèÖÃÎļþÀ´½ç˵¸ºÔØƽºâÕ½ÂÔ¡£

upstream webapp {
    server container1:8080;
    server container2:8080;
    server container3:8080;
}

server {
    listen 80;
    server_name my-webapp.com;
    location / {
        proxy_pass http://webapp/;
    }
}

µÇ¼ºó¸´ÖÆ

Õâ¸öÉèÖÃÎļþ½ç˵ÁËÒ»¸öÃûΪ¡°webapp¡±µÄÉÏÓÎЧÀÍÆ÷  £¬ÆäÖаüÀ¨ÁË3¸öÈÝÆ÷µÄµØµãºÍ¶Ë¿Ú¡£È»ºóÎÒÃǽ«ÔÚDockerÖÐÆô¶¯Ò»¸öNginxÈÝÆ÷  £¬²¢½«Õâ¸öÉèÖÃÎļþÓ³Éäµ½ÈÝÆ÷ÄÚµÄNginxЧÀÍÆ÷ÉèÖÃĿ¼ÖС£

docker run -d -p 80:80 --name nginx -v /path/to/nginx.conf:/etc/nginx/nginx.conf nginx

µÇ¼ºó¸´ÖÆ

ͨ¹ýʹÓÃNginxÀ´¾ÙÐÐÈÝÆ÷µÄ¸ºÔØƽºâ  £¬ÎÒÃÇ¿ÉÒÔ½«ÇëÇó·Ö·¢µ½ËùÓÐÈÝÆ÷ÖÐ  £¬²¢È·±£Ã¿¸öÈÝÆ÷¶¼¾ßÓÐÏàͬµÄ¸ºÔØ¡£¸üÖ÷ÒªµÄÊÇ  £¬Nginx»¹Ö§³ÖÆäËû¸ß¼¶¹¦Ð§  £¬È綯̬ÉèÖúͻùÓÚȨÖصĸºÔØƽºâ¡£

½áÂÛ

ÔÚ±¾ÎÄÖÐ  £¬ÎÒÃÇÏêϸÏÈÈÝÁËÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄˮƽÉìËõºÍ¸ºÔØƽºâ  £¬²¢ÌṩÁËÏêϸµÄ´úÂëʾÀý¡£ÈÝÆ÷ˮƽÉìËõºÍ¸ºÔØƽºâÊÇÏÖ´úÓ¦ÓóÌÐòµÄ±Ø±¸¹¦Ð§  £¬²¢ÇÒDockerÌṩÁ˶àÖÖÇ¿Ê¢µÄ¹¤¾ßÀ´ÊµÏÖÕâЩ¹¦Ð§¡£ÈôÊÇÄúÕýÔÚʹÓÃDockerÀ´ÖÎÀíÓ¦ÓóÌÐò  £¬ÇëÎñ±ØÕÆÎÕÈÝÆ÷ˮƽÉìËõºÍ¸ºÔØƽºâµÄÊÖÒÕ¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄˮƽÉìËõºÍ¸ºÔØƽºâµÄÏêϸÄÚÈÝ  £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí  £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø  £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È  £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ  £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢  £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢  £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå  £¬9:30-18:30  £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿