【问题标题】:Resque to connect to Redis with AUTHResque 使用 AUTH 连接到 Redis
【发布时间】:2013-04-26 10:01:46
【问题描述】:

需要帮助将 Resque Web UI (Rack config.ru) 连接到具有 AUTH 的 Redis 服务器

使用 Resque + Unicorn + Nginx 并使用 apt-get install (Debian) 和 gem install 进行安装

所以基本上 Unicorn 使用标准 config.ru 加载 resque-web(通过 Rack)

http://etagwerker.wordpress.com/2011/06/27/how-to-setup-resque-web-with-nginx-and-unicorn/

#!/usr/bin/env ruby

# Put this in /var/www/resque-web/config.ru

require 'logger'

$LOAD_PATH.unshift ::File.expand_path(::File.dirname(__FILE__) + '/lib')
require 'resque/server'

Resque::Server.use Rack::Auth::Basic do |username, password|
    password == '{{password}}' # password
end

# Set the RESQUE_CONFIG env variable if you’ve a `resque.rb` or similar
# config file you want loaded on boot.
if ENV['RESQUECONFIG'] && ::File.exists?(::File.expand_path(ENV['RESQUE_CONFIG']))
    load ::File.expand_path(ENV['RESQUE_CONFIG'])
end

use Rack::ShowExceptions
run Resque::Server.new  

我正在尝试根据此处的文档了解如何使用 AUTH 将其连接到 Redis 服务器:http://redis.io/topics/security(基本上在 /etc/redis/redis.conf 中)

此机架配置似乎仅使用默认值(具有标准 6379 端口的本地主机)连接到“香草”Redis 服务器——如何指定 Redis 连接,以便我可以通过以下格式传递用户/密码

redis://user:PASSWORD@redis-server:6379

我尝试使用 ENV['RESQUE_CONFIG'] 加载 resque.rb 文件

需要'resque'

Resque.redis = Redis.new(:password => '{{password}}')

这是通过 /etc/unicorn/resque-web.conf 获取的

# Put this in /etc/unicorn/resque-web.conf

RAILS_ROOT=/var/www/resque-web
RAILS_ENV=production
RESQUE_CONFIG=/var/www/resque-web/config/resque.rb

但它仍然没有真正工作


顺便说一句,一切都可以在没有 Redis AUTH 的情况下运行,并且只使用“vanilla”本地主机 Redis 连接

【问题讨论】:

    标签: redis resque


    【解决方案1】:

    试试这个

    redis_client = Redis.new(:url => "redis://user:PASSWORD@redis-server:6379")
    

    然后这样做

    Resque.redis = redis_client
    

    希望有帮助

    【讨论】:

    • 我应该在哪里做这个?在 config.ru 里面?
    • @ChrisGo 如果您使用 resque 的 Rails 环境只需在 config/application.rb 中定义上述内容,resque-web 将按预期工作,因为内部 resque-web 使用 redis 连接获取 resque
    • 感谢 Viren 的回复,我使用 sudo gem install resque 似乎找不到 config/application.rb ... 通常在您自己的应用程序中,它只是在您的目录结构中,但是不确定 gem install 将这些文件放在哪里...
    • Viren,谢谢,我想通了。在 config.ru(被独角兽拉取的机架文件)中,我必须做Resque.redis = Redis.new(:password => 'password')
    • 也可以通过resque.yml配置文件配置Redis访问密码,例如:development: 'redis://user:password@host:port/database'。然后:Resque.redis = YAML.load_file(...)[RACK_ENV]
    猜你喜欢
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 2022-08-03
    相关资源
    最近更新 更多