Mongoid 生产问题:无法连接到主节点
我已经从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设“记录的 mongoid 方法”是指设置推荐的“uri”参数,而不是所有这些不同的设置。您可能想尝试一下,因为这是推荐的方法。
请注意,我确实使用 Heroku,但不使用 MongoHQ 插件。我只是直接使用它,所以我手动设置了我的MONGOHQ_URL。您的 uri 看起来像这样:
在我看来,您无法根据错误连接到“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.
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:
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.