NGINXã¯ãWebãµãŒããŒãšããŠã ãã§ãªãããªããŒã¹ãããã·ãµãŒããŒãããŒããã©ã³ãµãŒãHTTPãã£ãã·ã¥ãšããŠããäžçæ倧ã®ãµã€ãã®40ïŒ ä»¥äžã§äœ¿çšãããŠããŸãã å ¬åŒã®NGINXã€ã¡ãŒãžã¯340äžåããŠã³ããŒããããŠããŸãã
ãã®èšäºã§ã¯ã次ã®ããšãåŠç¿ããŸãã
- NGINXã§dockerã€ã¡ãŒãžãå±éããŠäœ¿çšããæ¹æ³ã
- ãªããŒã¹ãããã·ãNGINXããã³Dockerã®ããã€ãã®ãµã€ãã«ãã°ããå±éããæ¹æ³
- 3ã€ã®InfoboxCloudãªãŒãžã§ã³ã®ããããã«ãè€æ°ã®ãµã€ããšãªããŒã¹ãããã·ã§æ§æãããå°ççã«åæ£ããã€ã³ã¹ããŒã«ãå±éããæ¹æ³ã
Dockerã䜿çšããããšããªãå Žåã¯ã以äžãèªãããšããå§ãããŸãã
Dockerã䜿çšããŠããããã³ããŒããã¯ãå¿é ããŸããã
Dockerãžã®ãã€ãã³ã°ïŒDockerfileãšã³ã³ãããŒéä¿¡
1.0ãã1.8ãŸã§ã®Docker Engineã€ãããŒã·ã§ã³ã®æŠèŠã Docker Composeã®æŠèŠ
èšäºã®æåŸã«ã InfoboxCloudã®è©Šçšçãç¡æã§æäŸããŸãã
ç°å¢ã®æºå
1. CentOS 7ã§ãµãŒããŒãäœæããŠã DocboxãInfoboxCloudã«ã€ã³ã¹ããŒã«ããŸã ã Dockerãæ©èœããããã«ã¯ããŸãã«ä»å¿ èŠãªä»®æ³ãã·ã³ã§ãããã®ããããµãŒããŒãäœæãããšãã¯ã ãOSã«ãŒãã«å¶åŸ¡ãèš±å¯ãããããã¯ã¹ãå¿ ããã§ãã¯ããŠãã ããã
InfoboxCloud for Dockerã§ãµãŒããŒãäœæããæ¹æ³
InfoboxCloudã«ãŸã ã¢ã¯ã»ã¹ã§ããªãå Žåã¯ã 泚æããŠãã ãã ã
ç»é²åŸãé»åã¡ãŒã«ã§ã³ã³ãããŒã«ããã«ã«ã¢ã¯ã»ã¹ããããã®ããŒã¿ãåãåããŸãã https://panel.infobox.ruã§ã³ã³ãããŒã«ããã«ã«ãã°ã€ã³ããŸãã
ãµãã¹ã¯ãªãã·ã§ã³ã®[ã¯ã©ãŠãã€ã³ãã©ã¹ãã©ã¯ãã£]ã»ã¯ã·ã§ã³ã§ã[æ°ãããµãŒããŒ]ãã¯ãªãã¯ããŸãïŒå¿ èŠã«å¿ããŠãããããããŠã³ã¡ãã¥ãŒã®å³äžé ã«ãããµãã¹ã¯ãªãã·ã§ã³ãå€æŽãããŸãïŒã
å¿ èŠãªãµãŒããŒãã©ã¡ãŒã¿ãèšå®ããŸãã äžã®ã¹ã¯ãªãŒã³ã·ã§ããã«ç€ºãããã«ããµãŒããŒã«1ã€ã®ãããªãã¯IPã¢ãã¬ã¹ãäžãã ãOSã«ãŒãã«å¶åŸ¡ãèš±å¯ãããããã¯ã¹ããã§ãã¯ããŠãã ããã
䜿çšå¯èœãªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ãªã¹ãã§ãCentOS 7ãéžæãããµãŒããŒã®äœæãå®äºããŸãã
ãã®åŸããµãŒããŒã«ã¢ã¯ã»ã¹ããããã®ããŒã¿ãé»åã¡ãŒã«ã§éä¿¡ãããŸãã
ç»é²åŸãé»åã¡ãŒã«ã§ã³ã³ãããŒã«ããã«ã«ã¢ã¯ã»ã¹ããããã®ããŒã¿ãåãåããŸãã https://panel.infobox.ruã§ã³ã³ãããŒã«ããã«ã«ãã°ã€ã³ããŸãã
ãµãã¹ã¯ãªãã·ã§ã³ã®[ã¯ã©ãŠãã€ã³ãã©ã¹ãã©ã¯ãã£]ã»ã¯ã·ã§ã³ã§ã[æ°ãããµãŒããŒ]ãã¯ãªãã¯ããŸãïŒå¿ èŠã«å¿ããŠãããããããŠã³ã¡ãã¥ãŒã®å³äžé ã«ãããµãã¹ã¯ãªãã·ã§ã³ãå€æŽãããŸãïŒã
å¿ èŠãªãµãŒããŒãã©ã¡ãŒã¿ãèšå®ããŸãã äžã®ã¹ã¯ãªãŒã³ã·ã§ããã«ç€ºãããã«ããµãŒããŒã«1ã€ã®ãããªãã¯IPã¢ãã¬ã¹ãäžãã ãOSã«ãŒãã«å¶åŸ¡ãèš±å¯ãããããã¯ã¹ããã§ãã¯ããŠãã ããã
䜿çšå¯èœãªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ãªã¹ãã§ãCentOS 7ãéžæãããµãŒããŒã®äœæãå®äºããŸãã
ãã®åŸããµãŒããŒã«ã¢ã¯ã»ã¹ããããã®ããŒã¿ãé»åã¡ãŒã«ã§éä¿¡ãããŸãã
CentOS 7ã§ãµãŒããŒãäœæããåŸã SSHãä»ããŠãµãŒããŒã«æ¥ç¶ããŸãã
ãã®ãããªãµãŒããŒã§DockerãšDockerãæäœããããã®äŸ¿å©ãªãŠãŒãã£ãªãã£ãã€ã³ã¹ããŒã«ã§ããã¹ã¯ãªãããæºåããŸããã å¿ èŠãªèšå®ã¯èªåçã«è¡ãããŸãã
ã³ãã³ããå®è¡ããŠDockerããã³Composeãã€ã³ã¹ããŒã«ããŸãã
bash <(curl -s http://repository.sandbox.infoboxcloud.ru/scripts/docker/centos7/install.sh)
ãã®åŸãdockerããã³composeãã€ã³ã¹ããŒã«ãããŸãã ãµãŒããŒãã¯ãªãã¯ããŠãã€ã¡ãŒãžãäœæããã¯ãªãã¯ãããšãã³ã³ãããŒã«ããã«ã« dockerãã€ã³ã¹ããŒã«ãããã€ã¡ãŒãžãäœæã§ããŸãã
ãã®åŸãDockerã䜿çšããŠã€ã¡ãŒãžããæ°ãããµãŒããŒãäœæãããã®ã¹ããããå床å®è¡ããªãã§ãã ããã
ããŒã¿ãã«ç°å¢ã®äœæ
ç§ãã¡ã®ããŒã¿ãã«ç°å¢ã¯ä»¥äžã§æ§æãããŠããŸãïŒ
- Dockerfile-ã³ã³ãããŒãæ§ç¯ããããã»ã¹ãèšè¿°ãããã¡ã€ã«
- docker-compose.yml-ã³ã³ãããŒãŸãã¯ã³ã³ãããŒã®ã»ãããèµ·åããããã»ã¹ãèšè¿°ãããã¡ã€ã«
- htmlãã£ã¬ã¯ããªå ã®ãµã€ããã¡ã€ã«
- confãã£ã¬ã¯ããªã®nginxèšå®ãã¡ã€ã«
ãµã€ããã¡ã€ã«ãŸãã¯æ§æãæŽæ°ãããšãã«ã³ã³ãããŒãåæ§ç¯ããã«ã¯ãããŒã¿ãã«ç°å¢ãgithubãªã©ã®ãªããžããªã«ä¿æããããšããå§ãããŸãã ããã«ãããå¿ èŠã«å¿ããŠãã«ã¹ã¿ãã€ãºãããµã€ããæ°åã§åå±éã§ããŸãã ãŸããéçºçšã«å¥ã®ã³ã³ããã§ãµã€ãããã°ããäžããããšãã§ããŸãã
gitã䜿çšããã«ã¯ããµãŒããŒã«gitãã€ã³ã¹ããŒã«ããŠãã ããã
yum install -y git
次ã®ã³ãã³ãã䜿çšããŠãgithubããã·ã³ãã«ãªããŒã¿ãã«ç°å¢ãã³ããŒããŸãã
git clone https://github.com/InfoboxHosting/DockerNginxSimpleStaticSite.git
次ã®ã³ãã³ãã䜿çšããŠãç°å¢ãã£ã¬ã¯ããªã«ç§»åããŸãã
cd DockerNginxSimpleStaticSite/
ã³ãã³ãã䜿çšããŠDockerã€ã¡ãŒãžãæ§ç¯ãã
docker-compose build
ã³ãã³ãã§ç»åãã³ã³ããã«å±éããŸã
docker-compose up -d
IPã§ãµãŒããŒã«ã¢ã¯ã»ã¹ããŠã¿ãŠãã ããã äºåæ§æãããéçãµã€ããæ£åžžã«ãããã€ãããŸããã
å®è¡ããå Žå
ã³ã³ããã®ãªã¹ãã§ãµã€ãã確èªã§ããŸããdocker ps
ããŒã¿ãã«ç°å¢ã®æ§æãèŠãŠã¿ãŸãããã
conf / nginx.confãã¡ã€ã«ã«ã¯ãnginxèšå®ãå«ãŸããŠããŸãã
nginx.conf
user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 4086; use epoll; multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; keepalive_requests 1000; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { listen 80; server_name domain.tld www.domain.tld; location / { root /usr/share/nginx/html; } } }
domain.tldããµã€ãã®ãã¡ã€ã³ã«çœ®ãæããå¿ èŠããããŸãã
ãµã€ãã®WebãµãŒããŒèšå®ã¯ããŒã¿ãã«ç°å¢ã«ä¿åããããããå±éäžã«æ¯åWebãµãŒããŒãåèšå®ããå¿ èŠã¯ãããŸããã
ããŒã¿ãã«ç°å¢ã®ã«ãŒãã«ã¯ãå ¬åŒã®NGINXã€ã¡ãŒãžã䜿çšãã htmlãã©ã«ããŒããWebãµã€ããè¿œå ãã confãã©ã«ããŒããNGINXæ§æãè¿œå ããDockerfileããããŸãã
FROM nginx MAINTAINER Yuri Trukhin "trukhinyuri@infoboxcloud.com" COPY conf/nginx.conf /etc/nginx/nginx.conf COPY html/ /usr/share/nginx/html
ãã®èšäºã§ Dockerfileã®è©³çŽ°ãåŠãã§ãã ããã
ãŸããããŒã¿ãã«ç°å¢ãã©ã«ããŒã®ã«ãŒãã§ã次ã®å 容ã®docker-compose.ymlãã¡ã€ã«ãäœæããŸã ã
sitename: build: . ports: - 80:80 restart: always
åããã£ã¬ã¯ããªã«ããDockerfileããæåã«ãµã€ãåç°å¢ãæ§ç¯ããããšã«ããã ãµã€ãåç°å¢ãå±éããå¿ èŠããããšæžãããŠããŸãã ã³ã³ããã®ããŒã80ã¯ããã¹ãã®ããŒã80ã«è»¢éããå¿ èŠããããŸãã NGINXãã¯ã©ãã·ã¥ããå Žåã¯ãåèµ·åããŠãã ããã
ãã®èšäºã§ Composeã®è©³çŽ°ãåŠãã§ãã ããã
ãµã€ããŸãã¯nginxèšå®ãã¡ã€ã«ãå€æŽããå Žå-ã³ãã³ãã§ã€ã¡ãŒãžãåæ§ç¯ããã ãã§ã
docker-compose build
ãããŠãç»åãã³ã³ããã«å±éããŸãïŒ
docker-compose up -d
ãµãŒããŒãæ¯åèšå®ããããšãå¿é ããå¿ èŠã¯ãããŸããã ãã€ãŠéçºãããDockerã䜿çšããããŒã¿ãã«ç°å¢ã«ãããè¿ éã«ãããã€ã§ããŸãã
次ã®ã»ã¯ã·ã§ã³ã®æšå¥šäºé ã«åŸãã«ã¯ã次ã®ããã«ãããã€ãããã³ã³ãããåæ¢ããŠåé€ããŸãã ãã¹ãã®ããŒã80ãå æããŸããããã¯å¿ èŠã§ãã
ãããè¡ãã«ã¯ã次ãå®è¡ããŸãã
docker ps
container_idãã¯ãªããããŒãã«ã³ããŒããŸãã
次ã®ã³ãã³ãã§ã³ã³ãããåæ¢ããŸãïŒ
docker stop bc88ee61a933
bc88ee61a933ã®ä»£ããã«container_idãæ¿å ¥ããŸãã
ã³ã³ãããåé€ïŒ
docker rm bc88ee61a933
bc88ee61a933ã®ä»£ããã«container_idãæ¿å ¥ããŸãã
ãªããŒã¹ãããã·ã䜿çšããŠè€æ°ã®ãµã€ããå±éããŸã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãç°ãªããã¡ã€ã³ãšãªããŒã¹ãããã·ãæã€ããã€ãã®éçãµã€ããå±éããŸãã èšäºã®ãã®éšåãå®äºããã«ã¯ããã¡ã€ã³ãDNSã®ãµãŒããŒã®IPã¢ãã¬ã¹ã«ãªãã€ã¬ã¯ãããå¿ èŠããããŸãã
- domain1.tld Aã¬ã³ãŒãã¯ããµãŒããŒã®å°çšãããªãã¯IPã¢ãã¬ã¹ã«éä¿¡ããå¿ èŠããããŸãã domain1.tld-æåã®ãµã€ãã®ãã¡ã€ã³ã
- domain2.tld Aã¬ã³ãŒãã¯ããµãŒããŒã®å°çšãããªãã¯IPã¢ãã¬ã¹ã«éä¿¡ããå¿ èŠããããŸãã domain2.tld-2çªç®ã®ãµã€ãã®ãã¡ã€ã³ã
å¿ èŠãªIPã¢ãã¬ã¹ã¯ã InfoboxCloud ã³ã³ãããŒã«ããã«ã«ãããŸãã
ãã¡ã€ã³ããªãå Žåã®å¯ŸåŠæ¹æ³
ãã®ãªãã·ã§ã³ã¯ãã¹ãã«æé©ã§ãããã³ã³ãã¥ãŒã¿ãŒããã®ã¿æ©èœããŸãã
ãã¡ã€ã³ã¬ã³ãŒããã³ã³ãã¥ãŒã¿ãŒã®ãã¹ããã¡ã€ã«ã«è¿œå ããŸã ã
OS Xããã³Linuxã§ã¯ããšã³ããªã/ etc / hostsãã¡ã€ã«ã«è¿œå ã§ããŸã ã
Windowsã§ã¯ã管çè ãšããŠã¡ã¢åž³ãå®è¡ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãæ€çŽ¢ãã£ãŒã«ãã«ã¡ã¢åž³ãŸãã¯ã¡ã¢åž³ïŒãã·ã¢èªçã®WindowsïŒãå ¥åãã管çè ãšããŠèµ·åãã€ã³ããéžæããŸãã
ãã¡ã€ã«CïŒ\ Windows \ System32 \ drivers \ etc \ hostsãéããŸã ã ããŒãããã¯ã«è¡šç€ºãããªãå Žåã¯ããéãããã¿ã³ã®æšªã«ããããã¹ãŠã®ãã¡ã€ã«ããã¡ã€ã«ã¿ã€ããéžæããŸãã
å¿ èŠãªãšã³ããªãè¿œå ããŠãå€æŽãä¿åããŸãã ã³ã³ãããŒã«ããã«ãããµãŒããŒã®ã¢ãã¬ã¹ãIPã¢ãã¬ã¹ãšããŠäœ¿çšããããšãå¿ããªãã§ãã ããã
ãã¹ãåŸããããã®ãšã³ããªããã¹ããã¡ã€ã«ããåé€ããŠãã ããã
ããšãã°ã ããã§å®è¡ã§ããŸã ã
ãªãã·ã§ã³1.ãã¹ãã®æ§æ
ãã®ãªãã·ã§ã³ã¯ãã¹ãã«æé©ã§ãããã³ã³ãã¥ãŒã¿ãŒããã®ã¿æ©èœããŸãã
ãã¡ã€ã³ã¬ã³ãŒããã³ã³ãã¥ãŒã¿ãŒã®ãã¹ããã¡ã€ã«ã«è¿œå ããŸã ã
OS Xããã³Linuxã§ã¯ããšã³ããªã/ etc / hostsãã¡ã€ã«ã«è¿œå ã§ããŸã ã
Windowsã§ã¯ã管çè ãšããŠã¡ã¢åž³ãå®è¡ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãæ€çŽ¢ãã£ãŒã«ãã«ã¡ã¢åž³ãŸãã¯ã¡ã¢åž³ïŒãã·ã¢èªçã®WindowsïŒãå ¥åãã管çè ãšããŠèµ·åãã€ã³ããéžæããŸãã
ãã¡ã€ã«CïŒ\ Windows \ System32 \ drivers \ etc \ hostsãéããŸã ã ããŒãããã¯ã«è¡šç€ºãããªãå Žåã¯ããéãããã¿ã³ã®æšªã«ããããã¹ãŠã®ãã¡ã€ã«ããã¡ã€ã«ã¿ã€ããéžæããŸãã
å¿ èŠãªãšã³ããªãè¿œå ããŠãå€æŽãä¿åããŸãã ã³ã³ãããŒã«ããã«ãããµãŒããŒã®ã¢ãã¬ã¹ãIPã¢ãã¬ã¹ãšããŠäœ¿çšããããšãå¿ããªãã§ãã ããã
ãã¹ãåŸããããã®ãšã³ããªããã¹ããã¡ã€ã«ããåé€ããŠãã ããã
ãªãã·ã§ã³2.å¿ èŠãªãã¡ã€ã³ãè³Œå ¥ãã
ããšãã°ã ããã§å®è¡ã§ããŸã ã
次ã«ãInfoboxCloudã§Dockerã䜿çšããŠSSHçµç±ã§ãµãŒããŒã«æ¥ç¶ããŸãã
ããŒããã©ã³ãµãŒã䜿çšããŠã2ã€ã®ãµã€ãã®æºåæžã¿ãªããžããªãè€è£œããŸãã
cd ~
git clone https://github.com/InfoboxHosting/DockerNginxSimpleBalancer.git
ãã©ã³ãµãŒã®ããŒã¿ãã«ç°å¢ã®ãã£ã¬ã¯ããªã«ç§»åããŸãã
cd ~/DockerNginxSimpleBalancer/balancer
1ã€ã®ã³ãã³ãã§ãã©ã³ãµãŒãšäŸåã€ã¡ãŒãžã®æ§ç¯ãéå§ããŸãã
docker-compose build
ãã©ã³ãµãŒãšäŸåç»åãå±éããŸãã
docker-compose up -d
泚ïŒãã®äŸã§ã¯ãåããã³ããšã³ãã®ãã©ã«ããŒå ã®docker-compose.ymlãã¡ã€ã«ã¯äœ¿çšãããŸããã
ãã©ãŠã¶ã§æåã®ãµã€ãã®ãã¡ã€ã³ãéããŸãã
次ã«ã2çªç®ã®ãµã€ããæ£ããéãããšã確èªããŸãã
/ etc / hostsã®æå®ã®domain1.comããã³domain2.comã§ãµã€ããéããªãããã«ããã«ã¯ããã¡ã€ã«ã/ DockerNginxSimpleBalancer / balancer / conf / nginx.confãä¿®æ£ããå¿ èŠããããŸãã
nginx.conf
user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 4086; use epoll; multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; keepalive_requests 1000; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { listen 80; server_name domain1.com www.domain1.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend1:80; } } server { listen 80; server_name domain2.com www.domain2.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend2:80; } } }
domain1.comãšdomain2.comããµã€ãã®ã¢ãã¬ã¹ã«çœ®ãæããã€ã¡ãŒãžãåæ§ç¯ããŠãã³ã³ãããŒãåãããã€ããŸãã
cd ~/DockerNginxSimpleBalancer/balancer
docker-compose build
docker-compose up -d
è€æ°ã®å°ççã«åæ£ãããµã€ããå±éããŸã
ãç°å¢ã®æºåãã»ã¯ã·ã§ã³ã«ç€ºãããã«ãã¢ã¹ã¯ã¯ããµã³ã¯ãããã«ãã«ã¯ãã¢ã ã¹ãã«ãã ã®åInfoboxCloudãªãŒãžã§ã³ã«dockerã䜿çšããŠãµãŒããŒãäœæãã次ã®ã³ãã³ãã§gitãã€ã³ã¹ããŒã«ããŸãã
yum install -y git
è¿œå ã®ã¯ã©ãŠããªãŒãžã§ã³ãæ¥ç¶ããæ¹æ³
ã³ã³ãããŒã«ããã«ã§ ãã¡ã€ã³ããŒãžã«ç§»åãã[æ°ãããµãŒãã¹ã泚æ]ãã¯ãªãã¯ããŸãã
Cloud ServersãµãŒãã¹ãéžæããŸãã
ç®çã®å°åãéžæãã泚æããã»ã¹ãæåŸãŸã§å®äºããŸãã
è¿œå ã®å°åã®æ¥ç¶ã¯ç¡æã§ãããã¢ã«ãŠã³ãã«ã¯500ã«ãŒãã«ä»¥äžãå¿ èŠã§ãã
Cloud ServersãµãŒãã¹ãéžæããŸãã
ç®çã®å°åãéžæãã泚æããã»ã¹ãæåŸãŸã§å®äºããŸãã
è¿œå ã®å°åã®æ¥ç¶ã¯ç¡æã§ãããã¢ã«ãŠã³ãã«ã¯500ã«ãŒãã«ä»¥äžãå¿ èŠã§ãã
ããããããŠã³ã¡ãã¥ãŒã®ã³ã³ãããŒã«ããã«ã®å³äžé ã§ãªãŒãžã§ã³ãåãæ¿ããããšãã§ããŸãã
èšäºã®ãã®éšåãå®äºããã«ã¯ããã¡ã€ã³ãDNSã®ãµãŒããŒã®IPã¢ãã¬ã¹ã«ãªãã€ã¬ã¯ãããå¿ èŠããããŸãã
- 3æåã®ãµã€ãã®ãã¡ã€ã³ã®ã¬ã³ãŒã ãåã¬ã³ãŒã㯠ãããããã¢ã¹ã¯ã¯ãã¢ã ã¹ãã«ãã ããµã³ã¯ãããã«ãã«ã¯ã®ãµãŒããŒãæããŸãã
- 3 2çªç®ã®ãµã€ãã®ãã¡ã€ã³ã®ã¬ã³ãŒã㯠ãããããã¢ã¹ã¯ã¯ãã¢ã ã¹ãã«ãã ããµã³ã¯ãããã«ãã«ã¯ã®ãµãŒããŒãæããŸãã
- ã¿ã€ãspbã®ã¬ã³ãŒãAã ãµã³ã¯ãããã«ãã«ã¯ã®ãµãŒããŒãæã domain.comã 代ããã«ãdomain.comã§ãµãŒãã¹ãã¡ã€ã³ã䜿çšããå¿ èŠããããŸãã
- ã¿ã€ãmskã®ã¬ã³ãŒãã domain.com ã¯ã¢ã¹ã¯ã¯ã®ãµãŒããŒãæããŸã ã 代ããã«ãdomain.comã§ãµãŒãã¹ãã¡ã€ã³ã䜿çšããå¿ èŠããããŸãã
- ã¿ã€ãamsã®ã¬ã³ãŒãã domain.com ã¯ãã¢ã ã¹ãã«ãã ã®ãµãŒããŒãæããŸã ã 代ããã«ãdomain.comã§ãµãŒãã¹ãã¡ã€ã³ã䜿çšããå¿ èŠããããŸãã
å¿ èŠãªIPã¢ãã¬ã¹ã¯ã InfoboxCloud ã³ã³ãããŒã«ããã«ã«ãããŸãã
æºåãããããŒã¿ãã«ç°å¢ãåãµãŒããŒã«ä¿åããŸãã
git clone https://github.com/InfoboxHosting/DockerNginxGeoRedundantBalancer.git
åãµãŒããŒã§ããã¡ã€ã«ã/ DockerNginxGeoRedundantBalancer / balancer / conf / nginx.confãç·šéãã domain1.comãæåã®ãµã€ãã®ãã¡ã€ã³åã«ã domain2.comã2çªç®ã®ãµã€ãã®ãã¡ã€ã³åã«ã domain.comããµãŒãã¹ãã¡ã€ã³ã®ååã«çœ®ãæããŸãã
æåã§ååãå€æŽãã代ããã«ã åãµãŒããŒã§ã³ãã³ããå®è¡ã§ããŸã ã
bash ~/DockerNginxGeoRedundantBalancer/rename.sh domain.com domain1.com domain2.com
ããã§ãdomain.comã®ä»£ããã«domain1.com-æåã®ãµã€ãã®ååãdomain2.com-2çªç®ã®ãµã€ãã®ååã®ä»£ããã«ãµãŒãã¹ãã¡ã€ã³ã®ååãæå®ããŸãã
ãªãªãžãã«ã®nginx.conf
user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 4086; use epoll; multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; keepalive_requests 1000; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; upstream frontend1 { #!!!replace domain.com #!!!remove backup word in your location server spb.domain.com:8000 backup; server msk.domain.com:8000 backup; server ams.domain.com:8000 backup; } upstream frontend2 { #!!!replace domain.com #!!!remove backup word in your location server spb.domain.com:8001 backup; server msk.domain.com:8001 backup; server ams.domain.com:8001 backup; } server { listen 80; #!!!replace domain1.com server_name domain1.com www.domain1.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend1; } } server { listen 80; #!!!replace domain2.com server_name domain2.com www.domain2.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend2; } } }
ã¢ã ã¹ãã«ãã ã«å€æŽãå ããåŸã®nginx.conf
user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 4086; use epoll; multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; keepalive_requests 1000; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; upstream frontend1 { #!!!replace domain.com server spb.plugndo.com:8000 backup; server msk.plugndo.com:8000 backup; server ams.plugndo.com:8000; } upstream frontend2 { #!!!replace domain.com server spb.plugndo.com:8001 backup; server msk.plugndo.com:8001 backup; server ams.plugndo.com:8001; } server { listen 80; #!!!replace domain1.com server_name site1.plugndo.com www.site1.plugndo.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend1; } } server { listen 80; #!!!replace domain1.com server_name site2.plugndo.com www.site2.plugndo.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend2; } } }
ãµã³ã¯ãããã«ãã«ã¯ã®å€æŽãè¡ã£ãåŸã®nginx.conf
user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 4086; use epoll; multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; keepalive_requests 1000; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; upstream frontend1 { #!!!replace domain.com server spb.plugndo.com:8000; server msk.plugndo.com:8000 backup; server ams.plugndo.com:8000 backup; } upstream frontend2 { #!!!replace domain.com server spb.plugndo.com:8001; server msk.plugndo.com:8001 backup; server ams.plugndo.com:8001 backup; } server { listen 80; #!!!replace domain1.com server_name site1.plugndo.com www.site1.plugndo.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend1; } } server { listen 80; #!!!replace domain1.com server_name site2.plugndo.com www.site2.plugndo.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend2; } } }
ã¢ã¹ã¯ã¯ã«å€æŽãå ããåŸã®nginx.conf
user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 4086; use epoll; multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; keepalive_requests 1000; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; upstream frontend1 { #!!!replace domain.com server spb.plugndo.com:8000 backup; server msk.plugndo.com:8000; server ams.plugndo.com:8000 backup; } upstream frontend2 { #!!!replace domain.com server spb.plugndo.com:8001 backup; server msk.plugndo.com:8001; server ams.plugndo.com:8001 backup; } server { listen 80; #!!!replace domain1.com server_name site1.plugndo.com www.site1.plugndo.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend1; } } server { listen 80; #!!!replace domain1.com server_name site2.plugndo.com www.site2.plugndo.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://frontend2; } } }
ã¢ã¹ã¯ã¯ã®å Žåãé©åãªãã©ã«ããŒã«è»¢éããŸãã
cd DockerNginxGeoRedundantBalancer/balancerMSK/
ã¢ã ã¹ãã«ãã ã®å Žåãé©åãªãã©ã«ããŒã«è»¢éããŸãã
cd DockerNginxGeoRedundantBalancer/balancerAMS/
ãµã³ã¯ãããã«ãã«ã¯ã®å ŽåïŒ
cd DockerNginxGeoRedundantBalancer/balancerSPB/
åãµãŒããŒã§ã³ãã³ããå®è¡ãã
docker-compose build
ãããŠ
docker-compose up -d
ããã§ãåãµã€ãã«ã¢ã¯ã»ã¹ããŠããã®å¯çšæ§ã確èªã§ããŸãã
次ã«ãã³ã³ãããŒã«ããã«ãããããããã®å°åã§ãµãŒããŒã®é»æºãåããŸãã ãµã€ãã¯åŒãç¶ãå©çšå¯èœã§ãã
2çªç®ã®å°åã®ãµãŒããŒã®é»æºãåããŸãã ãµã€ãã¯åŒãç¶ãå©çšå¯èœã§ãã
å°ãªããšã1ã€ã®ãµãŒããŒãå©çšå¯èœã§ããããµã€ãã¯æ©èœããŸãã ãªãã«ãªã£ãŠãããµãŒããŒã«èŠæ±ãå±ããå Žåãææ°ã®ãã©ãŠã¶ãŒã¯ãã¹ãŠDNSããå¥ã®ãµãŒããŒã«èŠæ±ãéä¿¡ããããšããŸãã ãã®çµæãæ°ç§åŸã«ãµã€ããéããŸãã
è€æ°ã®å°åã§ãµãŒããŒãšãµã€ããå±éããããã»ã¹ãå®å šã«èªååããã«ã¯ãAnsibleã䜿çšã§ããŸãã
ããŒã1
ããŒã2
ããŒã3
ããŒã4
ããŒã5
InfoboxCloudã®è©Šçšçãç¡æã§å ¥æããæ¹æ³ã¯ïŒ
trukhinyuri@infoboxcloud.comã«ã¡ãŒã«ã¢ãã¬ã¹ãšæ°åããéããã ãããã³ã³ãããŒã«ããã«ã«ã¢ã¯ã»ã¹ããããã®ããŒã¿ãåãåããŸãã æ°ããã¯ã©ãŠããªãŒãžã§ã³ã15æ¥éãã¹ãããŠããããã«ããŒãžã§ã³ã®ã¯ã©ãŠãã«ç§»åã§ããŸãã 2015幎9æ5æ¥ãŸã§ã«ç¡æè©Šçšçããªã¯ãšã¹ãã§ããŸãã
質åãã³ã¡ã³ãããããŸãããã ç§ãã¡ã«æžããŠãã ãããç§ãã¡ã¯åãã§çããŸãã
Habréã«ã³ã¡ã³ããæ®ãããšãã§ããªãå Žåã¯ã ã³ãã¥ããã£ã§ç§ãã¡ã«æçŽãæžããŠãã ããã
InfoboxCloudã§ã®NGINXãšDockerã®äœ¿çšã®æåïŒ