블루-그린 배포를 위해 nginx 시뮬레이션을 사용하는 방법
블루-그린 배포
블루-그린 배포의 핵심은 다음과 같습니다
1. 블루 버전과 그린 버전이 동시에 존재합니다
2. 파란색 또는 녹색 중 하나만 가능하며 스위치로 제어됩니다.
장점과 단점 분석: 장점은 속도와 롤백에 있습니다. 그리고 단점도 분명합니다. 두 가지 환경 세트가 동시에 존재하기 때문에 빠른 롤백이 가능하며, 두 가지 환경 세트가 있기 때문에 복잡성과 소요 리소스가 증가하게 됩니다.
또한, 속도가 향상되었지만 구현 과정에서 스위치 제어는 스위칭 속도가 아무리 빠르더라도 다른 기술을 결합하지 않으면 여전히 완전히 원활한 스위칭을 달성할 수 없습니다.
청록색 배포 시뮬레이션
다음으로 nginx의 업스트림을 사용하여 청록색 배포 시나리오를 간단히 시뮬레이션합니다. 구체적인 시나리오는 다음과 같습니다. nginx 설정을 조정하면 파란색 버전이 현재 활성화된 버전으로 설정됩니다.
미리 준비하세요
시연의 편의를 위해 7001/7002 두 포트에서 두 서비스를 미리 시작하여 서로 다른 정보를 표시하도록 tornado를 사용하여 이미지를 만들고 도커 실행 시 전달된 매개변수를 전달했습니다. 컨테이너가 시작되었습니다. Different는 서비스 간의 차이점을 표시하는 데 사용됩니다.
docker run -d -p 7001:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello blue/green service: v1 in 7001" docker run -d -p 7002:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello blue/green service: v2 in 7002"
실행 로그
[root@kong ~]# docker run -d -p 7001:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello blue/green service: v1 in 7001" 70c74dc8e43d5635983f7240deb63a3fc0599d5474454c3bc5197aa5c0017348 [root@kong ~]# docker run -d -p 7002:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello blue/green service: v2 in 7002" 6c5c2ea322d4ac17b90feefb96e3194ec8adecedaa4c944419316a2e4bf07117 [root@kong ~]# curl http://192.168.163.117:7001 hello, service :hello blue/green service: v1 in 7001 [root@kong ~]# curl http://192.168.163.117:7002 hello, service :hello blue/green service: v2 in 7002 [root@kong ~]#
Start nginx
[root@kong ~]# docker run -p 9080:80 --name nginx-blue-green -d nginx d3b7098c44890c15918dc47616b67e5e0eb0da7a443eac266dbf26d55049216a [root@kong ~]# docker ps |grep nginx-blue-green d3b7098c4489 nginx "nginx -g 'daemon ..." 10 seconds ago up 9 seconds 0.0.0.0:9080->80/tcp nginx-blue-green [root@kong ~]#
nginx 코드 스니펫
다음 nginx 코드 스니펫을 준비하여 nginx의 /etc/nginx/conf.d/default.conf에 추가하고 시뮬레이션 방법은 매우 간단합니다. down을 사용하여 트래픽이 0임을 나타냅니다(nginx에서는 가중치를 0으로 설정할 수 없음). 처음에는 트래픽의 100%가 블루 버전으로 전송됩니다.
http { upstream nginx_blug_green { server 192.168.163.117:7001 weight=100; server 192.168.163.117:7002 down; } server { listen 80; server_name www.liumiao.cn 192.168.163.117; location / { proxy_pass http://nginx_blug_green; } }
default.conf 수정 방법
컨테이너에 vim을 설치하면 효과를 얻을 수 있고, 로컬에서 수정한 다음 docker cp를 통해 전달하거나 sed로 직접 수정할 수도 있습니다. 컨테이너에 vim을 설치하는 경우 다음 방법을 사용하세요
[root@kong ~]# docker exec -it nginx-lb sh # apt-get update ...省略 # apt-get install vim ...省略
수정 전
# cat default.conf server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the php scripts to apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param script_filename /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } #
수정 후
# cat default.conf upstream nginx_blug_green { server 192.168.163.117:7001 weight=100; server 192.168.163.117:7002 down; } server { listen 80; server_name www.liumiao.cn 192.168.163.117; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { #root /usr/share/nginx/html; #index index.html index.htm; proxy_pass http://nginx_blug_green; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the php scripts to apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param script_filename /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } #
nginx 설정 다시 로드
# nginx -s reload 2018/05/28 04:39:47 [notice] 321#321: signal process started #
결과 확인
10번 호출 후 모두 출력 All 7001의 v1입니다
블루-그린 배포: 그린 버전으로 전환[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]
> do
> let cnt++
> 안녕하세요, 서비스: /그린 서비스: 7001의 v1
hello, 서비스 :hello 블루/그린 서비스: 7001의 v1
hello, 서비스 :hello 블루/그린 서비스: 7001의 v1
hello, 서비스 :hello 블루/그린 서비스: 7001의 v1
hello, 서비스 :hello 블루/그린 서비스: 7001의 v1
hello, 서비스 :hello 블루/그린 서비스: 7001의 v1
hello, 서비스 :hello 블루/그린 서비스: 7001
hello, 서비스 :hello 블루/그린 서비스: v1 in 7001
hello, service :hello blue/green 서비스: v1 in 7001
hello, service :hello blue/green 서비스: v1 in 7001
[root@kong ~]#
default.conf의 가중치를 조정한 다음 nginx -s reload를 실행하면 nginx 서비스를 중지하지 않고도 그린 버전으로 동적으로 전환할 수 있습니다. 대상은 7002
에서 모든 트래픽을 출력합니다.
default.conf 수정 방법다음과 같이 업스트림에서 서버의 가중치를 조정하세요.
upstream nginx_blug_green { server 192.168.163.117:7001 down; server 192.168.163.117:7002 weight=100; }
[root @kong ~]# cnt= 0; while [ $cnt -lt 10 ]; do 컬 ; let cnt++; service :hello blue/green 서비스: 7002의 v2 hello, 서비스 :hello 블루/그린 서비스: 7002의 v2 위 내용은 블루-그린 배포를 위해 nginx 시뮬레이션을 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!# nginx -s reload
2018/05/28 05:01:28 [notice] 330#330: signal process started
#
hello, service :hello blue/green 서비스: 7002의 v2
hello, 서비스 :hello 블루/그린 서비스: 7002의 v2
hello, service :hello 블루/그린 서비스: 7002의 v2
hello, 서비스 : hello 블루/그린 서비스: v2 in 7002
hello, 서비스 :hello 블루/그린 서비스: 7002
hello, 서비스 :hello 블루/그린 서비스: 7002
hello, 서비스 :hello 블루/그린 서비스: 7002
hello, 서비스 :hello 블루/그린 서비스: v2 in 7002
[root@kong ~]#

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Nginx 403 금지 된 오류를 수정하는 방법은 무엇입니까? 파일 또는 디렉토리 권한을 확인합니다. 2. 확인 파일을 확인하십시오. 3. nginx 구성 파일 확인; 4. nginx를 다시 시작하십시오. 다른 가능한 원인으로는 방화벽 규칙, Selinux 설정 또는 응용 프로그램 문제가 있습니다.

질문에 대한 답변 : 304 수정되지 않은 오류는 브라우저가 클라이언트 요청의 최신 리소스 버전을 캐시했음을 나타냅니다. 솔루션 : 1. 브라우저 캐시를 지우십시오. 2. 브라우저 캐시를 비활성화합니다. 3. 클라이언트 캐시를 허용하도록 nginx를 구성합니다. 4. 파일 권한을 확인하십시오. 5. 파일 해시를 확인하십시오. 6. CDN 또는 리버스 프록시 캐시를 비활성화합니다. 7. nginx를 다시 시작하십시오.

Linux에서 Nginx를 시작하는 단계 : Nginx가 설치되어 있는지 확인하십시오. systemctl start nginx를 사용하여 nginx 서비스를 시작하십시오. SystemCTL을 사용하여 NGINX를 사용하여 시스템 시작시 NGINX의 자동 시작을 활성화하십시오. SystemCTL 상태 nginx를 사용하여 시작이 성공했는지 확인하십시오. 기본 환영 페이지를 보려면 웹 브라우저의 http : // localhost를 방문하십시오.

서버는 요청 된 리소스에 액세스 할 수있는 권한이 없으므로 Nginx 403 오류가 발생합니다. 솔루션에는 다음이 포함됩니다. 파일 권한 확인 권한을 확인하십시오. .htaccess 구성을 확인하십시오. nginx 구성을 확인하십시오. Selinux 권한을 구성하십시오. 방화벽 규칙을 확인하십시오. 브라우저 문제, 서버 장애 또는 기타 가능한 오류와 같은 다른 원인을 해결하십시오.

Nginx 크로스 도메인 문제를 해결하는 두 가지 방법이 있습니다. 크로스 도메인 응답 헤더 수정 : 교차 도메인 요청을 허용하고 허용 된 메소드 및 헤더를 지정하고 캐시 시간을 설정하는 지시문을 추가하십시오. CORS 모듈 사용 : 모듈을 활성화하고 CORS 규칙을 구성하여 크로스 도메인 요청, 메소드, 헤더 및 캐시 시간을 허용합니다.

nginx가 시작되었는지 확인하는 방법 : 1. 명령 줄을 사용하십시오 : SystemCTL 상태 nginx (linux/unix), netstat -ano | Findstr 80 (Windows); 2. 포트 80이 열려 있는지 확인하십시오. 3. 시스템 로그에서 nginx 시작 메시지를 확인하십시오. 4. Nagios, Zabbix 및 Icinga와 같은 타사 도구를 사용하십시오.

nginx의 실행 상태를 보는 방법은 다음과 같습니다. PS 명령을 사용하여 프로세스 상태를보십시오. nginx 구성 파일 /etc/nginx/nginx.conf를 봅니다. Nginx 상태 모듈을 사용하여 상태 끝점을 활성화하십시오. Prometheus, Zabbix 또는 Nagios와 같은 모니터링 도구를 사용하십시오.

오류 로그는/var/log/nginx (linux) 또는/usr/local/var/log/nginx (macOS)에 있습니다. 명령 줄을 사용하여 단계를 정리하십시오. 1. 원래 로그를 백업하십시오. 2. 빈 파일을 새 로그로 만듭니다. 3. Nginx 서비스를 다시 시작하십시오. 자동 청소는 Logrotate 또는 구성과 같은 타사 도구와 함께 사용할 수도 있습니다.
