【问题标题】:Redis master/slave setup on Kubernetes throwing error: BRPOPLPUSH { ReplyError: MOVED 2651Kubernetes 上的 Redis 主/从设置抛出错误:BRPOPLPUSH { ReplyError: MOVED 2651
【发布时间】:2019-05-20 05:39:07
【问题描述】:

我正在使用基于 Redis 的出色 Bull.js 作为 Kubernetes 上的作业队列。

它被配置为一个集群:

当 Kubernetes 在部署时重新启动时,我遇到了以下错误:

BRPOPLPUSH { ReplyError: MOVED 2651 <IP_ADDRESS>:6379
at parseError (/usr/src/app/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (/usr/src/app/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:302:14)
command:
{ name: 'brpoplpush',
args:
[ '{slack}:slack notifications:wait',
'{slack}:slack notifications:active',
'5' ] } }

&lt;IP_ADDRESS&gt; 在哪里,我认为集群 IP?我没有配置这个,但我正在尝试调试它。我想知道是否需要为 Bull.js 启用集群模式,或者这是否是 Bull.js 项目之外的配置问题?

还是 K8s 的网络问题?

启用:https://github.com/OptimalBits/bull#cluster-support 会是解决方案吗?这是正确的方法吗?

这是我的代码:

import Queue from 'bull';
import config from 'config';
import { run as slackRun } from './tasks/send-slack-message';
import { run as emailRun } from './tasks/send-email';

const redisConfig = {
  redis: {
    host: config.redis.host,
    port: config.redis.port
  }
};

const slackQueue = new Queue('slack notifications', { ...redisConfig, ...{ prefix: '{slack}' } });
const emailQueue = new Queue('email notifications', { ...redisConfig, ...{ prefix: '{email}' } });

slackQueue.process(slackRun);
emailQueue.process(emailRun);

emailQueue.on('completed', (job, result) => {
  job.remove();
});

export { emailQueue, slackQueue };
import { emailQueue, slackQueue } from 'worker/worker';

const queueOptions = {
  attempts: 2,
  removeOnComplete: true,
  backoff: {
    type: 'exponential',
    delay: 60 * 1000
  }
};

emailQueue.add(
  {
    params: {
      from: email,
      fromname: name,
      text: body
    }
  },
  queueOptions
);
slackQueue.add(
  {
    channelId: SLACK_CHANNELS.FEEDBACK,
    attachments: [
      {
        text: req.body.body
      }
    ]
  },
  queueOptions
);

这是配置图:

Name:         redis-cluster-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
update-node.sh:
----
#!/bin/sh
REDIS_NODES="/data/nodes.conf"
sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${REDIS_NODES}
exec "$@"

redis.conf:
----
cluster-enabled yes
cluster-require-full-coverage no
cluster-node-timeout 15000
cluster-config-file nodes.conf
cluster-migration-barrier 1
appendonly yes
# Other cluster members need to be able to connect
protected-mode no

Events:  <none>

【问题讨论】:

  • 你在使用 helm chart 来设置 redis 吗?
  • 不使用舵图。
  • @bob_cobb,我敢打赌这是 ioredis 问题。所以值得尝试使用主从设置。
  • bull code,默认是做普通的Redis客户端。我认为如果您通过 createClient 选项来使 ioredis Cluster 对象改为连接,您可以修复它。以here 为例

标签: kubernetes redis bull.js


【解决方案1】:

Hitobat 是对的。

如果这没有帮助:

const Redis = require('ioredis');
...
const ioCluster = new Redis.Cluster([redisConfig.redis]);
const slackQueue = new Queue('slack notifications', {
  prefix: '{slack}' ,
  createClient: () => ioCluster
});
const emailQueue = new Queue('email notifications', {
  prefix: '{email}' ,
  createClient: () => ioCluster
});

我会不使用 ioredis 或尝试将 redis 引擎降级到 4.x。

【讨论】:

  • typescript 抛出 Queue 不接受 Redis.Cluster 的错误(我们应该传递 Redis 实例)
猜你喜欢
  • 1970-01-01
  • 2017-08-29
  • 1970-01-01
  • 2022-10-20
  • 1970-01-01
  • 2018-10-20
  • 1970-01-01
  • 2019-12-19
  • 2014-12-16
相关资源
最近更新 更多