- 注册时间
- 2009-3-25
- 最后登录
- 2013-5-17
- 在线时间
- 468 小时
- 阅读权限
- 90
- 积分
- 25836
- 帖子
- 59
- 主题
- 3
- 精华
- 0
- UID
- 2124
 
 - 签到
- 303
- 注册时间
- 2009-3-25
- 最后登录
- 2013-5-17
- 在线时间
- 468 小时
- 阅读权限
- 90
- 积分
- 25836
- 帖子
- 59
- 主题
- 3
- 精华
- 0
- UID
- 2124
|
发表于 2011-4-21 16:16:31
|显示全部楼层
最近在学习mongodb,发现mongodb的没有conf配置文件,所有的设置都是在启动时的参数设定的。
今天在做mongodb主从复制时,出错了,mongodb进程起不来,命令如下:
/usr/local/mongodb/bin/mongod --master --dbpath=/usr/local/mongodb/data/ --logpath=/usr/local/mongodb/log/mongodb.log --logappend &
查看日志,发现:
Thu Apr 21 15:19:24 [initandlisten] MongoDB starting : pid=5673 port=27017 dbpath=/usr/local/mongodb/data/ master=1 64-bit
Thu Apr 21 15:19:24 [initandlisten] db version v1.8.0, pdfile version 4.5
Thu Apr 21 15:19:24 [initandlisten] git version: 9c28b1d608df0ed6ebe791f63682370082da41c0
Thu Apr 21 15:19:24 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Thu Apr 21 15:19:24 [initandlisten] waiting for connections on port 27017
Thu Apr 21 15:19:24 [initandlisten] ******
Thu Apr 21 15:19:24 [initandlisten] creating replication oplog of size: 944MB...
Thu Apr 21 15:19:24 [FileAllocator] allocating new datafile /usr/local/mongodb/data/local.ns, filling with zeroes...
Thu Apr 21 15:19:24 [FileAllocator] done allocating datafile /usr/local/mongodb/data/local.ns, size: 16MB, took 0.164 secs
Thu Apr 21 15:19:24 [FileAllocator] allocating new datafile /usr/local/mongodb/data/local.0, filling with zeroes...
Thu Apr 21 15:19:25 [FileAllocator] done allocating datafile /usr/local/mongodb/data/local.0, size: 64MB, took 1.109 secs
Thu Apr 21 15:19:25 [FileAllocator] allocating new datafile /usr/local/mongodb/data/local.1, filling with zeroes...
Thu Apr 21 15:19:27 [FileAllocator] done allocating datafile /usr/local/mongodb/data/local.1, size: 128MB, took 1.639 secs
Thu Apr 21 15:19:27 [FileAllocator] allocating new datafile /usr/local/mongodb/data/local.2, filling with zeroes...
Thu Apr 21 15:19:37 [FileAllocator] done allocating datafile /usr/local/mongodb/data/local.2, size: 1024MB, took 9.577 secs
Thu Apr 21 15:19:37 [initandlisten] ERROR: mmap() failed for /usr/local/mongodb/data/local.2 len:1073741824 errno:12 Cannot allocate memory
Thu Apr 21 15:19:37 [initandlisten] ERROR: mmap failed with out of memory. (64 bit build)
Thu Apr 21 15:19:37 [initandlisten] exception in initAndListen std::exception: can't map file memory, terminating
Thu Apr 21 15:19:37 dbexit:
Thu Apr 21 15:19:37 [initandlisten] shutdown: going to close listening sockets...
Thu Apr 21 15:19:37 [initandlisten] shutdown: going to flush diaglog...
Thu Apr 21 15:19:37 [initandlisten] shutdown: going to close sockets...
Thu Apr 21 15:19:37 [initandlisten] shutdown: waiting for fs preallocator...
Thu Apr 21 15:19:38 [initandlisten] shutdown: closing all files...
Thu Apr 21 15:19:38 closeAllFiles() finished
Thu Apr 21 15:19:38 [initandlisten] shutdown: removing fs lock...
Thu Apr 21 15:19:38 dbexit: really exiting now
看来是因为我在虚拟机上做的,内存太小,而mongodb在设置为主从关系时,会创建oplog“creating replication oplog of size: 944MB”,这个日志应该是放在内存中的,所以就爆了“ERROR: mmap failed with out of memory”
解决方法:
(1)设置oplog的大小,用参数--oplogSize来指定,不默认创建944M
(2)放开虚拟内存的限制(虚拟机默认设定512M ),ulimit -v unlimited
再执行主从的启动命令就ok了
疑问?
mongodb如此吃内存,现在还没有做线上应用,希望有用mongodb做应用的给点建议···
|
|