首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >码头工人-使用redis,sidekiq,rails撰写

码头工人-使用redis,sidekiq,rails撰写
EN

Stack Overflow用户
提问于 2021-10-12 11:59:43
回答 2查看 630关注 0票数 2

我对我的坞-撰写配置中的错误感到困惑。我在现有的rails应用程序中添加了redis,它使用的是docker,但我在试图让容器之间进行通信时失败了。我尝试了几个不同的选择,并研究了几乎每一个合理的主题,因此,涉及这个问题,但我一直失败,基本上相同的事情。下面是我当前的配置(或至少它的相关部分,)和错误:

docker-compose.yml

代码语言:javascript
复制
services:
  web:
    <<: *common-settings
    build:
      context: .
      dockerfile: docker/development/Dockerfile
      target: web
    command: dumb-init bash -c "(bundle check || bundle install) && rails s -b 0.0.0.0 -p 3000"
    depends_on:
      - db
      - redis
      - elasticsearch
    ports:
      - '3000:3000'
    expose:
      - 3000
 

  redis:
    image: 'redis:5-alpine'
    ports:
      - '6379:6379'
    volumes:
      - 'redis:/data'

  sidekiq:
    depends_on:
      - db
      - redis
      - web
    build: .
    command: bundle exec sidekiq
    volumes:
      - .:/app:cached
      - bundle:/bundle
    env_file:
      - ./.env

config/initializers/sidekiq.rb kiq.rb

代码语言:javascript
复制
Sidekiq.configure_server do |config|
  config.redis = { url: 'redis://redis:6379/12' }
end

Sidekiq.configure_client do |config|
  config.redis = { url: 'redis://redis:6379/12' }
end

是的,这是目前公开的硬编码,但是我尝试过使用ENV变量,结果是完全相同的,不管我从哪里得到的结果是相同的。现在就试试这样的东西,因为这没什么区别。

下面是当我试图访问localhost:3000/sidekiq时出现的错误

代码语言:javascript
复制
Error connecting to Redis on redis:6379 (SocketError)
Application Trace | Framework Trace | Full Trace
redis (4.4.0) lib/redis/client.rb:384:in `rescue in establish_connection'
redis (4.4.0) lib/redis/client.rb:365:in `establish_connection'
redis (4.4.0) lib/redis/client.rb:117:in `block in connect'
redis (4.4.0) lib/redis/client.rb:330:in `with_reconnect'
redis (4.4.0) lib/redis/client.rb:116:in `connect'
redis (4.4.0) lib/redis/client.rb:403:in `ensure_connected'
redis (4.4.0) lib/redis/client.rb:255:in `block in process'
redis (4.4.0) lib/redis/client.rb:342:in `logging'
redis (4.4.0) lib/redis/client.rb:254:in `process'
redis (4.4.0) lib/redis/client.rb:148:in `call'
redis (4.4.0) lib/redis.rb:307:in `block in info'
redis (4.4.0) lib/redis.rb:70:in `block in synchronize'
/usr/local/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
redis (4.4.0) lib/redis.rb:70:in `synchronize'
redis (4.4.0) lib/redis.rb:306:in `info'
sidekiq (6.2.2) lib/sidekiq.rb:120:in `block in redis_info'
sidekiq (6.2.2) lib/sidekiq.rb:98:in `block in redis'
connection_pool (2.2.5) lib/connection_pool.rb:63:in `block (2 levels) in with'
connection_pool (2.2.5) lib/connection_pool.rb:62:in `handle_interrupt'
connection_pool (2.2.5) lib/connection_pool.rb:62:in `block in with'
connection_pool (2.2.5) lib/connection_pool.rb:59:in `handle_interrupt'
connection_pool (2.2.5) lib/connection_pool.rb:59:in `with'
sidekiq (6.2.2) lib/sidekiq.rb:95:in `redis'
sidekiq (6.2.2) lib/sidekiq.rb:114:in `redis_info'
sidekiq (6.2.2) lib/sidekiq/web/helpers.rb:177:in `redis_info'
.
.
.

当我试图从web应用程序运行一个工作人员或使用bundle exec sidekiq时,也会发生同样的错误。

下面是我运行docker-compose up时注销的内容

代码语言:javascript
复制
redis_1          | 1:C 12 Oct 2021 11:44:19.103 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo                                                                                                                                                                                                                                                        
redis_1          | 1:C 12 Oct 2021 11:44:19.103 # Redis version=5.0.14, bits=64, commit=00000000, modified=0, pid=1, just started                                                                                                                                                                                                                      
redis_1          | 1:C 12 Oct 2021 11:44:19.103 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf                                                     
redis_1          | 1:M 12 Oct 2021 11:44:19.105 * Running mode=standalone, port=6379.                                                                                                                                                                                                                                                                  
redis_1          | 1:M 12 Oct 2021 11:44:19.105 # Server initialized                                                                                                                                                                                                                                                                                   
redis_1          | 1:M 12 Oct 2021 11:44:19.105 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1          | 1:M 12 Oct 2021 11:44:19.105 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain 
the setting after a reboot. Redis must be restarted after THP is disabled.                                                                                                                                                                                                                                                                             
redis_1          | 1:M 12 Oct 2021 11:44:19.105 * DB loaded from disk: 0.000 seconds                                                                                                                                                                                                                                                                   
redis_1          | 1:M 12 Oct 2021 11:44:19.106 * Ready to accept connections              
代码语言:javascript
复制
sidekiq_1        | 2021-10-12T11:44:26.712Z pid=1 tid=ouccdy1p5 INFO: Booting Sidekiq 6.2.2 with redis options {:url=>"redis://redis:6379/12"}
sidekiq_1        | 2021-10-12T11:44:27.174Z pid=1 tid=ouccdy1p5 INFO: Booted Rails 5.2.6 application in development environment
sidekiq_1        | 2021-10-12T11:44:27.174Z pid=1 tid=ouccdy1p5 INFO: Running in ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux-musl]
sidekiq_1        | 2021-10-12T11:44:27.174Z pid=1 tid=ouccdy1p5 INFO: See LICENSE and the LGPL-3.0 for licensing details.
sidekiq_1        | 2021-10-12T11:44:27.174Z pid=1 tid=ouccdy1p5 INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org

至于使用ENV变量,我通常尝试在.env文件中设置这样的值

代码语言:javascript
复制
REDIS_URL=redis://redis:6379/12

当我检查码头ps时,红色集装箱通常在那里。如果我正确理解,URL redis://redis:6379/12使用redis作为主机的名称,它对应于我在docker-come.yml中指定的服务的名称,并且应该允许容器相互交谈。这个文件最初有更多的服务,比如elasticsearch,它们工作得很好。

我试过好几种不同的装置,但我觉得我的头撞到了跌倒的地方。我遗漏了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-10-14 10:16:15

结果我漏掉了配置的一个重要细节

代码语言:javascript
复制
networks:
  app:

加后

代码语言:javascript
复制
    networks:
      - app

对于瑞迪斯和塞德基克来说,一切都能很好地交谈。

票数 0
EN

Stack Overflow用户

发布于 2021-10-13 20:17:14

您可能没有将redis端口公开给sidekiq服务,尝试在docker组合中公开这一点。这也许能行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69540161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档