[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次调用全部输出的都是v1 in 7001
[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl http://localhost:9080; let cnt++; done
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
Hello, Service :Hello main service: v1 in 7001
[root@kong ~]#
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 ]; do curl http://localhost:9080; 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 ~]#
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 http://localhost:9080; 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 ~]#
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 http://localhost:9080; 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 ~]#
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 http://localhost:9080; 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 ~]#