Grayscale release refers to a release method that can smoothly transition between black and white. AB testing is a grayscale release method , where some users continue to use A, while some users start using B. If users have no objection to B, then the scope is gradually expanded and all users are migrated to B. Grayscale release can ensure the stability of the overall system. Problems can be discovered and adjusted during the initial grayscale release to ensure their impact. There are generally three ways to release grayscale:
This article will mainly explain how to implement simple grayscale publishing based on cookies and source IP. The Nginx+LUA method involves too much content and will not be expanded in this article. A/B Testing Process Nginx implements grayscale release based on Cookie According to the Cookie query, the Cookie key is the value of version. If the Cookie value is V1, it is forwarded to hilinux_01. If it is V2, it is forwarded to hilinux_02. If the cookie values do not match, the server corresponding to hilinux_01 will be used by default. The two servers are defined as:
Implemented with if instruction upstream hilinux_01 { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } upstream hilinux_02 { server 192.168.1.200:8080 max_fails=1 fail_timeout=60; } upstream default { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } server { listen 80; server_name www.hi-linux.com; access_log logs/www.hi-linux.com.log main; #match cookie set $group "default"; if ($http_cookie ~* "version=V1"){ set $group hilinux_01; } if ($http_cookie ~* "version=V2"){ set $group hilinux_02; } location / { proxy_pass http://$group; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; index index.html index.htm; } } Implemented with the map directive Configure a mapping in Nginx, If a user with version V1 accesses the system, $group will be equal to hilinux_01. When used in the server, it will proxy to http://hilinux_01. If the user with version V2 accesses the system, $group is equal to hilinux_02. When used in the server, it will proxy to http://hilinux_02. If the cookie values do not match, the server corresponding to hilinux_01 will be used by default. upstream hilinux_01 { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } upstream hilinux_02 { server 192.168.1.200:8080 max_fails=1 fail_timeout=60; } upstream default { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } map $COOKIE_version $group { ~*V1$ hilinux_01; ~*V2$ hilinux_02; default default; } server { listen 80; server_name www.hi-linux.com; access_log logs/www.hi-linux.com.log main; location / { proxy_pass http://$group; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; index index.html index.htm; } } Nginx implements grayscale release based on the incoming IP If it is an internal IP, the reverse proxy is sent to hilinux_02 (pre-release environment); if not, the reverse proxy is sent to hilinux_01 (production environment). upstream hilinux_01 { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } upstream hilinux_02 { server 192.168.1.200:8080 max_fails=1 fail_timeout=60; } upstream default { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } server { listen 80; server_name www.hi-linux.com; access_log logs/www.hi-linux.com.log main; set $group default; if ($remote_addr ~ "211.118.119.11") { set $group hilinux_02; } location / { proxy_pass http://$group; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; index index.html index.htm; } } If you only have a single server, you can set up different website root directories according to different IP addresses to achieve the same purpose. server { listen 80; server_name www.hi-linux.com; access_log logs/www.hi-linux.com.log main; set $rootdir "/var/www/html"; if ($remote_addr ~ "211.118.119.11") { set $rootdir "/var/www/test"; } location / { root $rootdir; } } This is the end of the most basic method for implementing grayscale release. If you want to do a more fine-grained grayscale release, you can refer to the ABTestingGateway project. ABTestingGateway is an open source dynamic routing system from Sina. ABTestingGateway is a grayscale release system that can dynamically set diversion strategies. It works at Layer 7 and is developed based on nginx and ngx-lua. It uses redis as the diversion strategy database and can implement dynamic scheduling functions. ABTestingGateway: https://github.com/CNSRE/ABTestingGateway Reference Documentation This is the end of this article about using Nginx to implement grayscale publishing. For more relevant Nginx grayscale publishing content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue implements simple slider verification
>>: Detailed explanation of ensuring the consistency of MySQL views (with check option)
Table of contents Preface What is index pushdown?...
MySQL multi-table query (Cartesian product princi...
Table of contents introduction 1. MySQL master-sl...
Copy code The code is as follows: <object clas...
1. There are two ways to modify global variables ...
Take MySQL 5.7.19 installation as an example, fir...
transform: scale(); Scaling will cause jitter in ...
Table of contents Introduction Create a Next.js p...
background All of the company's servers are p...
Table of contents Vue.js 1. Register global guard...
Environment: CentOS 7.1.1503 Minimum Installation...
To automatically load kernel modules in CentOS, y...
1. Demand We have three tables. We need to classi...
When the scale of Docker deployment becomes large...
I am currently learning MySQL. I am a complete no...