如何设置mongod --dbpath [英] how to set mongod --dbpath

查看:290
本文介绍了如何设置mongod --dbpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于mongodb和数据库而言,这通常是全新的.每当我运行mongo时,我都会收到以下错误消息:

very new to mongodb and databases in general. whenever i run mongo i receive this error message: ​​​

MongoDB shell version: 2.4.9
connecting to: test
Thu Jan 30 13:03:33.170 Error: couldn't connect to server 127.0.0.1:27017 
at src/mongo/shell/mongo.js:145
exception: connect failed

运行mongod我看到了:

Thu Jan 30 13:13:36.588 [initandlisten] MongoDB starting : pid=29408 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Kimis-MacBook-Air-2.local
Thu Jan 30 13:13:36.588 [initandlisten] 
Thu Jan 30 13:13:36.588 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jan 30 13:13:36.588 [initandlisten] db version v2.4.9
Thu Jan 30 13:13:36.588 [initandlisten] git version: nogitversion
Thu Jan 30 13:13:36.588 [initandlisten] build info: Darwin minilionvm.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jan 30 13:13:36.588 [initandlisten] allocator: tcmalloc
Thu Jan 30 13:13:36.588 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb" }
Thu Jan 30 13:13:36.591 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Thu Jan 30 13:13:36.591 [initandlisten] recover begin
Thu Jan 30 13:13:36.591 [initandlisten] recover lsn: 108155770
Thu Jan 30 13:13:36.591 [initandlisten] recover /usr/local/var/mongodb/journal/j._0
Thu Jan 30 13:13:36.591 [initandlisten] journal file version number mismatch got:4147 expected:4149. if you have just upgraded, recover with old version of mongod, terminate cleanly, then upgrade.
Thu Jan 30 13:13:36.592 [initandlisten] dbexception during recovery: 13536 journal version number mismatch 16711
Thu Jan 30 13:13:36.592 [initandlisten] exception in initAndListen: 13536 journal version number mismatch 16711, terminating
Thu Jan 30 13:13:36.592 dbexit: 
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close listening sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to flush diaglog...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: lock for final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: closing all files...
Thu Jan 30 13:13:36.592 [initandlisten] closeAllFiles() finished
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: removing fs lock...
Thu Jan 30 13:13:36.592 dbexit: really exiting now

当我手动将mongo dpath设置为mongod --dbpath /data/db时(应该是安装时的默认值),并使它在终端中运行,一切正常.但是一旦我关闭它,一切都会再次崩溃.我的问题是:

when i manually set my mongo dpath to mongod --dbpath /data/db (as should be the default on installation) and keep it running in terminal everything runs fine. but once i close it, everything breaks again. my question is:

  1. 为什么我的dbpath设置为/usr/local/var/mongodb?
  2. 我如何解决此错误,以便mongo在我的计算机上正常工作?

我假设我需要将dbpath永久设置为/data/db或重新配置某些内容,以便它与dbpath一起使用,作为/usr/local/var/mongodb

i'm assuming i either need to permanently set the dbpath to /data/db or reconfigure something so it works with the dbpath as /usr/local/var/mongodb

我对Unix命令也很陌生,因此不能完全确定如何解决此错误.

i fairly new to unix commands as well so not entirely sure how to fix this error.

感谢您的任何建议!

因此,我在阅读mongodb文档时会读到以下内容:

so, digging through the mongodb documentation i read this:

"除非指定,否则mongod会在默认的/data/db目录中查找数据文件.(Windows系统使用\ data \ db目录.)如果使用软件包管理系统进行安装.请检查由提供的/etc/mongodb.conf文件您的软件包以查看dbpath的配置."

"Unless specified, mongod will look for data files in the default /data/db directory. (Windows systems use the \data\db directory.) If you installed using a package management system. Check the /etc/mongodb.conf file provided by your packages to see the configuration of the dbpath."

当我查看/etc/中的文件时,没有mongodb.conf文件...但是,我确实看到了/usr/local/etc/mongod.conf ...,因此,如果我正确理解这一点,我应该创建一个名为/etc/mongodb.conf,并将dbpath设置为/data/db.

when i took a look at the files within /etc/ there is no mongodb.conf file... however, i do see /usr/local/etc/mongod.conf... so if i understand this correctly, i should create a file called /etc/mongodb.conf and set the dbpath to /data/db.

我还需要删除/usr/local/中的内容吗?

do i need to delete the stuff within /usr/local/ as well?

我认为这与我的PATH的设置有关...有人可以向我解释如何在Unix中修复此问题,这样我就不会遇到这个问题了?

i think this has something to do with how my PATH are setup... could someone explain to me how to fix this in unix so i won't have this problem?

再次感谢!

推荐答案

首先,您将在/etc/mongodb.conf中拥有一个配置文件,因此,这听起来像是自制安装,它将使用一些更标准的路径.整个/data/db/内容都在许多手动安装文档.

First you will have a config file in /etc/mongodb.conf, therefore this sounds like a homebrew install which will use some more standardized paths. The whole /data/db/ thing is referenced in a lot of manual install documentation.

因此,从您的日志来看,服务器基本上没有在运行,它正在关闭,因此没有任何要连接的外壳程序.好像您进行了一些不干净的关闭/重新启动操作,从而导致不一致.

So basically from your log the server is not running, it's shutting down, so there is nothing for the shell to connect to. Seems like you have had some unclean shutdowns/restarts which has led to the inconsistency.

在配置中清除日志/usr/local/var/mongodb/journal/中的文件.

Clear the files in the journal /usr/local/var/mongodb/journal/ on your config.

也:

sudo rm /var/lib/mongodb/mongod.lock

以防万一,即使那部分看起来很干净.然后重新启动.

Just in case, even though that part looks clean. And then restart.

这篇关于如何设置mongod --dbpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆