×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùÔÚLinuxÉÏ°²ÅŸ߿ÉÓõÄ΢ЧÀͼܹ¹

ÔõÑùÔÚlinuxÉÏ°²ÅŸ߿ÉÓõÄ΢ЧÀͼܹ¹

СÐò£º

Ëæ×ÅÏÖ´úÈí¼þ¿ª·¢µÄÒ»Ö±Éú³¤£¬Î¢Ð§ÀͼÜ×é³ÉΪÁ˹¹½¨ÎÞа¡¢¿ÉÀ©Õ¹ºÍ¿Éά»¤µÄÓ¦ÓóÌÐòµÄÒ»ÖÖÊ¢Ðз½·¨¡£ÔÚ΢ЧÀͼܹ¹ÖУ¬Ó¦ÓóÌÐò±»²ð·Ö³ÉһϵÁÐСÐÍ×ÔÁ¦µÄЧÀÍ£¬Ã¿¸öЧÀÍÈÏÕæÒ»¸öÌض¨µÄ¹¦Ð§£¬²¢Í¨¹ýÍøÂç¾ÙÐÐͨѶ¡£ÓÉÓÚЧÀÍÓëЧÀÍÖ®¼äµÄ×ÔÁ¦ÐÔ£¬ÎÒÃÇ¿ÉÒÔ¸üÈÝÒ׵ؾÙÐа²ÅÅ¡¢À©Õ¹ºÍά»¤¡£

±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxÉÏ°²ÅÅÒ»¸ö¸ß¿ÉÓõÄ΢ЧÀͼܹ¹£¬²¢ÌṩһЩÊÊÓõĴúÂëʾÀý¡£

µÚÒ»²¿·Ö£º×¼±¸ÊÂÇé

ÔËÐÐÇéÐΣºÊ×ÏÈÈ·±£ÄãÓÐһ̨ÔËÐÐLinuxµÄЧÀÍÆ÷£¬¿ÉÒÔÊÇÐéÄâ»ú»òÎïÀíЧÀÍÆ÷¡£ÎÒÃÇÍƼöʹÓÃһЩʢÐеÄLinux¿¯Ðа棬ÀýÈçUbuntu»òCentOS¡£

×°ÖÃDocker£ºDockerÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔ×ÊÖúÎÒÃÇ¿ìËÙ°²ÅźÍÖÎÀí΢ЧÀÍ¡£ÔÚLinuxÉÏ×°ÖÃDockerºÜÊǼòÆÓ£¬¿ÉÒÔͨ¹ý¹Ù·½Îĵµ¾ÙÐÐ×°Öá£

µÚ¶þ²¿·Ö£º¹¹½¨Î¢Ð§À;µÏñ

½¨ÉèDockerfile£ºÔÚÿ¸öЧÀ͵ĸùĿ¼Ï½¨ÉèÒ»¸öDockerfileÎļþ£¬ÓÃÓÚ¹¹½¨¾µÏñ¡£DockerfileÊÇÒ»¸ö´¿Îı¾Îļþ£¬½ç˵ÁËһϵÁÐÖ¸ÁîÀ´¹¹½¨¾µÏñ¡£

±àдDockerfile£ºÀýÈ磬ÎÒÃǼÙÉèÎÒÃÇÓÐÒ»¸öÃûΪ”userservice”µÄ΢ЧÀÍ£¬ÎÒÃǵÄDockerfileÈçÏÂËùʾ£º

# »ùÓÚJavaµÄ¾µÏñ
FROM openjdk:8-jdk-alpine

# ÉèÖÃÊÂÇéĿ¼
WORKDIR /app

# ½«Ó¦ÓóÌÐò¸´ÖƵ½¾µÏñ
COPY target/userservice.jar .

# ½ç˵ÈÝÆ÷̻¶µÄ¶Ë¿Ú
EXPOSE 8080

# ÉèÖÃÇéÐαäÁ¿
ENV JAVA_OPTS=""

# Æô¶¯Ó¦ÓóÌÐò
ENTRYPOINT exec java $JAVA_OPTS -jar userservice.jar

µÇ¼ºó¸´ÖÆ

¹¹½¨¾µÏñ£ºÊ¹ÓÃÒÔÏÂÏÂÁî¹¹½¨¾µÏñ£¨¼ÙÉèDockerfileºÍÓ¦ÓóÌÐòÔÚͳһĿ¼Ï£©£º

docker build -t userservice .

µÇ¼ºó¸´ÖÆ

µÚÈý²¿·Ö£º°²ÅÅ΢ЧÀͼ¯Èº

½¨ÉèDocker Swarm£ºÔËÐÐÒÔÏÂÏÂÁÎÒÃǵÄЧÀÍÆ÷ת»»ÎªÒ»¸öDocker Swarm¼¯ÈºµÄÖÎÀí½Úµã¡£

docker swarm init

µÇ¼ºó¸´ÖÆ

°²ÅÅЧÀÍ£º½¨ÉèÒ»¸ödocker-compose.yamlÎļþ£¬ÓÃÓÚ½ç˵ÎÒÃǵÄ΢ЧÀͼܹ¹¡£ÒÔÏÂÊÇÒ»¸öʾÀýÉèÖÃÎļþ£º

version: '3'
services:
  userservice:
    image: userservice
    deploy:
      replicas: 3
      restart_policy:
        condition: on-failure

µÇ¼ºó¸´ÖÆ

´ËÉèÖÃÎļþÖ¸¶¨ÁËÎÒÃǵÄuserserviceЧÀÍÓ¦¸ÃÔËÐÐ3¸ö¸±±¾£¬²¢ÔÚ±¬·¢¹ÊÕÏʱ×Ô¶¯ÖØÆô¡£

ʹÓÃdocker stackÏÂÁî°²ÅÅЧÀÍ£º

docker stack deploy -c docker-compose.yaml myservice

µÇ¼ºó¸´ÖÆ

Õ⽫ÔÚÎÒÃǵÄDocker Swarm¼¯ÈºÖа²ÅÅÎÒÃǵÄ΢ЧÀͼ¯Èº¡£

µÚËIJ¿·Ö£º¼à¿ØÓëÀ©Õ¹

ʹÓÃDocker Swarm¾ÙÐÐЧÀÍÀ©Õ¹£ºÈôÊÇÎÒÃÇÐèÒª¸ü¶àµÄЧÀÍʵÀýÀ´´¦Àí¸ü¸ßµÄ¸ºÔØ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ©Õ¹Ð§ÀÍ£º

docker service scale myservice_userservice=5

µÇ¼ºó¸´ÖÆ

Õ⽫½«userserviceЧÀ͵ĸ±±¾ÊýÀ©Õ¹µ½5¸ö¡£

ʹÓÃPrometheusºÍGrafana¾ÙÐмà¿Ø£ºPrometheusÊÇÒ»¸ö¿ªÔ´µÄ¼à¿Øϵͳ£¬¶øGrafanaÊÇÒ»¸ö¿ÉÊÓ»¯¹¤¾ß¡£ÎÒÃÇ¿ÉÒÔʹÓÃÕâÁ½¸ö¹¤¾ßÀ´¼à¿ØÎÒÃǵÄ΢ЧÀͼ¯Èº¡£

ʹÓÃÒÔÏÂÏÂÁîÆô¶¯PrometheusºÍGrafanaÈÝÆ÷£º

docker run -d -p 9090:9090 --name prometheus prom/prometheus
docker run -d -p 3000:3000 --name grafana grafana/grafana

µÇ¼ºó¸´ÖÆ

ÉèÖÃPrometheusÒÔ¼à¿ØÎÒÃǵÄ΢ЧÀͼ¯Èº£¬²¢Ê¹ÓÃGrafana½¨ÉèÒDZí°åÀ´Éó²é¼à¿ØÊý¾Ý¡£

½áÂÛ£º

ÒÔÉÏÊÇÔÚLinuxÉÏ°²ÅŸ߿ÉÓÃ΢ЧÀͼܹ¹µÄ°ì·¨ºÍʾÀý´úÂ롣ͨ¹ýʹÓÃDockerºÍDocker Swarm£¬ÎÒÃÇ¿ÉÒÔÇáËɵع¹½¨¡¢°²ÅźÍÀ©Õ¹Î¢Ð§Àͼ¯Èº¡£Í¬Ê±£¬Ê¹ÓÃPrometheusºÍGrafana¿ÉÒÔ×ÊÖúÎÒÃǼà¿Ø΢ЧÀ͵ÄÐÔÄܺͿµ½¡×´Ì¬¡£Ï£Íû±¾ÎĶÔÄú¹¹½¨¸ß¿ÉÓÃ΢ЧÀͼܹ¹ÌṩÁËһЩ×ÊÖúºÍÖ¸µ¼¡£

ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏ°²ÅŸ߿ÉÓõÄ΢ЧÀͼܹ¹µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ