如果 auth_enabled 为 redis 设置为 true,如何从 GCP cloudrun 连接到 GCP redis?

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

我在 GCP 中有一个 redis 实例和一个云运行。

首先为redis-instance设置auth_enabled为false,cloudrun可以连接redis。此外,我能够通过 gcp-compute-engine(VM) 从本地连接到 redis。

现在,我为 redis 激活了身份验证,您可以直接在 GCP 控制台中执行此操作,或者通过将“auth_enabled = true”添加到资源“google_redis_instance”来按地形执行此操作。

之后,我可以在 Redis 的 GCP-Console 中看到,生成了一个“auth_string”。

使用生成的 auth_string,我仍然可以通过 VM 从本地连接到 redis 实例(使用的命令:redis-cli -h 127.0.0.1 -p 6379 -a )。

但现在的问题是,我的cloudrun应用程序启动失败,因为cloud run无法再连接到redis,我不知道在哪里设置auth_string。

Cloudrun-Application的错误是:

"Constructor threw exception; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to xx.xx.xxx.xxx/<unresolved>:6379"

我的应用在cloud run上运行,是一个spring boot应用,java版本17,Spring boot版本2.7.7,lettuce版本6.2.3.RELEASE

我认为生成的“auth_string”NOT等同于redis的“密码”。 因为我试图将这个 Spring-Property“spring.data.redis.password”的值设置为可以从 gcp-console 复制的 的值,但在日志中仍然出现相同的错误。

有谁知道,我如何在我的 spring boot 应用程序中设置 auth_string 以连接到 redis?非常感谢!

spring spring-boot google-cloud-platform redis google-cloud-run
1个回答
0
投票

我们找到了解决方案。我们的设置是这样的: (1) 我们有一个 gcp-redis-instanz,选项“auth_enabled”设置为 true,之后 gcp 自动为我们生成了一个 redis-password(它是 36 个字符长并且它是一个 UUID)。 (2) 我们有 spring boot 应用程序,运行在 gcp cloud run 上。启用redis auth后,我们使用了这个包含生成密码的redis_uri,然后它就可以工作了:redis://@:.

我们的错误是,我们将redis密码保存在gcp secret manager中,并将redis-password的secret作为envrionment vairbale传递给cloud run,但是忘记在pom.xml中添加gcp-secret-manager的依赖,所以secret不能被正确读取,这就是我们收到错误的原因:“无法连接到 xx.xx.xxx.xxx/:6379”

生成的36个字符长的redis-AUTH-String是redis-password,两者是一回事

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