In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to use nginx to simulate blue-green deployment", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use nginx simulation for blue-green deployment" article.
Blue and green deployment
The focus of blue and green deployment is on the following characteristics
1. Blue version and green version exist at the same time
two。 The actual operating environment is blue or green, which can only be one of them, which can be controlled by switch.
Analysis of advantages and disadvantages: the advantage lies in its speed and rollback. And the shortcomings are obvious. You can roll back quickly because there are two sets of environments at the same time, so the complexity and resource requirements will increase, because it has two sets of environments.
In addition, although the speed has been improved, but in the process of implementation, the switch control, no matter how fast the switching speed, if not combined with other technologies, can not achieve complete seamless switching.
Simulate a blue-green deployment
Next, we use nginx's upstream to briefly simulate the blue-green deployment scenario. The specific scenarios are as follows. The blue version is currently active. By adjusting the nginx setting, the green version is set to the current active version.
Prepare beforehand
In advance, start two services on the two ports of 7001 docker 7002 to display different information. For convenience of demonstration, use tornado to make a mirror image. Different parameters passed when starting through the docker container are used to display different services.
Docker run-d-p 7001 in 8080 liumiaocn/tornado:latest python / usr/local/bin/daemon.py "hello blue/green service: v1 in 7001" docker run-d-p 7002 purl 8080 liumiaocn/tornado:latest python / usr/local/bin/daemon.py "hello blue/green service: v2 in 7002"
Execution log
[root@kong ~] # docker run-d-p 7001docker run 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 purl 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:7001hello, Service: hello blue/green service: v1 in 7001 [root@kong ~] # curl http://192.168.163.117:7002hello, service: hello blue/green service: v2 in 7002 [root@kong ~] #
Start nginx
[root@kong ~] # docker run-p 9080 nginxd3b7098c44890c15918dc47616b67e5e0eb0da7a443eac266dbf26d55049216a 80-- name nginx-blue-green-d nginxd3b7098c44890c15918dc47616b67e5e0eb0da7a443eac266dbf26d55049216a [root@kong ~] # docker ps | grep nginx-blue-greend3b7098c4489 nginx "nginx- g 'daemon..." 10 seconds ago up 9 seconds 0.0.0.0 seconds 9080-> 80/tcp nginx-blue-green [root@kong ~] #
Nginx code snippet
Prepare the following nginx code snippet to add it to the / etc/nginx/conf.d/default.conf of nginx. The simulation method is very simple. Zero traffic is indicated by down (weight cannot be set to zero in nginx). At the beginning, 100% of the traffic is sent to the blue version.
Http {upstream nginx_blug_green {server 192.168.163.117 upstream nginx_blug_green 7001 weight=100; server 192.168.163.117 upstream nginx_blug_green 7002 down;} server {listen 80; server_name www.liumiao.cn 192.168.163.117; location / {proxy_pass http://nginx_blug_green;}}
The method of modifying default.conf
You can achieve this by installing vim in the container, or you can modify it locally and pass it in via docker cp, or you can modify it directly by sed. If you install vim in the container, you can use the following
[root@kong ~] # docker exec-it nginx-lb sh# apt-get update... Omit # apt-get install vim... Omit
Before modification
# 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 proxy the php scripts to apache listening on 80 # # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1 php$ {# root html; # fastcgi_pass 127.0.0.1 # 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; #} #
After modification
# cat default.confupstream nginx_blug_green {server 192.168.163.117 down; 7001 weight=100; server 192.168.163.117 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 500502 503504 / 50x.html; location = / 50x.html {root / usr/share/nginx/html;} # proxy the php scripts to apache listening on 127.0.1 proxy the php scripts to apache listening on 80 # # location ~. Php$ {# proxy_pass #} # pass the php scripts to fastcgi server listening on 127.0.0.1 pass the php scripts to fastcgi server listening on 9000 # # location ~\. Php$ {# root html; # fastcgi_pass 127.0.0.1 php$ 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; #} #
Reload nginx settin
# nginx-s reload2018/05/28 04:39:47 [notice] 321: signal process started#
Confirm the result
All of the 10 calls output v1 in 7001.
[root@kong ~] # cnt=0; while [$cnt-lt 10]
> do
> curl
> let cnt++
> done
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
Hello, service: hello blue/green service: v1 in 7001
[root@kong ~] #
Blue and green deployment: switch to green version
By adjusting the weight of default.conf, and then executing nginx-s reload, you can dynamically switch to the green version without stopping the nginx service, and the target will output all traffic to v2 in 7002.
The method of modifying default.conf
You only need to adjust the weight of the server in upstream as follows:
Upstream nginx_blug_green {server 192.168.163.117:7001 down; server 192.168.163.117:7002 weight=100;}
Reload nginx settin
# nginx-s reload2018/05/28 05:01:28 [notice] 330mm 330: signal process started#
Confirm the result
[root@kong ~] # cnt=0; while [$cnt-lt 10]; do curl; let cnt++; done
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
Hello, service: hello blue/green service: v2 in 7002
[root@kong ~] #
The above is the content of this article on "how to use nginx to simulate blue-green deployment". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.