Node-redis: NOAUTH Authentication required error 即使设置了密码

创建于 2018-06-29  ·  18评论  ·  资料来源: NodeRedis/node-redis

  • 版本:节点 Redis 2.8.0 / Redis 4.0.9
  • 平台:Heroku-16 堆栈上的 NodeJS 8.11.3
  • 描述:我正在连接到 redis 并传递以下具有密码的选项对象,但 node_redis 总是抛出 NOAUTH 错误
options = {
   'auth_pass': nconf.get('redis_pass')[nodeEnv],
   'no_ready_check': true,
};

如果我使用redis-cli工具连接到 redis,它可以正常工作,但由于某种原因,我一直收到此错误

29 Jun 2018 11:06:14.626136 <190>1 2018-06-29T18:06:14.346750+00:00 app web.1 - - ReplyError: NOAUTH Authentication required
    at new Command (/app/node_modules/redis/lib/command.js:12:22)
    at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
    at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
    at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
    at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:10)Exception

最有用的评论

我这里也有这个问题。

错误信息: ReplyError: NOAUTH Authentication required.

版本:节点 Redis 3.0.0 / Redis 5.0.8

所有18条评论

仅从您的options对象很难分辨,但这是非常标准的并且众所周知。 如果我不得不打赌,您可能连接到错误的 redis 服务器或nconf.get('redis_pass')[nodeEnv]提供了错误的密码(或者可能未定义)。

你能提供更多的代码吗?

嗨,我有同样的问题,我将密码作为纯文本传递,它仍然给我发送同样的错误。 事实上,我只取消了默认 redis.conf 文件中的 requirepass 行的注释,如下面的代码所示:

# use a very strong password otherwise it will be very easy to break.
#
requirepass foobared

# Command renaming.

为了进行测试,我在本地机器上进行了此配置,但仍然遇到相同的错误:

events.js:160
      throw er; // Unhandled 'error' event
      ^
ReplyError: Ready check failed: NOAUTH Authentication required.
    at parseError (/home/mauricio/Documents/lisapp/pos_lisa/node_modules/redis/node_modules/redis-parser/lib/parser.js:193:12)
    at parseType (/home/mauricio/Documents/lisapp/pos_lisa/node_modules/redis/node_modules/redis-parser/lib/parser.js:303:14)

这是我在 nodejs 服务器中应用的代码:

const redisPassword = "foobared" ; 
const ClientRedisApi = redis.createClient({
          host : '127.0.0.1',  
          no_ready_check: true,
          auth_pass: redisPassword,                                                                                                                                                           
});                               

ClientRedisApi.on('connect', () => {   
          global.console.log("connected");
})                              

ClientRedisApi.on('error', err => {       
          global.console.log(err.message)
})                             

ClientRedisApi.set("foo", 'bar');         

ClientRedisApi.get("foo", function (err, reply) {
        global.console.log(reply.toString())
})

有趣的是,当我启动服务器时,键“foo”以值“bar”保存在我的 redis 数据库中,但我的应用程序崩溃了,我无法与之交互。

给这里的每一个人。 当我尝试使用由 Linux 随机密码生成器生成的长密码时,我遇到了同样的问题。 当我将密码更改为更短的密码时,一切正常。 这可能是这个 Node.JS 包本身的问题,因为如果我进入redis-cli并将其与auth命令一起使用,长密码确实有效。 但是,无论我使用什么方法变体(即 - 完整 URL,或选项块中的“auth_pass”/“password”,或redisClient.auth( )方法 - 他们都因长密码而失败)。

@roschler ,请您提供您的代码。 事实是,我尝试了您的建议,但我仍然遇到同样的问题,即使使用像“123”这样的密码也是如此。 我尝试了文档中的所有方法,没有什么不同。 我知道这可能会给您带来麻烦,但事实是我别无选择。 提前非常感谢。

@maooricio我 99.999% 确定这是服务器上的错误配置或错误的服务器。 查看您 2018 年 10 月的代码,我会尝试使用随机生成的密钥并在redis-cli中与 MONITOR 相呼应。

我认为@roschler有一个完全不同的问题(引用?)

我仍然遇到这个问题我已经尝试了很多不同的方法来连接我的 redis 数据库但是用户的密码验证失败

@nicolasmatheus你的错误是什么?

我有同样的错误。 我相信所有的设置参数都是正确的。 我已经尝试了所有 3 种方法,并且在所有方法中都出现了相同的错误。

      // First method
      const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
      client.auth(process.env.REDIS_PASSWORD);

      // Second method
      const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, {
        password: process.env.REDIS_PASSWORD
      });

      // Third method
      const client = redis.createClient(uri)

设置后NODE_DEBUG=redis

[0] Sending auth to redis:6379 id 0
[0] Send redis:6379 id 0: *2
[0] $4
[0] auth
[0] $14
[0] mypassword
[0]
[0] Stream connected redis:6379 id 0
[0] Redis: CONNECTED // CUSTOM MESSAGE
[0] Checking server ready state...
[0] Send redis:6379 id 0: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 0
[0] Redis server ready.
[0] on_ready called redis:6379 id 0
[0] Redis: READY // CUSTOM MESSAGE
[0] Stream connected redis:6379 id 1
[0] Checking server ready state...
[0] Send redis:6379 id 1: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 1
[0]
[0] /app/node_modules/redis/lib/command.js:12
[0]         this.error = new Error();
[0]                      ^
[0] ReplyError: NOAUTH Authentication required.
[0]     at new Command (/app/node_modules/redis/lib/command.js:12:22)
[0]     at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
[0]     at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
[0]     at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
[0]     at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
[0]     at Object.onceWrapper (events.js:299:28)
[0]     at Socket.emit (events.js:215:7)
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1115:10)
[0] npm ERR! code ELIFECYCLE

我正在使用 docker-compose

  redis:
    container_name: redis
    image: redis:5.0.3-alpine
    restart: always
    env_file: .env
    command: ["redis-server", "--appendonly", "yes", "--requirepass", "${REDIS_PASSWORD}"]
    hostname: ${REDIS_HOST}
    volumes:
      - ~/.mydata/redis:/data
    ports:
      - ${REDIS_PORT}:6379
    networks:
      - my-network

我可以使用 cli redis-cli -h 127.0.0.1 -p 6379 -a 'mypassword'访问 redis

@thellimist查看redis-cliMONITOR发生了什么,尤其是您的第二种方法。

@stockholmux

export default class Cache {
   static client: any

   static init(): Promise<any> {
      if (Cache.client) {
        logger.error("Client already exists")
        return new Promise((resolve, reject) => { reject() });
      }

      const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, {
        password: process.env.REDIS_PASSWORD
      });
      Cache.client = asyncRedis.decorate(client);
      Cache.client.monitor(function (err, res) {
        logger.info("Entering monitoring mode.");
      });
      Cache.client.set('foo', 'bar');

      Cache.client.on("ready", (e: any) => {
        logger.info(`ready ${e}`);
      });

      Cache.client.on("reconnecting", (e: any) => {
        logger.info(`reconnecting ${e}`);
      });

      Cache.client.on("end", (e: any) => {
        logger.info(`end ${e}`);
      });

      Cache.client.on("warning", (e: any) => {
        logger.info(`warning ${e}`);
      });

      Cache.client.on("monitor", (e: any, res: any) => {
        logger.error(`monitor err: ${e}`);
        logger.info(`monitor res: ${res}`);
      });

      Cache.client.on("connect", () => {
        logger.info("connected");
      });
      Cache.client.on("error", (e: any) => {
        logger.error(`Error: :${e}`);
      });

      return new Promise((resolve, reject) => { resolve() }
   }

我打电话给await Cache.init() 。 响应如下:

[0] Sending auth to redis:6379 id 0
[0] Send redis:6379 id 0: *2
[0] $4
[0] auth
[0] $14
[0] mypassword
[0]
[0] Queueing monitor for next server connection.
[0] Queueing set for next server connection.
[0] Stream connected redis:6379 id 0
[0] 2019-12-17 06:49:48 error [server.ts]: connected
[0] Checking server ready state...
[0] Send redis:6379 id 0: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 0
[0] Redis server ready.
[0] on_ready called redis:6379 id 0
[0] Sending offline command: monitor
[0] Send redis:6379 id 0: *1
[0] $7
[0] monitor
[0]
[0] Sending offline command: set
[0] Send redis:6379 id 0: *3
[0] $3
[0] set
[0] $3
[0] foo
[0] $3
[0] bar
[0]
[0] 2019-12-17 06:49:48 info [server.ts]: ready undefined
[0] Net read redis:6379 id 0
[0] 2019-12-17 06:49:48 info [server.ts]: Entering monitoring mode.
[0] 2019-12-17 06:49:48 error [server.ts]: monitor err: 1576565388.385183
[0] 2019-12-17 06:49:48 info [server.ts]: monitor res: set,foo,bar
[0] Stream connected redis:6379 id 1
[0] Checking server ready state...
[0] Send redis:6379 id 1: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 1
[0]
[0] /app/node_modules/redis/lib/command.js:12
[0]         this.error = new Error();
[0]                      ^
[0] ReplyError: NOAUTH Authentication required.
[0]     at new Command (/app/node_modules/redis/lib/command.js:12:22)
[0]     at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
[0]     at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
[0]     at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
[0]     at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
[0]     at Object.onceWrapper (events.js:299:28)
[0]     at Socket.emit (events.js:215:7)
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1115:10)

还将 key/val "foo: bar" 添加到 redis。 所以它最初连接正确,然后由于某种原因它尝试重新连接但失败。 我只在 express server.listen 中调用await Cache.init()一次。

@thellimist我认为您误解了-您需要运行MONITOR _from_ redis-cli才能正确诊断这些问题。 如上所述从您的应用程序中运行它不会捕获身份验证(因为它发生在 MONITOR 之前)。 我也会在完全刷新的数据库上运行它。

无论如何,看看你的代码(我假设它是一个片段),它看起来就像你在代码中的其他地方调用redis.createClient没有正确的密码(甚至可能是另一个模块)。 我没有看到重新连接的调试日志,并且id 1表示您正在处理不同的网络流。

@stockholmux

正如你所说,问题很简单。 我使用的是 typeorm 包,它有一个不同的配置文件,它不在 js/ts 文件中。 Node Redis loge 没有告诉我它是从哪里调用的,所以很难找到。

谢谢。

如果使用 Docker,请编辑 redis.conf 的文件网络设置:

bind 0.0.0.0

那为我修好了。

@mariothedev 对此要非常小心。 如果没有适当的防火墙,您的 redis 使用bind设置是完全开放的。

@stockholmux - 感谢您让我知道 :)

我这里也有这个问题。

错误信息: ReplyError: NOAUTH Authentication required.

版本:节点 Redis 3.0.0 / Redis 5.0.8

遇到这个线程寻找相同问题的答案。 想知道这个问题的解决方案是什么。

要添加到列表中的另一种可能的解决方案。 我遇到了这个错误,我花了很长时间才想起我正在使用Bull这是一个基于 Redis 的队列。 我还在应用程序的其他地方使用 Redis,我一直在传递连接信息,但忘记了 Bull 并且在控制台上得到了这些错误。

所以我想另一件要检查的事情是你的应用程序中是否有其他任何东西正在使用 Redis,并且可能会触发这些错误。

编辑如果是 Bull 为您导致此错误,则必须在您的 redis 连接对象中使用password ,而不是auth_pass

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

Stono picture Stono  ·  6评论

Alchemystic picture Alchemystic  ·  6评论

betimer picture betimer  ·  5评论

abhaygarg picture abhaygarg  ·  5评论

shmendo picture shmendo  ·  6评论