EC2内にRedisをインストールして、そのEC2の中にあるrailsアプリから動かそうとしていますが接続がうまくいかず、ログにRedis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL)):
と出てしまいます。
エラー文からみるに接続がうまくいっていないのだと思いますが、どのように解消すればいいのかが詰まっています。ご助言お願いいたします。下記に関係がありそうなファイルを記述しておきます。(REDISの生成処理も問題があるかもしれないと思ったので、redis.rbも置いておきます。)
production.rb
ruby
1require "active_support/core_ext/integer/time" 2 3Rails.application.configure do 4 # Settings specified here will take precedence over those in config/application.rb. 5 6 # Code is not reloaded between requests. 7 config.cache_classes = true 8 9 # Eager load code on boot. This eager loads most of Rails and 10 # your application in memory, allowing both threaded web servers 11 # and those relying on copy on write to perform better. 12 # Rake tasks automatically ignore this option for performance. 13 config.eager_load = true 14 15 # Full error reports are disabled and caching is turned on. 16 config.consider_all_requests_local = false 17 18 # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 19 # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 20 # config.require_master_key = true 21 22 # Disable serving static files from the `/public` folder by default since 23 # Apache or NGINX already handles this. 24 config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 25 26 # Enable serving of images, stylesheets, and JavaScripts from an asset server. 27 # config.asset_host = 'http://assets.example.com' 28 29 # Specifies the header that your server uses for sending files. 30 # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 31 # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 32 33 # Store uploaded files on the local file system (see config/storage.yml for options). 34 config.active_storage.service = :local 35 36 # Mount Action Cable outside main process or domain. 37 # config.action_cable.mount_path = nil 38 # config.action_cable.url = 'wss://example.com/cable' 39 # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] 40 41 # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 42 # config.force_ssl = true 43 44 # Include generic and useful information about system operation, but avoid logging too much 45 # information to avoid inadvertent exposure of personally identifiable information (PII). 46 config.log_level = :info 47 48 # Prepend all log lines with the following tags. 49 config.log_tags = [ :request_id ] 50 51 # Use a different cache store in production. 52 # config.cache_store = :mem_cache_store 53 54 # Use a real queuing backend for Active Job (and separate queues per environment). 55 # config.active_job.queue_adapter = :resque 56 # config.active_job.queue_name_prefix = "api_practice_production" 57 58 config.action_mailer.perform_caching = false 59 60 # Ignore bad email addresses and do not raise email delivery errors. 61 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 62 # config.action_mailer.raise_delivery_errors = false 63 64 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 65 # the I18n.default_locale when a translation cannot be found). 66 config.i18n.fallbacks = true 67 68 # Send deprecation notices to registered listeners. 69 config.active_support.deprecation = :notify 70 71 # Log disallowed deprecations. 72 config.active_support.disallowed_deprecation = :log 73 74 # Tell Active Support which deprecation messages to disallow. 75 config.active_support.disallowed_deprecation_warnings = [] 76 77 # Use default logging formatter so that PID and timestamp are not suppressed. 78 config.log_formatter = ::Logger::Formatter.new 79 80 config.session_store :redis_store, servers: 'redis://localhost:6379/0', expire_in: 7.day 81 82 # Use a different logger for distributed setups. 83 # require "syslog/logger" 84 # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 85 86 if ENV["RAILS_LOG_TO_STDOUT"].present? 87 logger = ActiveSupport::Logger.new(STDOUT) 88 logger.formatter = config.log_formatter 89 config.logger = ActiveSupport::TaggedLogging.new(logger) 90 end 91 92 # Do not dump schema after migrations. 93 config.active_record.dump_schema_after_migration = false 94 95 # Inserts middleware to perform automatic connection switching. 96 # The `database_selector` hash is used to pass options to the DatabaseSelector 97 # middleware. The `delay` is used to determine how long to wait after a write 98 # to send a subsequent read to the primary. 99 # 100 # The `database_resolver` class is used by the middleware to determine which 101 # database is appropriate to use based on the time delay. 102 # 103 # The `database_resolver_context` class is used by the middleware to set 104 # timestamps for the last write to the primary. The resolver uses the context 105 # class timestamps to determine how long to wait before reading from the 106 # replica. 107 # 108 # By default Rails will store a last write timestamp in the session. The 109 # DatabaseSelector middleware is designed as such you can define your own 110 # strategy for connection switching and pass that into the middleware through 111 # these configuration options. 112 # config.active_record.database_selector = { delay: 2.seconds } 113 # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver 114 # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session 115end
settings.yml
session: url: redis://localhost:6379 timeout: 7200
initializers/redis.rb
ruby
1if Rails.env.test? 2 REDIS = MockRedis.new 3else 4 REDIS = Redis.new(url: Settings.session.url) 5end
redis.confの内容
protected-mode no port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 ################################# GENERAL ##################################### daemonize no supervised no pidfile /var/run/redis_6379.pid loglevel notice logfile /var/log/redis/redis.log databases 16 always-show-logo yes ################################ SNAPSHOTTING ################################ save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir /var/lib/redis ################################# REPLICATION ################################# slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 ############################# LAZY FREEING #################################### lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no ############################## APPEND ONLY MODE ############################### appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble no ################################ LUA SCRIPTING ############################### lua-time-limit 5000 ################################## SLOW LOG ################################### slowlog-log-slower-than 10000 # There is no limit to this length. Just be aware that it will consume memory. # You can reclaim memory used by the slow log with SLOWLOG RESET. slowlog-max-len 128 ################################ LATENCY MONITOR ############################## latency-monitor-threshold 0 ############################# EVENT NOTIFICATION ############################## notify-keyspace-events "" ############################### ADVANCED CONFIG ############################### hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
sudo systemctl status redisで出力された内容
● redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled) Drop-In: /etc/systemd/system/redis.service.d └─limit.conf Active: inactive (dead)
回答1件
あなたの回答
tips
プレビュー