【问题标题】:Can't connect to redis bull from google cloud run无法从谷歌云运行连接到 redis 公牛
【发布时间】:2020-11-21 15:05:26
【问题描述】:

我正在尝试在 Google Cloud 上运行我的 redis 公牛。在本地一切正常。

我在服务器启动时使用以下代码:

const client = redis.createClient('6379', '10.103.YYY.YYY');

这似乎有效。我在启动时没有收到任何错误。

当我尝试与 Bull 一起工作时:

             const actionQueue = new Bull(uuid(), {
                redis: {
                    port: 6379, host: '10.103.YYY.YYY', tls: {
                        servername: '10.103.YYY.YYY'
                    }
                }
            });
         
            await actionQueue.add();

            actionQueue.process(async (job) => {
                return this._job();
            });

            actionQueue.on('completed', async (job, actionId) => {
                console.log(`Job completed with result ${actionId}`);
            });

            actionQueue.on("failed", (job, error) => {
                console.log(job.id, error);
            });

但是redis仍然连接到localhost ip&port。有人知道为什么这仍然连接到我的本地主机吗?我需要以不同的方式进行设置吗?

错误日志:

2020-11-21T14:55:35.794783Z <rejected> Error: connect ECONNREFUSED 127.0.0.1:6379
Standaard
2020-11-21T14:55:35.794791Z at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1145:16) {
Standaard
2020-11-21T14:55:35.794798Z errno: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.794804Z code: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.794810Z syscall: 'connect',
Standaard
2020-11-21T14:55:35.794816Z address: '127.0.0.1',
Standaard
2020-11-21T14:55:35.794822Z port: 6379
Standaard
2020-11-21T14:55:35.794828Z }
Standaard
2020-11-21T14:55:35.794834Z}
Standaard
2020-11-21T14:55:35.794987Z The error was: Error: connect ECONNREFUSED 127.0.0.1:6379
Standaard
2020-11-21T14:55:35.794994Z at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1145:16) {
Standaard
2020-11-21T14:55:35.795Z errno: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.795006Z code: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.795011Z syscall: 'connect',
Standaard
2020-11-21T14:55:35.795017Z address: '127.0.0.1',
Standaard
2020-11-21T14:55:35.795022Z port: 6379
Standaard
2020-11-21T14:55:35.795028Z}

【问题讨论】:

  • new Bull 替换为new Queue 并告诉我是否更好
  • 我用于 init : const Bull = require('bull');
  • 你知道我是否需要配置一些东西来允许连接谷歌云运行 Redis 服务?
  • 如果您的 localhost 问题得到解决,是的,Cloud Run 上还有一个额外的配置要执行
  • 你能帮我看看哪个配置吗?

标签: node.js redis google-cloud-run


【解决方案1】:

Cloud Run 本身不与 VPC 对话。您需要在没有项目 VPC 的情况下连接无服务器世界。

为此,您必须使用serverless VPC connector。在部署 Cloud Run 的同一区域创建。

然后attach it to your Cloud Run service。像这样,私有范围(至少,您也可以路由所有传出流量)流量被路由到连接器并登陆您的 VPC。现在您可以访问您的 VPC 中的私有资源,例如您的 redis 实例。

【讨论】:

    猜你喜欢
    • 2023-01-26
    • 1970-01-01
    • 2020-03-18
    • 2022-07-08
    • 2019-12-08
    • 2019-07-01
    • 2019-04-01
    • 2020-08-03
    • 1970-01-01
    相关资源
    最近更新 更多