ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂç
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂç
СÐò£º
ÔÚÏÖ´úµÄÔÆÅÌËãÇéÐÎÖУ¬ÈÝÆ÷ÊÖÒÕÒѾ³ÉΪһÖÖºÜÊÇÊ¢ÐеݲÅÅÓ¦ÓóÌÐòµÄ·½·¨¡£¶øÔÚÈÝÆ÷ÍøÂç·½Ã棬¸ß¿ÉÓÃÐÔÊÇÒ»¸öÒªº¦µÄÐèÇó¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂ磬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£
Ò»¡¢Ê¹ÓÃDocker Swarm´î½¨¼¯Èº
Docker SwarmÊÇÒ»¸öÈÝÆ÷±àÅŹ¤¾ß£¬¿ÉÒÔÈÃÎÒÃÇÇáËɵØÖÎÀí¶à¸öDockerÈÝÆ÷¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒª´î½¨Ò»¸öDocker Swarm¼¯Èº£¬ÒÔÏÂÊǼòÆӵİ취£º
×°ÖÃDocker EngineºÍDocker Swarm
ÔÚÿ¸ö½ÚµãÉÏ×°ÖÃDocker EngineºÍDocker Swarm£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
$ curl -fsSL https://get.docker.com -o get-docker.sh $ sudo sh get-docker.sh $ sudo usermod -aG docker your-user $ docker swarm init --advertise-addr your-ip
µÇ¼ºó¸´ÖÆ
¼ÓÈ뼯Ⱥ
ÔÚÆäËû½ÚµãÉÏʹÓÃÒÔÏÂÏÂÁî¼ÓÈ뼯Ⱥ£º
$ docker swarm join --token your-token your-ip
µÇ¼ºó¸´ÖÆ
ÉèÖÃÍøÂç
ÔÚ¼¯ÈºÖн¨ÉèÒ»¸öoverlayÍøÂ磬ÓÃÓÚÈÝÆ÷Ö®¼äµÄͨѶ£º
$ docker network create --driver overlay my-network
µÇ¼ºó¸´ÖÆ
ÔËÐÐЧÀÍ
½¨ÉèÒ»¸ö¿É¸ß¿ÉÓõÄЧÀÍ£¬²¢½«Æä°²Åŵ½¼¯ÈºÖУº
$ docker service create --replicas 3 --network my-network --name my-service nginx
µÇ¼ºó¸´ÖÆ
¶þ¡¢Ê¹ÓÃKeepalivedʵÏÖ¹ÊÕÏÇл»
³ýÁËʹÓÃDocker Swarm£¬ÎÒÃÇ»¹¿ÉÒÔʹÓÃKeepalivedʵÏÖÈÝÆ÷ÍøÂçµÄ¹ÊÕÏÇл»¡£KeepalivedÊÇÒ»ÖÖÓÃÓڸ߿ÉÓÃÐÔµÄÈí¼þ£¬¿ÉÒÔÈ·±£Ö÷»úµÄ¿ÉÓÃÐÔ¡£ÒÔÏÂÊÇ°ì·¨£º
×°ÖÃKeepalived
ÔÚÿ¸ö½ÚµãÉÏ×°ÖÃKeepalived£¬²¢È·±£ÍøÂç½Ó¿ÚµÄÉèÖÃ׼ȷ¡£
ÉèÖÃKeepalived
ÔÚÿ¸ö½ÚµãÉϽ¨ÉèÒ»¸öKeepalivedµÄÉèÖÃÎļþ£¬Ê¾ÀýÈçÏ£¨ÎļþÃûΪkeepalived.conf£©£º
vrrp_script chk_docker { script "docker service ls | grep my-service" interval 5 } vrrp_instance VI_1 { interface eth0 state MASTER virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass my-password } virtual_ipaddress { 10.0.0.100 } track_script { chk_docker } }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬chk_dockerΪ¼ì²éDockerЧÀÍÊÇ·ñÕý³£ÔËÐеľ籾£¬my-serviceΪÎÒÃÇÐèÒª¼à¿ØµÄDockerЧÀÍ¡£
Æô¶¯Keepalived
ÔÚÿ¸ö½ÚµãÉÏÆô¶¯Keepalived£¬²¢È·±£ÆäÔÚÈÝÆ÷ÍøÂç¹ÊÕÏʱ¿ÉÒÔ·¢Ã÷²¢Çл»µ½ÁíÒ»¸ö½Úµã¡£
Èý¡¢Ê¹ÓÃNginx×÷Ϊ¸ºÔØƽºâÆ÷
³ýÁËʹÓÃDocker SwarmºÍKeepalived£¬ÎÒÃÇ»¹¿ÉÒÔʹÓÃNginx×÷ΪÈÝÆ÷ÍøÂçµÄ¸ºÔØƽºâÆ÷¡£ÒÔÏÂÊÇ°ì·¨£º
×°ÖÃNginx
ÔÚÿ¸ö½ÚµãÉÏ×°ÖÃNginx£¬²¢È·±£NginxµÄÉèÖÃÎļþ׼ȷ¡£
ÉèÖÃNginx
ÔÚNginxµÄÉèÖÃÎļþÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£¬ÓÃÓÚÊðÀíÇëÇóµ½ÈÝÆ÷µÄÕæʵµØµã£º
http { upstream my-service { server 10.0.0.1:80; server 10.0.0.2:80; server 10.0.0.3:80; } server { listen 80; location / { proxy_pass http://my-service; } } }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬my-serviceΪÎÒÃÇÐèÒªÊðÀíµÄDockerЧÀÍ¡£
Æô¶¯Nginx
ÔÚÿ¸ö½ÚµãÉÏÆô¶¯Nginx£¬²¢È·±£ÆäÄܹ»ÔÚÈÝÆ÷ÍøÂç¹ÊÕÏʱ×Ô¶¯Çл»µ½Ò»¸ö¿ÉÓõÄÈÝÆ÷½Úµã¡£
½áÂÛ£º
ͨ¹ýÒÔÉÏÒªÁ죬ÎÒÃÇ¿ÉÒÔÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂ磬ȷ±£ÈÝÆ÷ЧÀ͵ĿÉÓÃÐÔ¡£ÎÞÂÛÊÇʹÓÃDocker Swarm¡¢KeepalivedÕÕ¾ÉNginx£¬¶¼ÊÇÒ»ÖÖ¿ÉÐеĽâ¾ö¼Æ»®£¬¿ÉÒÔƾ֤ÏêϸÐèÇóÑ¡ÔñÊʺϵÄÒªÁì¡£ÔÚÏÖʵӦÓÃÖУ¬ÎÒÃÇ¿ÉÒÔƾ֤ÏÖÕæÏàÐξÙÐÐÉèÖú͵÷½â£¬ÒÔʵÏÖ×î¼ÑµÄ¸ß¿ÉÓÃÈÝÆ÷ÍøÂç¼Ü¹¹¡£
0 ÈËÔÞÐíÁ˸ÃÎÄÕÂ0 ÈË×èµ²Á˸ÃÎÄÕÂ
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂçµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡