検索
ホームページ運用・保守NginxCanary パブリッシングに nginx シミュレーションを使用する方法

カナリア リリース/グレースケール リリース

カナリア リリースの焦点は、試行錯誤です。カナリアの放鳥自体の起源は、人間の産業の発展における美しい自然の生き物たちの悲劇的な物語です。カナリアは、鉱山労働者の安全のために自らの命をかけて試行錯誤します。全体的なセキュリティのための交換には、少額のコストが使用されます。継続的デプロイメントの実践では、カナリアはトラフィック制御です。1 パーセントや 10 分の 1 などの非常に少量のトラフィックが、特定のバージョンが正常かどうかを確認するために使用されます。異常であれば、その機能は最小限のコストで達成され、リスクは軽減されます。正常であれば、100% に達するまで徐々に重みを増やし、すべてのトラフィックを新しいバージョンにスムーズに切り替えることができます。グレースケール パブリッシングも一般に同様の概念です。グレーは黒と白の間の移行です。青か緑のどちらかであるブルー アンド グリーン デプロイメントとは異なります。グレースケール リリース/カナリア リリースには両方が同時に存在する期間がありますが、この 2 つの対応するトラフィックはカナリア リリースとグレースケール リリースが異なる場合、その違いが目的である必要があります。カナリア リリースの目的は試行錯誤ですが、グレースケール リリースは安定リリースについてであり、カナリア リリースには問題はありません。スムーズな移行です。グレースケール出版の状況下で。

カナリア リリースのシミュレーション

次に、nginx のアップストリームを使用して、カナリア リリース シナリオを単純にシミュレートします。具体的なシナリオとしては、現在メインバージョンがアクティブになっており、nginx の設定を調整し、常に Canary バージョンのウェイトを調整することで、最終的にスムーズなリリースが実現されます。

Canary パブリッシングに nginx シミュレーションを使用する方法

#事前準備

2 つのポート 7001/7002 で 2 つのサービスを事前に起動し、異なる情報を表示します。便利です tornadoを使って画像を作成しました Dockerコンテナ起動時に渡される各種パラメータはサービスの違いを表示するために使用されます。

docker run -d -p 7001:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello main service: v1 in 7001"
docker run -d -p 7002:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello canary deploy service: v2 in 7002"

実行ログ

[root@kong ~]# docker run -d -p 7001:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello main service: v1 in 7001"
28f42bbd21146c520b05ff2226514e62445b4cdd5d82f372b3791fdd47cd602a
[root@kong ~]# docker run -d -p 7002:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello canary deploy service: v2 in 7002"
b86c4b83048d782fadc3edbacc19b73af20dc87f5f4cf37cf348d17c45f0215d
[root@kong ~]# curl http://192.168.163.117:7001
hello, service :hello main service: v1 in 7001
[root@kong ~]# curl http://192.168.163.117:7002
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#

nginxの開始

[root@kong ~]# docker run -p 9080:80 --name nginx-canary -d nginx
659f15c4d006df6fcd1fab1efe39e25a85c31f3cab1cda67838ddd282669195c
[root@kong ~]# docker ps |grep nginx-canary
659f15c4d006    nginx           "nginx -g 'daemon ..."  7 seconds ago    up 7 seconds    0.0.0.0:9080->80/tcp   nginx-canary
[root@kong ~]#

nginxコードセグメント

以下の nginx コード スニペットを用意し、nginx の /etc/nginx/conf.d/default.conf に追加します。シミュレーション方法は非常に簡単です。トラフィックがゼロであることを示すには、down を使用します (重みをゼロに設定することはできません)。 nginx 内) 最初は、トラフィックの 100% がメイン バージョンに送信されます。

http {
upstream 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;
  location / {
    proxy_pass http://nginx_canary;
  }
}

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_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 reload
2018/05/28 05:16:20 [notice] 319#319: signal process started
#

#結果を確認します

##10 回の呼び出しすべての出力は 7001 の v1 です

[ root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; docurl ; let cnt ; 完了

hello, サービス :hello メイン サービス: v1 in 7001

hello, サービス :hello メイン サービス: v1 in 7001
hello, サービス :hello メイン サービス: v1 in 7001

hello, サービス :hello メイン サービス: v1 in 7001
hello, サービス :hello メイン サービス: v1 in 7001
hello 、サービス :hello メイン サービス: 7001 の v1
hello、サービス :hello メイン サービス: 7001 の v1
hello、サービス :hello メイン サービス: 7001 の v1
hello、サービス :hello メイン サービス : v1 in 7001
hello, service :hello main service: v1 in 7001
[root@kong ~]



# カナリア リリース: カナリア バージョン トラフィックの重み 10%

##default.conf の重みを調整してから nginx -s reload を実行することで、カナリア バージョンの重みを 10% に調整すると、トラフィックの 10% が新しいサービスを実行します

default.conf を変更する方法

次のようにアップストリームのサーバーの重みを調整するだけです:

upstream nginx_canary {
  server 192.168.163.117:7001 weight=10;
  server 192.168.163.117:7002 weight=90;
}
nginx 設定をリロードします決定

# nginx -s reload
2018/05/28 05:20:14 [notice] 330#330: signal process started
#

結果を確認

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; docurl ; let cnt ; 完了hello、サービス :hello カナリア デプロイ サービス: 7002 年の v2 hello、サービス :hello カナリア デプロイ サービス: 7002 の v2

hello、サービス :hello カナリア デプロイ サービス: 7002 の v2
こんにちは、サービス :hello Canary デプロイ サービス: v2 で 7002

hello、サービス :hello メイン サービス: v1 で 7001
hello、サービス :hello Canary デプロイ サービス: v2 で 7002
hello、サービス :hello Canaryデプロイ サービス: v2 で 7002
hello, サービス :hello Canary デプロイ サービス: v2 で 7002
hello, サービス :hello Canary デプロイ サービス: v2 で 7002
hello, サービス :hello Canary デプロイ サービス : v2 で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 reload
2018/05/28 05:22:26 [notice] 339#339: signal process started
#

确认结果

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl ; let cnt++; done
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#

金丝雀发布: 金丝雀版本流量权重90%

通过调整default.conf的weight,然后执行nginx -s reload的方式,调节金丝雀版本的权重为90%,流量的90%会执行新的服务

修改default.conf的方法

只需要将upstream中的server的权重做如下调整:

upstream nginx_canary {
  server 192.168.163.117:7001 weight=10;
  server 192.168.163.117:7002 weight=90;
}

重新加载nginx设定

# nginx -s reload
2018/05/28 05:24:29 [notice] 346#346: signal process started
#

确认结果

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl ; let cnt++; done
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#

金丝雀发布: 金丝雀版本流量权重100%

通过调整default.conf的weight,然后执行nginx -s reload的方式,调节金丝雀版本的权重为100%,流量的100%会执行新的服务

修改default.conf的方法

只需要将upstream中的server的权重做如下调整:

upstream nginx_canary {
  server 192.168.163.117:7001 down;
  server 192.168.163.117:7002 weight=100;
}

重新加载nginx设定

# nginx -s reload
2018/05/28 05:26:37 [notice] 353#353: signal process started

确认结果

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl ; let cnt++; done
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#

以上がCanary パブリッシングに nginx シミュレーションを使用する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事は亿速云で複製されています。侵害がある場合は、admin@php.cn までご連絡ください。
Nginxの主な機能:パフォーマンス、スケーラビリティ、セキュリティNginxの主な機能:パフォーマンス、スケーラビリティ、セキュリティApr 13, 2025 am 12:09 AM

Nginxは、イベント駆動型のアーキテクチャと非同期処理機能を通じてパフォーマンスを向上させ、モジュラー設計と柔軟な構成を通じてスケーラビリティを向上させ、SSL/TLSの暗号化と要求レートの制限を介してセキュリティを改善します。

Nginx vs. Apache:Webホスティングとトラフィック管理Nginx vs. Apache:Webホスティングとトラフィック管理Apr 12, 2025 am 12:04 AM

Nginxは、高い並行性と低リソース消費シナリオに適していますが、Apacheは複雑な構成と機能的拡張を必要とするシナリオに適しています。 1.Nginxは、高性能と多数の同時接続を処理することで知られています。 2。Apacheは、その安定性とリッチモジュールのサポートで知られています。選択するときは、特定のニーズに基づいて決定する必要があります。

NGINX:最新のWebアプリケーション用の汎用ツールNGINX:最新のWebアプリケーション用の汎用ツールApr 11, 2025 am 12:03 AM

nginxisentialformodernwebapplicationsdueToitsRolesasareverseproxy、loadbalancer、andwebserver、weberporformanceandscalability.1)itactsasaReverseproxy、拡張、およびパフォーマンスを強化し、パフォーマンスを強化し、積極的に積極的なものを増やします

nginx SSL/TLS構成:HTTPSでWebサイトを保護しますnginx SSL/TLS構成:HTTPSでWebサイトを保護しますApr 10, 2025 am 09:38 AM

NGINXを通じてWebサイトのセキュリティを確保するには、次の手順が必要です。1。基本的な構成を作成し、SSL証明書と秘密鍵を指定します。 2。構成を最適化し、HTTP/2を有効にし、OCSPSTAPLING。 3.証明書パスや暗号化スイートの問題などの一般的なエラーをデバッグします。 4。let'sencryptの使用やセッションの多重化など、アプリケーションのパフォーマンス最適化の提案。

Nginxインタビューの質問:DevOps/System管理インタビューをAceNginxインタビューの質問:DevOps/System管理インタビューをAceApr 09, 2025 am 12:14 AM

Nginxは、高性能のHTTPおよびリバースプロキシサーバーであり、高い並行接続の取り扱いに優れています。 1)基本的な構成:ポートを聞いて静的ファイルサービスを提供します。 2)高度な構成:逆プロキシとロードバランシングを実装します。 3)デバッグスキル:エラーログを確認し、構成ファイルをテストします。 4)パフォーマンスの最適化:GZIP圧縮を有効にし、キャッシュポリシーを調整します。

nginxキャッシュテクニック:ウェブサイトのパフォーマンスの向上nginxキャッシュテクニック:ウェブサイトのパフォーマンスの向上Apr 08, 2025 am 12:18 AM

Nginxキャッシュは、次の手順を通じてWebサイトのパフォーマンスを大幅に改善できます。1)キャッシュ領域を定義し、キャッシュパスを設定します。 2)キャッシュ有効期間を構成します。 3)異なるコンテンツに従って異なるキャッシュポリシーを設定します。 4)キャッシュストレージと負荷分散を最適化します。 5)キャッシュ効果を監視およびデバッグします。これらの方法により、Nginxキャッシュはバックエンドサーバーの圧力を軽減し、応答速度とユーザーエクスペリエンスを向上させることができます。

Dockerを使用したNginx:コンテナ化されたアプリケーションの展開とスケーリングDockerを使用したNginx:コンテナ化されたアプリケーションの展開とスケーリングApr 07, 2025 am 12:08 AM

DockerComposeを使用すると、Nginxの展開と管理が簡素化され、DockerswarmまたはKubernetesをスケーリングすることは一般的な慣行です。 1)DockerComposeを使用してNginxコンテナを定義および実行する、2)DockerswarmまたはKubernetesを介してクラスター管理と自動スケーリングを実装します。

Advanced Nginx構成:マスタリングサーバーブロックとリバースプロキシAdvanced Nginx構成:マスタリングサーバーブロックとリバースプロキシApr 06, 2025 am 12:05 AM

nginxの高度な構成は、サーバーブロックとリバースプロキシを介して実装できます。1。サーバーブロックにより、複数のWebサイトを1つの場合に実行することができます。各ブロックは個別に構成されます。 2.逆プロキシは、リクエストをバックエンドサーバーに転送して、負荷分散とキャッシュアクセラレーションを実現します。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。