Mongoid 生产问题:无法连接到主节点

发布于 2024-12-05 17:31:56 字数 1020 浏览 0 评论 0原文

我已经从 Mongo_Mapper 切换到 Mongoid,但由于某种原因,在部署到生产环境时遇到了麻烦。我正在使用 NGINX、Rails 3.1 和 Passenger。我不断收到此消息“无法连接到位于 myusernamehere:27017 (Mongo::ConnectionFailure) 的主节点”。

  defaults: &defaults
  host: localhost
  # slaves:
  #   - host: slave1.local
  #     port: 27018
  #   - host: slave2.local
  #     port: 27019

  development:
    <<: *defaults
    database: s3uploadergen_development

  test:
    <<: *defaults
    database: s3uploadergen_test

  production:
    host: localhost
    port: 27017
    database: mydbnamehere
    username: myuserhere
    password: mypasswordhere

我已经对所有设置进行了三重检查,并尝试了 ENV 方法(将 ENV 变量添加到 production.rb 并通过记录的 mongoid 方法调用它们,但遇到了相同的问题):

production:
  host: <%= ENV['MONGOID_HOST'] %>
  port: <%= ENV['MONGOID_PORT'] %>
  username: <%= ENV['MONGOID_USERNAME'] %>
  password: <%= ENV['MONGOID_PASSWORD'] %>
  database: <%= ENV['MONGOID_DATABASE'] %>

理想情况下,我只想在生产中指定它.rb 或某种初始化程序。

I've switched away from Mongo_Mapper to Mongoid and am having trouble deploying to production, for some reason. I'm using NGINX, Rails 3.1, and Passenger. I keep getting this message, "Failed to connect to a master node at myusernamehere:27017 (Mongo::ConnectionFailure)".

  defaults: &defaults
  host: localhost
  # slaves:
  #   - host: slave1.local
  #     port: 27018
  #   - host: slave2.local
  #     port: 27019

  development:
    <<: *defaults
    database: s3uploadergen_development

  test:
    <<: *defaults
    database: s3uploadergen_test

  production:
    host: localhost
    port: 27017
    database: mydbnamehere
    username: myuserhere
    password: mypasswordhere

I've triple-checked all settings and tried the ENV approach as well (adding the ENV variables to production.rb and calling them via the documented mongoid approach but had the same issue):

production:
  host: <%= ENV['MONGOID_HOST'] %>
  port: <%= ENV['MONGOID_PORT'] %>
  username: <%= ENV['MONGOID_USERNAME'] %>
  password: <%= ENV['MONGOID_PASSWORD'] %>
  database: <%= ENV['MONGOID_DATABASE'] %>

Ideally, I want to just specify it either in production.rb or an initializer of some sort.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唐婉 2024-12-12 17:31:56

我假设“记录的 mongoid 方法”是指设置推荐的“uri”参数,而不是所有这些不同的设置。您可能想尝试一下,因为这是推荐的方法。

defaults: &defaults
  persist_in_safe_mode: true

development:
  <<: *defaults
  host: localhost
  database: app_development

test:
  <<: *defaults
  host: localhost
  database: app_test

production:
  <<: *defaults
  uri: <%= ENV['MONGOHQ_URL'] %>

请注意,我确实使用 Heroku,但不使用 MongoHQ 插件。我只是直接使用它,所以我手动设置了我的MONGOHQ_URL。您的 uri 看起来像这样:

mongodb://<user>:<password>@<the.db.host.com>:<port>/<database_name>

在我看来,您无法根据错误连接到“localhost”(就像您可能需要完整的主机名或 IP 或其他内容?)。您的应用程序日志中有什么内容吗?

只需确保不要在任何 ENV 上设置“host”和“uri”,因为“host”将覆盖从 uri 派生的设置。

I'm assuming that by "documented mongoid approach" you mean setting the recommended "uri" param instead of all those different setttings. You might want to try it since it's the recommended way of doing it.

defaults: &defaults
  persist_in_safe_mode: true

development:
  <<: *defaults
  host: localhost
  database: app_development

test:
  <<: *defaults
  host: localhost
  database: app_test

production:
  <<: *defaults
  uri: <%= ENV['MONGOHQ_URL'] %>

Note that I do use Heroku but I don't use the MongoHQ add on. I just use it directly, so I manually set my MONGOHQ_URL. Your uri would look something like:

mongodb://<user>:<password>@<the.db.host.com>:<port>/<database_name>

Looks to me like you can't connect to "localhost" based on the error (like maybe you need the full host name or IP or something?). Anything in your app logs?

Just make sure not to set "host" and "uri" on any of the ENV's because "host" will override the setting that is derived from the uri.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文