이 글에서는 주로 nginx 애플리케이션을 소개합니다. nginx를 카나리아 퍼블리싱에 사용하는 것은 특정 참고 가치가 있습니다. 이제 필요한 친구들이 참고할 수 있도록 공유하겠습니다.
이 글에서는 blue-green 배포 및 nginx 사용 방법을 소개합니다. 가장 간단한 방법으로 카나리아 릴리스를 시뮬레이션하세요
카나리아 릴리스/그레이스케일 릴리스
카나리아 릴리스의 핵심은 시행착오입니다. 카나리아방출의 기원 자체는 인간의 산업 발전 과정에서 자연의 아름다운 생명체들이 겪는 비극적인 이야기이다. 카나리아는 광부의 안전을 위해 목숨을 걸고 실수를 저지릅니다. 전반적인 보안을 위해 약간의 비용이 사용됩니다. 지속적인 배포를 실행하는 경우 카나리아는 1% 또는 10분의 1과 같은 아주 적은 양의 트래픽을 사용하여 특정 버전이 정상인지 확인합니다. 비정상적인 경우에는 최저 비용으로 기능을 달성하고 위험이 줄어듭니다. 정상이라면 100%에 도달할 때까지 점차적으로 가중치를 늘려가며 모든 트래픽을 새 버전으로 원활하게 전환할 수 있습니다. 그레이스케일 출판은 일반적으로 비슷한 개념입니다. 회색은 검정색과 흰색 사이의 전환입니다. 파란색 또는 녹색인 파란색 및 녹색 배포와는 다릅니다. 그레이스케일 릴리스/카나리아 릴리스는 두 가지가 동시에 존재하는 기간을 가지지만 둘의 해당 트래픽은 카나리아 릴리스가 그레이스케일 릴리스와 다른 경우에는 그 목적에 차이가 있어야 합니다. 카나리아 릴리스의 목적은 시행착오인 반면, 그레이스케일 릴리스는 안정적인 릴리스에 관한 것이지만 카나리아 릴리스에서는 문제가 없습니다. 그레이스케일 출판 상황에서의 전환.
카나리아 릴리스 시뮬레이션
다음으로 nginx의 업스트림을 사용하여 카나리아 릴리스 시나리오를 간단히 시뮬레이션합니다. 구체적인 시나리오는 다음과 같습니다. 현재 메인 버전이 활성화되어 있으며, nginx 설정을 조정하고 카나리아 버전의 가중치를 지속적으로 조정함으로써 최종적으로 원활한 출시가 이루어졌습니다. http : // localhost : 8090
Canary 버전 | |
---|---|
미리 준비하세요 | |
실행 로그 | Start nginx |
다음 nginx 코드 스니펫을 준비하여 nginx의 /etc/nginx/conf.d/default.conf에 추가합니다. 시뮬레이션 방법은 매우 간단합니다. through down 트래픽이 0임을 나타내기 위해(nginx에서는 가중치를 0으로 설정할 수 없음) 처음에는 트래픽의 100%가 기본 버전으로 전송됩니다. | default.conf 수정 방법 |
# cat default.confserver {
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.confupstream nginx_canary { 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_canary; } #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 reload2018/05/28 05:16:20 [notice] 319#319: signal process started#
결과 확인10번 호출 후의 모든 출력은 v1 in 7001[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl http://localhost:9080; let cnt++; doneHello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello main service: v1 in 7001[root@kong ~]#
Canary Release : 카나리아 버전의 트래픽 가중치는 10%입니다default.conf의 가중치를 조정한 후 nginx -s reload를 실행하여 카나리아 버전의 가중치를 10%로 조정하면 10%의 트래픽이 실행됩니다. New servicedefault.conf 수정 방법다음과 같이 업스트림에서 서버의 가중치만 조정하면 됩니다.upstream nginx_canary { server 192.168.163.117:7001 weight=10; server 192.168.163.117:7002 weight=90;
}
nginx 설정 다시 로드# nginx -s reload2018/05/28 05:20:14 [notice] 330#330: signal process started#
결과 확인[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl http://localhost:9080; let cnt++; doneHello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002[root@kong ~]#
Canary 릴리스: Canary 버전 트래픽 가중치는 50입니다. %default.conf의 가중치를 조정한 다음 nginx -s reload를 실행하여 카나리아 버전의 가중치를 50%로 조정합니다. 트래픽의 50%가 새 서비스를 실행합니다default.conf 메소드를 만 수정하세요. upstream nginx_canary { server 192.168.163.117:7001 weight=50; server 192.168.163.117:7002 weight=50; }nginx 설정 다시 로드
# nginx -s reload2018/05/28 05:22:26 [notice] 339#339: signal process started#
결과 확인 [root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl http://localhost:9080; let cnt++; doneHello, Service :Hello main service: v1 in 7001Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello canary deploy service: v2 in 7002[root@kong ~]#카나리아 릴리스: 카나리아 버전 트래픽 가중치는 90% 조정에 따라 기본 가중치입니다. 그런 다음 nginx -s reload를 실행하고 카나리아 버전의 가중치를 90%로 조정하면 트래픽의 90%가 새 서비스를 실행하게 됩니다default.conf를 수정하는 방법업스트림만 변경하면 됩니다. 서버의 가중치는 다음과 같이 조정됩니다.
upstream nginx_canary { server 192.168.163.117:7001 weight=10; server 192.168.163.117:7002 weight=90; }Reload nginx settings
# nginx -s reload2018/05/28 05:24:29 [notice] 346#346: signal process started#
결과 확인[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl http://localhost:9080; let cnt++; doneHello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello main service: v1 in 7001Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002[root@kong ~]#Canary 릴리스: Canary 버전 트래픽 가중치 100%default.conf의 가중치를 조정한 후 nginx -s reload를 실행합니다. 메서드에서 카나리아 버전의 가중치를 100%로 조정하면 트래픽의 100%가 새 서비스를 실행합니다default.conf 수정 방법다음과 같이 업스트림에서 서버의 가중치만 조정하면 됩니다.
<p style="margin-bottom: 7px; margin-top: 14px;">upstream nginx_canary { server 192.168.163.117:7001 down; server 192.168.163.117:7002 weight=100;<br/>}<br/></p>nginx 설정 다시 로드
# nginx -s reload2018/05/28 05:26:37 [notice] 353#353: signal process started#
결과 확인[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl http://localhost:9080; let cnt++; doneHello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002Hello, Service :Hello canary deploy service: v2 in 7002[root@kong ~]#관련 권장 사항:
nginx 애플리케이션: 로드 밸런싱을 위해 nginx 사용
위 내용은 nginx 애플리케이션: nginx를 사용한 카나리아 게시의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

데이터베이스 스토리지 세션 사용의 주요 장점에는 지속성, 확장 성 및 보안이 포함됩니다. 1. 지속성 : 서버가 다시 시작 되더라도 세션 데이터는 변경되지 않아도됩니다. 2. 확장 성 : 분산 시스템에 적용하여 세션 데이터가 여러 서버간에 동기화되도록합니다. 3. 보안 : 데이터베이스는 민감한 정보를 보호하기 위해 암호화 된 스토리지를 제공합니다.

SessionHandlerInterface 인터페이스를 구현하여 PHP에서 사용자 정의 세션 처리 구현을 수행 할 수 있습니다. 특정 단계에는 다음이 포함됩니다. 1) CustomsessionHandler와 같은 SessionHandlerInterface를 구현하는 클래스 만들기; 2) 인터페이스의 방법 (예 : Open, Close, Read, Write, Despare, GC)의 수명주기 및 세션 데이터의 저장 방법을 정의하기 위해 방법을 다시 작성합니다. 3) PHP 스크립트에 사용자 정의 세션 프로세서를 등록하고 세션을 시작하십시오. 이를 통해 MySQL 및 Redis와 같은 미디어에 데이터를 저장하여 성능, 보안 및 확장 성을 향상시킬 수 있습니다.

SessionId는 웹 애플리케이션에 사용되는 메커니즘으로 사용자 세션 상태를 추적합니다. 1. 사용자와 서버 간의 여러 상호 작용 중에 사용자의 신원 정보를 유지하는 데 사용되는 무작위로 생성 된 문자열입니다. 2. 서버는 쿠키 또는 URL 매개 변수를 통해 클라이언트로 생성하여 보낸다. 3. 생성은 일반적으로 임의의 알고리즘을 사용하여 독창성과 예측 불가능 성을 보장합니다. 4. 실제 개발에서 Redis와 같은 메모리 내 데이터베이스를 사용하여 세션 데이터를 저장하여 성능 및 보안을 향상시킬 수 있습니다.

JWT 또는 쿠키를 사용하여 API와 같은 무국적 환경에서 세션을 관리 할 수 있습니다. 1. JWT는 무국적자 및 확장 성에 적합하지만 빅 데이터와 관련하여 크기가 크다. 2. 쿠키는보다 전통적이고 구현하기 쉽지만 보안을 보장하기 위해주의해서 구성해야합니다.

세션 관련 XSS 공격으로부터 응용 프로그램을 보호하려면 다음 조치가 필요합니다. 1. 세션 쿠키를 보호하기 위해 Httponly 및 Secure 플래그를 설정하십시오. 2. 모든 사용자 입력에 대한 내보내기 코드. 3. 스크립트 소스를 제한하기 위해 컨텐츠 보안 정책 (CSP)을 구현하십시오. 이러한 정책을 통해 세션 관련 XSS 공격을 효과적으로 보호 할 수 있으며 사용자 데이터가 보장 될 수 있습니다.

PHP 세션 성능을 최적화하는 방법 : 1. 지연 세션 시작, 2. 데이터베이스를 사용하여 세션을 저장, 3. 세션 데이터 압축, 4. 세션 수명주기 관리 및 5. 세션 공유 구현. 이러한 전략은 높은 동시성 환경에서 응용의 효율성을 크게 향상시킬 수 있습니다.

THESESSION.GC_MAXLIFETIMESETTINGINSTTINGTINGSTINGTERMINESTERMINESTERSTINGSESSIONDATA, SETINSECONDS.1) IT'SCONFIGUDEDINPHP.INIORVIAINI_SET ()

PHP에서는 Session_Name () 함수를 사용하여 세션 이름을 구성 할 수 있습니다. 특정 단계는 다음과 같습니다. 1. Session_Name () 함수를 사용하여 Session_Name ( "my_session")과 같은 세션 이름을 설정하십시오. 2. 세션 이름을 설정 한 후 세션을 시작하여 세션을 시작하십시오. 세션 이름을 구성하면 여러 응용 프로그램 간의 세션 데이터 충돌을 피하고 보안을 향상시킬 수 있지만 세션 이름의 독창성, 보안, 길이 및 설정 타이밍에주의를 기울일 수 있습니다.


핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

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

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

Dreamweaver Mac版
시각적 웹 개발 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.
