在 VNet 中运行的 Azure 函数无法连接到列入白名单的 Azure Redis 缓存

问题描述 投票:0回答:1

我有一个在单个子网内的 VNet 中运行的 Azure 函数。我还设置了一个可公开访问的 Azure Redis 缓存。最初,Azure Function 能够与 Redis 缓存进行通信,没有任何问题。但是,出于安全目的,我将 Redis 缓存中的 Azure Function 的出站 IP 列入白名单。从那时起,我就遇到了超时问题。

Azure 功能的出站 IP。功能应用程序 -> 属性 enter image description here

子网信息(我没有任何安全组或路由表): enter image description here

    Method: PutKeysAsync error while inserting key: key and value: akhil, Error: The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=SET, timeout: 5000, inst: 0, qu: 0, qs: 0, aw: False, bw: CheckingForTimeout, rs: NotStarted, ws: Initializing, in: 0, last-in: 0, cur-in: 0, sync-ops: 0, async-ops: 4, serverEndpoint: test-pr-analyzer-redis-cache.redis.cache.windows.net:6380, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: pd1sdwk001NH9(SE.Redis-v2.8.0.27420), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=2,Free=32765,Min=1,Max=32767), POOL: (Threads=5,QueuedItems=0,CompletedItems=4712,Timers=12), v:

2.8.0.27420 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeout

请帮我解决问题。

提前致谢

azure-functions azure-virtual-network azure-redis-cache
1个回答
0
投票

在 VNet 中运行的 Azure 函数无法连接到列入白名单的 Azure Redis 缓存。

以下是功能应用程序无法访问

Redis cache
的原因。

  1. 如果您不将所有功能应用程序出站IP地址添加到Redis缓存防火墙,它将无法连接。
  2. 如果您使用消费计划高级计划,出站 IP 地址可能会因自动缩放行为而随时更改。请参阅MS Doc了解更多详细信息

要永久解决该问题,请确保使用虚拟网络 NAT 网关将流量从 Function App 子网路由到 Redis 缓存。请按照以下步骤使用 NAT 网关建立连接。

  1. 创建 Vnet 和子网(在您的情况下,您已经创建了 Vnet 和子网)。
  2. 创建公共IP。
  3. 创建具有相同VNet
    Subnet
    NAT网关
    ,并在出站IP部分选择之前创建的公共IP

enter image description here

创建 NAT 网关后,出站流量将通过 NAT 网关的 IP 地址。要在 Azure Function App 和 Redis 缓存之间建立连接,请确保在 Redis 缓存防火墙中添加与 NAT 网关关联的公共 IP 地址。

NAT 网关详细信息

enter image description here

Redis 缓存防火墙设置

enter image description here

将公网IP地址添加到Redis缓存防火墙后,Function App就可以与Redis缓存通信了。

enter image description here

Redis 缓存结果

enter image description here

参考Azure Functions 网络选项]

使用 Azure 虚拟网络 NAT 网关控制 Azure Functions 出站 IP

© www.soinside.com 2019 - 2024. All rights reserved.