Ruby-on-rails Redis 引发错误:需要 NOAUTH 身份验证但没有密码设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34115213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:19:14  来源:igfitidea点击:

Redis raise error: NOAUTH Authentication required but there is no password setting

ruby-on-railsruby-on-rails-4redissidekiq

提问by Thanh

I got error NOAUTH Authentication requiredwhen I connect to Redis server via command: redis-cliand run pingto check if Redis is working.

当我通过命令连接到 Redis 服务器时,我收到错误NOAUTH Authentication requiredredis-cli并运行ping以检查 Redis 是否正常工作。

I found answer for NOAUTH Authentication required errorwhich describes that this error only happens when Redis is set a password, but I checked Redis config file at etc/redis/redis.confand there is no password setting.

我找到了 NOAUTH Authentication required 错误的答案,它描述了此错误仅在 Redis 设置密码时发生,但我检查了 Redis 配置文件,etc/redis/redis.conf但没有设置密码。

Redis config

Redis 配置

Does anyone know that if there are other settings which can cause this error? Thanks for any help.

有谁知道是否还有其他设置会导致此错误?谢谢你的帮助。

p/s: I am using Ruby on Rails web framework, Redis database is used for Sidekiq.

p/s:我使用 Ruby on Rails 网络框架,Redis 数据库用于 Sidekiq。

Edited: Redis version is 2.8.4. Server is hosted on AWS.

编辑:Redis 版本是 2.8.4。服务器托管在 AWS 上。

Currently, I decided to set a password for Redis server so that it can not be set password when it is running.

目前,我决定为Redis服务器设置密码,使其在运行时无法设置密码。

(When Redis server is restarted, it will work normal. You can run sudo service redis-server restartto restart Redis server.)

(重启Redis服务器后会正常工作,可以运行sudo service redis-server restart重启Redis服务器。)

回答by Ashutosh Agrawal



We also faced a similar issue. Looks like someone went and scanned AWS and connected to all public redis and possibly ran "CONFIG SET REQUIREPASS ''", thus locking down the running instance of redis. Once you restartthe redis, the config is restored to normal.

我们也遇到了类似的问题。看起来有人去扫描了 AWS 并连接到所有公共 redis 并可能运行了“CONFIG SET REQUIREPASS ''”,从而锁定了正在运行的 redis 实例。一旦你重新启动Redis的,在配置恢复到正常状态。

Best thing would be to use AWS security group policy and block port 6379for public.

最好的办法是使用 AWS 安全组策略并阻止公共端口 6379

回答by haren

I had the same issue (running on AWS) and discovered our redis port was exposed. You probably had the same. Someone was messing around.

我遇到了同样的问题(在 AWS 上运行)并发现我们的 redis 端口被暴露了。你可能也有同样的经历。有人在捣乱。

EDIT: The solution: reset your redis passwordand then (assuming you have it running as a service) restart the service providing the new password

编辑:解决方案:重置您的 redis 密码,然后(假设您将其作为服务运行)重新启动提供新密码的服务

回答by Justin Lee

Had the exact same problem running Redis on an AWS instance. I would restart redis-server without any password requirements (#requirepass ''), would work fine for a few hours, then would throw "NOAUTH Authentication required" and eventually would have to restart redis-server.

在 AWS 实例上运行 Redis 时遇到了完全相同的问题。我会在没有任何密码要求(#requirepass '')的情况下重新启动 redis-server,可以正常工作几个小时,然后会抛出“需要 NOAUTH 身份验证”并最终不得不重新启动 redis-server。

Checked the Security Groups settings in AWS for the instance and saw port 6379 open to the public (0.0.0.0/0). We limited the port access to our only server that needs to access and haven't seen the issue come up ever since!

检查 AWS 中实例的安全组设置,看到端口 6379 向公众开放 (0.0.0.0/0)。我们将端口访问限制在我们唯一需要访问的服务器上,从那以后就再也没有出现过这个问题!

P.S. This is my first ever contribution to StackOverflow. Thanks for the help!

PS 这是我对 StackOverflow 的第一次贡献。谢谢您的帮助!

回答by Son Nguyen

I Have the same problem. after that I'm set requirepassfor the redisserver.
And add that password in initializer/redis.rb

我也有同样的问题。之后,我requirepassredis服务器设置了。
并添加该密码initializer/redis.rb

$redis = Redis.new(:password=>"****") 

It works fine

它工作正常

回答by Akhil Sharma

If you have made any changes in configuration file then don't forget to restart redis service with sudo service redis-server restartcommand.

如果您对配置文件进行了任何更改,请不要忘记使用sudo service redis-server restart命令重新启动 redis 服务。

Edit:If you are running redis service in production mode then redis requires password to run. For that you need to set password in your config file present at /etc/redis.

编辑:如果您在生产模式下运行 redis 服务,那么 redis 需要密码才能运行。为此,您需要在 .config 文件中的配置文件中设置密码/etc/redis

You need to set requirepass *******in that file under ########### SECURITY ############section.

您需要requirepass *******在该文件下进行设置########### SECURITY ############

Then restart your server sudo service redis-server restart.

然后重新启动您的服务器sudo service redis-server restart

After that add that password in your config or initializer file where you have set your hostname and port. Example:

之后,在您设置主机名和端口的配置或初始值设定项文件中添加该密码。例子:

$redis = Redis.new(:host => 'localhost', :port => 6379, :password => "*******")

$redis = Redis.new(:host => 'localhost', :port => 6379, :password => "*******")

回答by fangxing

I Have the same problem, I found it's caused by someone started redis by another redis.cnfconfigure file, So I stoped redis-server and then started redis-server specify a configure file.

我有同样的问题,我发现它是由另一个redis.cnf配置文件启动redis引起的,所以我停止redis-server然后启动redis-server指定一个配置文件。

redis-server /etc/redis.cnf

Then every thing works fine.

然后一切正常。