Mongodb与replSet有关

时间:2012-05-30 09:14:07

标签: mongodb

我试着这个:

  

mongod --replSet mySet --dbpath / data / r1 --port 27017 --oplogSize 700

     

mongod --replSet mySet --dbpath / data / r2 --port 27018 --oplogSize 700

     

mongod --replSet mySet --dbpath / data / r3 --port 27019 --oplogSize 700

然后在新的终端:

/mongo --port 27017
MongoDB shell version: 2.0.2
connecting to: 127.0.0.1:27017/test 

> cfg = {

    _id : "mySet",
    members : [
    { _id : 0, host : "localhost:27017" },
    { _id : 1, host : "localhost:27018" },
    { _id : 2, host : "localhost:27019" } ] } 

当我跑步时

  

rs.initiate(CFG)

我收到此错误:

  

{“errmsg”:“服务器未运行--replSet”,“ok”:0}

为什么我收到此错误?

来自日志文件:

Fri Jun 01 15:05:11 [initandlisten] MongoDB starting : pid=5236 port=27017 dbpath=c:\mongodb\data 64-bit host=mami
Fri Jun 01 15:05:11 [initandlisten] db version v2.0.4, pdfile version 4.5
Fri Jun 01 15:05:11 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Fri Jun 01 15:05:11 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42
Fri Jun 01 15:05:11 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true }
Fri Jun 01 15:05:11 [initandlisten] journal dir=c:/mongodb/data/journal
Fri Jun 01 15:05:11 [initandlisten] recover : no journal files present, no recovery needed
Fri Jun 01 15:05:12 [initandlisten] waiting for connections on port 27017
Fri Jun 01 15:05:12 [websvr] admin web console waiting for connections on port 28017
Fri Jun 01 15:05:12 [initandlisten] connection accepted from 127.0.0.1:49663 #1
Fri Jun 01 15:05:56 [conn1] end connection 127.0.0.1:49663
Fri Jun 01 15:06:02 [initandlisten] connection accepted from 127.0.0.1:49669 #2
Fri Jun 01 15:06:11 [clientcursormon] mem (MB) res:22 virt:67 mapped:0
Fri Jun 01 15:06:19 [conn2] terminating, shutdown command received
Fri Jun 01 15:06:19 dbexit: shutdown called
Fri Jun 01 15:06:19 [conn2] shutdown: going to close listening sockets...
Fri Jun 01 15:06:19 [conn2] closing listening socket: 488
Fri Jun 01 15:06:19 [conn2] closing listening socket: 492
Fri Jun 01 15:06:19 [conn2] shutdown: going to flush diaglog...
Fri Jun 01 15:06:19 [conn2] shutdown: going to close sockets...
Fri Jun 01 15:06:19 [conn2] shutdown: waiting for fs preallocator...
Fri Jun 01 15:06:19 [conn2] shutdown: lock for final commit...
Fri Jun 01 15:06:19 [conn2] shutdown: final commit...
Fri Jun 01 15:06:19 [conn2] shutdown: closing all files...
Fri Jun 01 15:06:19 [conn2] closeAllFiles() finished
Fri Jun 01 15:06:19 [conn2] journalCleanup...
Fri Jun 01 15:06:19 [conn2] removeJournalFiles
Fri Jun 01 15:06:19 [conn2] shutdown: removing fs lock...
Fri Jun 01 15:06:19 dbexit: really exiting now


***** SERVER RESTARTED *****


Fri Jun 01 15:06:19 [initandlisten] MongoDB starting : pid=6980 port=27017 dbpath=c:\mongodb\data 64-bit host=mami
Fri Jun 01 15:06:19 [initandlisten] db version v2.0.4, pdfile version 4.5
Fri Jun 01 15:06:19 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Fri Jun 01 15:06:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42
Fri Jun 01 15:06:19 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true }
Fri Jun 01 15:06:19 [initandlisten] journal dir=c:/mongodb/data/journal
Fri Jun 01 15:06:19 [initandlisten] recover : no journal files present, no recovery needed
Fri Jun 01 15:06:19 [initandlisten] waiting for connections on port 27017
Fri Jun 01 15:06:20 [websvr] admin web console waiting for connections on port 28017
Fri Jun 01 15:06:20 [initandlisten] connection accepted from 127.0.0.1:49678 #1
Fri Jun 01 15:06:22 [conn1] end connection 127.0.0.1:49678
Fri Jun 01 15:06:30 [initandlisten] connection accepted from 127.0.0.1:49679 #2
Fri Jun 01 15:06:36 [conn2] terminating, shutdown command received
Fri Jun 01 15:06:36 dbexit: shutdown called
Fri Jun 01 15:06:36 [conn2] shutdown: going to close listening sockets...
Fri Jun 01 15:06:36 [conn2] closing listening socket: 488
Fri Jun 01 15:06:36 [conn2] closing listening socket: 492
Fri Jun 01 15:06:36 [conn2] shutdown: going to flush diaglog...
Fri Jun 01 15:06:36 [conn2] shutdown: going to close sockets...
Fri Jun 01 15:06:36 [conn2] shutdown: waiting for fs preallocator...
Fri Jun 01 15:06:36 [conn2] shutdown: lock for final commit...
Fri Jun 01 15:06:36 [conn2] shutdown: final commit...
Fri Jun 01 15:06:36 [conn2] shutdown: closing all files...
Fri Jun 01 15:06:36 [conn2] closeAllFiles() finished
Fri Jun 01 15:06:36 [conn2] journalCleanup...
Fri Jun 01 15:06:37 [conn2] removeJournalFiles
Fri Jun 01 15:06:37 [conn2] shutdown: removing fs lock...
Fri Jun 01 15:06:37 dbexit: really exiting now


***** SERVER RESTARTED *****


Fri Jun 01 15:06:37 [initandlisten] MongoDB starting : pid=7076 port=27017 dbpath=c:\mongodb\data 64-bit host=mami
Fri Jun 01 15:06:37 [initandlisten] db version v2.0.4, pdfile version 4.5
Fri Jun 01 15:06:37 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Fri Jun 01 15:06:37 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42
Fri Jun 01 15:06:37 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true }
Fri Jun 01 15:06:37 [initandlisten] journal dir=c:/mongodb/data/journal
Fri Jun 01 15:06:37 [initandlisten] recover : no journal files present, no recovery needed
Fri Jun 01 15:06:37 [initandlisten] waiting for connections on port 27017
Fri Jun 01 15:06:37 [websvr] admin web console waiting for connections on port 28017
Fri Jun 01 15:06:37 [initandlisten] connection accepted from 127.0.0.1:49680 #1
Fri Jun 01 15:06:39 [conn1] end connection 127.0.0.1:49680
Fri Jun 01 15:07:37 [clientcursormon] mem (MB) res:22 virt:66 mapped:0
Fri Jun 01 15:53:55 [clientcursormon] mem (MB) res:0 virt:64 mapped:0
Fri Jun 01 15:58:55 [clientcursormon] mem (MB) res:1 virt:64 mapped:0
Fri Jun 01 15:59:24 [initandlisten] connection accepted from 127.0.0.1:50087 #2
Fri Jun 01 15:59:55 [clientcursormon] mem (MB) res:2 virt:65 mapped:0
Fri Jun 01 16:04:55 [clientcursormon] mem (MB) res:2 virt:65 mapped:0
Fri Jun 01 16:06:07 [conn2] replSet replSetInitiate admin command received from client

我已经尝试了这个教程replSet,但仍然没有尝试

7 个答案:

答案 0 :(得分:16)

我能想到的一个原因是,在尝试启动它之前,你已经在没有--replSet参数的端口27017上运行了mongod。在尝试此操作之前,请确保没有mongod正在运行(ps aux |grep mongod)。我也会检查日志文件,因为它可能会给出一个线索,说明为什么它没有以副本集模式启动。

答案 1 :(得分:2)

我发现一个简单的解决方案是为--replSet指定一个子参数。

我将Mongo Server配置为只有一个节点的ReplicaSet,因为它充当PRYMARY,不会有另一个节点来阅读purpouse。

这是运行mongod服务时帮助我的原因。

  

/> sudo mongod --replSet myReplSet

一旦我使用mongo登录,然后提示改变了,那么我可以正确配置rs:

  

/ myReplSet:PRIMARY> cfg = {_id:“mySet”,成员:[{_ id:0,主持人:“localhost:27017”}]}

     

/ myReplSet:PRIMARY> rs.initiate(CFG)

这就成了伎俩!!

我希望这有助于某人。

答案 2 :(得分:1)

我注意到它的linux权限问题是上面的建议。要修复它,你需要设置数据目录命令权限sudo chown -R $USER /data。 我和npm有同样的问题。

答案 3 :(得分:0)

我在进行mongodb复制时遇到了同样的问题。分页作业.. 刚运行以下命令后:

./mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork

然后进行ps aux | grep mongo检查我意识到实际上没有任何东西在运行。 我做的工作只是将这些命令作为系统根运行,所以最后我运行mongod进程,如:

sudo ./mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork

就是这样! :)

希望它有所帮助。

答案 4 :(得分:0)

我成功地解决了这个问题。

  1. 我首先删除了mongodb: sudo apt-get remove mongodb

  2. I followed the MongoDB tutorial:

  3. 然而,在步骤......之后: sudo apt-get update

  4. ...我决定重新安装mongodb: sudo apt-get删除mongodb (在这一步我可能指定'mongodb-server')。

  5. 而且,奇迹般地,replSet名称能够从mongodb.conf加载。 我被留给了rs.initiate() - 就是这样。

    注意:我从2.4.9开始并使用相同的2.4.9完成 - 只是工作。

答案 5 :(得分:0)

有同样的问题,所以在我的情况下,系统中还有一个mongod进程在运行(当然在默认端口上没有--replSet标志运行,这就是为什么我有这个错误)。

运行命令:

$ ps aux | grep mongod

在我的情况下它输出:

root 63434 0.3 0.1 2621328 12228 ?? S 5:53PM 0:03.44 mongod --replSet m101 --logpath 1.log --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork

root 63442 0.2 0.1 2622352 12220 ?? S 5:54PM 0:03.37 mongod --replSet m101 --logpath 2.log --dbpath /data/rs2 --port 27018 --smallfiles --oplogSize 64 --fork

root 63448 0.2 0.1 2621312 12208 ?? S 5:54PM 0:03.35 mongod --replSet m101 --logpath 3.log --dbpath /data/rs3 --port 27019 --smallfiles --oplogSize 64 --fork

pavlo 683 0.0 0.0 3082276 6628 ?? S 31Aug14 11:27.70 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf

pavlo 63522 0.0 0.0 2432784 624 s002 S+ 6:06PM 0:00.00 grep mongod

所以id为683的进程正在进行中,所以在我杀了它之后一切正常:

$ kill 683

答案 6 :(得分:0)

是的,同样在我的ubuntu 15.04上。并通过解决端口解决了它。另外,检查日志,以便执行状态让我们知道它是如何工作的。