我一直在尝试在Ubuntu上使用Mongoid和Rails。Mongodb在我的rails应用3.0到3.2上运行得很好,
今天突然,我收到错误"/home/pravinmishra/.rvm/gems/ruby-1.9.2-p318/gems/mongo-1.5.2/lib/mongo/connection.rb:413:in‘connect’:无法连接到本地主机上的主节点:27017 (Mongo::ConnectionFailure)“
很多时候我都会遇到这个问题,下面的命令对我很有效。
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo start mongodb
sudo status mongodb 但今天我没那么走运。
前几天,我更改了etc/hosts文件,并添加了27.0.0.1 localhost.me
127.0.0.1 localhost.me:3000 localhost ubuntu
127.0.0.1 localhost
127.0.1.1 ubuntu
127.0.0.1 localhost.me locahost ubuntu我想,这个产生的问题。为了克服这个问题,我将本地主机文件更改为连接,但仍然收到错误"/home/pravinmishra/.rvm/gems/ruby-1.9.2-p318/gems/mongo-1.5.2/lib/mongo/connection.rb:413:in‘localhost.me’:无法连接到localhost.me:27017处的主节点(Mongo::ConnectionFailure)“
mongoid.yml文件
defaults: &defaults
host: localhost
allow_dynamic_fields: false
development:
<<: *defaults
database: xxx_development
test:
<<: *defaults
database: xxx_test
# set these environment variables on your prod server
production:
# host: <%= ENV['MONGOID_HOST'] %>
# port: <%= ENV['MONGOID_PORT'] %>
# username: <%= ENV['MONGOID_USERNAME'] %>
# password: <%= ENV['MONGOID_PASSWORD'] %>
# database: <%= ENV['MONGOID_DATABASE'] %>
# set these environment variables on your prod server
production:
uri: <%= ENV['MONGOHQ_URL'] %>任何建议都将不胜感激,提前谢谢.!!
发布于 2012-07-10 01:07:04
您的/etc/hosts文件已损坏
27.0.0.1 localhost.me:3000 localhost ubuntulocalhost位于127.0.0.1,而不是27.0.0.1hosts视为本地DNS覆盖。因为Mongoid为运行的MongoDB查看27.0.0.1,所以它找不到一个。并且连接失败。
https://stackoverflow.com/questions/11399340
复制相似问题