最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Openresty+redis實(shí)現(xiàn)灰度發(fā)布

標(biāo)簽:
Redis

一、架构

环境:

192.168.189.131:tomcat服务

192.168.189.132:tomcat服务

192.168.189.130:OpenResty服务、redis服务

流程:

请求到达openresty,openresty从redis获取白名单,然后判断请求地址是否再白名单,在白名单转到192.168.189.132服务否则转到192.168.189.131服务

在redis中动态设置白名单,实现服务切换

二、配置(openresty、redis、tomcat安装忽略)

1、在openresty根目录创建目录gray(作为工作空间),在gray目录创建conf(存放nginx配置文件nginx.conf)、logs(存放日志文件)、lua(存放lua脚本)

2、配置nginx.conf

复制代码

user root;
worker_processes 1;
error_log logs/error.log;

events {
    worker_connections 1024;
}

http {
  #添加;;标识默认路径下的lualib
  lua_package_path "$prefix/lualib/?.lua;;";
  lua_package_cpath "$prefix/lualib/?.so;;";

  upstream prod1 {
    server 192.168.189.131:8080;
  }

  upstream prod2 {
    server 192.168.189.132:8080;
  }

  server {
    listen 80;
    server_name localhost;
    location / {
      #为每个请求执行gray.lua脚本
      content_by_lua_file lua/gray.lua;
    }
    location @prod1 {
      proxy_pass http://prod1;
    }
    location @prod2 {
      proxy_pass http://prod2;
    }
    
  }

}

复制代码

3、配置gray.lua

复制代码

 
local redis=require "resty.redis";

local red=redis:new();

red:set_timeout(1000);
--redis连接
local ok,err=red:connect("192.168.189.130", 6379);

if not ok then
  ngx.say("failed to connect redis ",err);
  return;
end
--获取请求ip
local local_ip = ngx.req.get_headers()["X-Real-IP"];
if local_ip == nil then
   local_ip = ngx.req.get_headers()["x_forwarded_for"];
end
if local_ip == nil then
   local_ip = ngx.var.remote_addr;
end


local_ip=ngx.var.remote_addr;
--redis中获取白名单
local ip_lists=red:get("gray");
--判断是否在白名单然后转到对应服务
if string.find(ip_lists,local_ip) == nil then
  ngx.exec("@prod1");
else
  ngx.exec("@prod2");
end

local ok,err=red:close();

复制代码

注意:

redis配置注释掉bind 127.0.0.1、设置protected-mode 为no;否则通过lua连接redis出错

复制代码

#bind 127.0.0.1# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.protected-mode no

复制代码

4、启动openresty

在openresty/nginx/sbin执行:./nginx -p /root/data/program/openresty/gray  (-p表示指定空间)

5、演示效果:

访问192.168.189.131服务:

访问192.168.189.132服务:

redis中白名单gray:

请求地址192.168.189.130不在白名单,因此lua脚本执行@prod1,对应server 192.168.189.131:8080

redis设置白名单gray:

 请求地址192.168.189.130在白名单,lua脚本执行@prod2,对应server 192.168.189.132:8080

原文出处:https://www.cnblogs.com/ph7seven/p/9941189.html  

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
手記
粉絲
85
獲贊與收藏
378

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消