【Azure 應用服務】App Service 項目部署成功后,應用連接 Azure Redis時報錯 Could not get a resource from the pool

問題描述

App Service 項目部署成功后,需要連接到同在云上的Redis服務, Redis啟動了專用終結(jié)點,只能在于Redis同一個VNET(虛擬網(wǎng)絡)的資源能夠訪問。在進入App Service的Bash中使用Paping測試Redis的網(wǎng)絡連通性,驗證是通的。但是為什么應用程序中一直出錯呢?

Bash中使用Paping:

No alt text provided for this image

應用程序中的錯誤信息:

[INFO]  org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; 
nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to xxxxxxx.redis.cache.chinacloudapi.cn:6380

at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:86) 
~[spring-data-redis-2.0.6.RELEASE.jar!/:2.0.6.RELEASE]

問題分析

App Service配置了VNET后,可以在Bash中paping通Redis服務,表示從App Service到Redis之間的網(wǎng)絡鏈路是相通的。但是為什么在應用中就是連接不上Redis呢?

仔細查看App Service的文檔后,是由于應用與 VNet 集成后,它將使用 VNet 配置的 DNS 服務器。 默認情況下,應用不能用于 Azure DNS 專用區(qū)域。需要添加設置(WEBSITE_VNET_ROUTE_ALL & WEBSITE_DNS_SERVER )將所有出站調(diào)用從應用發(fā)送到 VNet,并允許應用訪問 Azure DNS 專用區(qū)域。

添加配置參數(shù)如下后,應用調(diào)用Redis成功。

WEBSITE_VNET_ROUTE_ALL = 1
WEBSITE_DNS_SERVER = 168.63.129.16

但是在App Service for Linux環(huán)境中,可以通過全部路由( Route All) 功能來代替 WEBSITE_VNET_ROUTE_ALL 配置。


No alt text provided for this image

注意:配置應用程序路由時,可將所有流量或僅將專用流量路由到 VNet。 通過“全部路由(Route All)”設置來配置此設置。

參考資料:

將應用與 Azure 虛擬網(wǎng)絡集成:https://docs.microsoft.com/zh-cn/azure/app-service/web-sites-integrate-with-vnet#regional-vnet-integration

**Azure DNS 專用區(qū)域: **https://docs.azure.cn/zh-cn/app-service/web-sites-integrate-with-vnet#azure-dns-private-zones

當在復雜的環(huán)境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 云中,恰是如此!

分類: 【Azure 應用服務】

標簽: 應用連接 Redis Could not get a resource from the pool, Azure Redis, App Service

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容