呵呵,终于算是安装成功了,对于一个我这样一个门外汗来说,真是浪费了不少的时间啊!
下面介绍一下安装的步骤吧!
首先在终端输入如下命令:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
在/etc/apt/sources.list.d/的目录下面建一个10gen.list的文件,在里面加入下面一行:deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
然后更新你的系统:
sudo apt-get update
开始安装:
sudo apt-get install mongodb-10gen
重新启动电脑后,进入含有mongod的目录打开终端输入如下:music@ubuntu:/usr/bin# ./mongod
./mongod --help for help and startup options
Thu Aug 16 22:43:18
Thu Aug 16 22:43:18 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Aug 16 22:43:18
Thu Aug 16 22:43:18 [initandlisten] MongoDB starting : pid=5051 port=27017 dbpath=/data/db/ 32-bit host=ubuntu
Thu Aug 16 22:43:18 [initandlisten]
Thu Aug 16 22:43:18 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Aug 16 22:43:18 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Aug 16 22:43:18 [initandlisten] ** with --journal, the limit is lower
Thu Aug 16 22:43:18 [initandlisten]
Thu Aug 16 22:43:18 [initandlisten] db version v2.0.7, pdfile version 4.5
Thu Aug 16 22:43:18 [initandlisten] git version: 875033920e8869d284f32119413543fa475227bf
Thu Aug 16 22:43:18 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_41
Thu Aug 16 22:43:18 [initandlisten] options: {}
Thu Aug 16 22:43:18 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminatingCtrl+C
Thu Aug 16 22:43:18 dbexit:
出现了一个错误是dbpath (/data/db/) does not exist!
Thu Aug 16 22:43:18 [initandlisten] shutdown: going to close listening sockets...
Thu Aug 16 22:43:18 [initandlisten] shutdown: going to flush diaglog...
Thu Aug 16 22:43:18 [initandlisten] shutdown: going to close sockets...
Thu Aug 16 22:43:18 [initandlisten] shutdown: waiting for fs preallocator...
Thu Aug 16 22:43:18 [initandlisten] shutdown: closing all files...
Thu Aug 16 22:43:18 [initandlisten] closeAllFiles() finished
Thu Aug 16 22:43:18 dbexit: really exiting now
我们在终端输入如下命令建立那个文件路径
music@ubuntu:/usr/bin#mkdir -p /data/db/
在执行./mongod就不会出现那种错误root@ubuntu:/usr/bin# ./mongod
./mongod --help for help and startup options
Thu Aug 16 22:45:41
Thu Aug 16 22:45:41 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Aug 16 22:45:41
Thu Aug 16 22:45:41 [initandlisten] MongoDB starting : pid=5079 port=27017 dbpath=/data/db/ 32-bit host=ubuntu
Thu Aug 16 22:45:41 [initandlisten]
Thu Aug 16 22:45:41 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Aug 16 22:45:41 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Aug 16 22:45:41 [initandlisten] ** with --journal, the limit is lower
Thu Aug 16 22:45:41 [initandlisten]
Thu Aug 16 22:45:41 [initandlisten] db version v2.0.7, pdfile version 4.5
Thu Aug 16 22:45:41 [initandlisten] git version: 875033920e8869d284f32119413543fa475227bf
Thu Aug 16 22:45:41 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_41
Thu Aug 16 22:45:41 [initandlisten] options: {}
Thu Aug 16 22:45:41 [initandlisten] waiting for connections on port 27017
Thu Aug 16 22:45:41 [websvr] admin web console waiting for connections on port 28017
^CThu Aug 16 22:46:17 got kill or ctrl c or hup signal 2 (Interrupt), will terminate after current cmd ends
Thu Aug 16 22:46:17 [interruptThread] now exitingCTRL+C
Thu Aug 16 22:46:17 dbexit:
Thu Aug 16 22:46:17 [interruptThread] shutdown: going to close listening sockets...
Thu Aug 16 22:46:17 [interruptThread] closing listening socket: 5
Thu Aug 16 22:46:17 [interruptThread] closing listening socket: 6
Thu Aug 16 22:46:17 [interruptThread] closing listening socket: 7
Thu Aug 16 22:46:17 [interruptThread] removing socket file: /tmp/mongodb-27017.sock
Thu Aug 16 22:46:17 [interruptThread] shutdown: going to flush diaglog...
Thu Aug 16 22:46:17 [interruptThread] shutdown: going to close sockets...
Thu Aug 16 22:46:17 [interruptThread] shutdown: waiting for fs preallocator...
Thu Aug 16 22:46:17 [interruptThread] shutdown: closing all files...
Thu Aug 16 22:46:17 [interruptThread] closeAllFiles() finished
Thu Aug 16 22:46:17 [interruptThread] shutdown: removing fs lock...
Thu Aug 16 22:46:17 dbexit: really exiting now
然后又运行了下面的root@ubuntu:/usr/bin# ./mongod --journal
Thu Aug 16 22:46:39 [initandlisten] MongoDB starting : pid=5091 port=27017 dbpath=/data/db/ 32-bit host=ubuntu
Thu Aug 16 22:46:39 [initandlisten]
Thu Aug 16 22:46:39 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Aug 16 22:46:39 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Aug 16 22:46:39 [initandlisten] ** with --journal, the limit is lower
Thu Aug 16 22:46:39 [initandlisten]
Thu Aug 16 22:46:39 [initandlisten] db version v2.0.7, pdfile version 4.5
Thu Aug 16 22:46:39 [initandlisten] git version: 875033920e8869d284f32119413543fa475227bf
Thu Aug 16 22:46:39 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_41
Thu Aug 16 22:46:39 [initandlisten] options: { journal: true }
Thu Aug 16 22:46:39 [initandlisten] journal dir=/data/db/journal
Thu Aug 16 22:46:39 [initandlisten] recover : no journal files present, no recovery needed
Thu Aug 16 22:46:45 [initandlisten] preallocateIsFaster=true 46.14
Thu Aug 16 22:46:52 [initandlisten] preallocateIsFaster=true 54.12
Thu Aug 16 22:46:59 [initandlisten] preallocateIsFaster=true 50.58
Thu Aug 16 22:46:59 [initandlisten] preallocateIsFaster check took 20.198 secs
Thu Aug 16 22:46:59 [initandlisten] preallocating a journal file /data/db/journal/prealloc.0
73400320/268435456 27%
157286400/268435456 58%
220200960/268435456 82%
262144000/268435456 97%
Thu Aug 16 22:48:07 [initandlisten] preallocating a journal file /data/db/journal/prealloc.1
83886080/268435456 31%
125829120/268435456 46%
188743680/268435456 70%
241172480/268435456 89%
Thu Aug 16 22:48:34 [initandlisten] preallocating a journal file /data/db/journal/prealloc.2
73400320/268435456 27%
115343360/268435456 42%
125829120/268435456 46%
209715200/268435456 78%
Thu Aug 16 22:48:56 [websvr] admin web console waiting for connections on port 28017
Thu Aug 16 22:48:56 [initandlisten] waiting for connections on port 27017
Thu Aug 16 22:49:56 [clientcursormon] mem (MB) res:12 virt:90 mapped:0
^CThu Aug 16 22:54:13 got kill or ctrl c or hup signal 2 (Interrupt), will terminate after current cmd ends
Thu Aug 16 22:54:13 [interruptThread] now exiting
Thu Aug 16 22:54:13 dbexit:
Thu Aug 16 22:54:13 [interruptThread] shutdown: going to close listening sockets...
Thu Aug 16 22:54:13 [interruptThread] closing listening socket: 6
Thu Aug 16 22:54:13 [interruptThread] closing listening socket: 7
Thu Aug 16 22:54:13 [interruptThread] closing listening socket: 8
Thu Aug 16 22:54:13 [interruptThread] removing socket file: /tmp/mongodb-27017.sock
Thu Aug 16 22:54:13 [interruptThread] shutdown: going to flush diaglog...
Thu Aug 16 22:54:13 [interruptThread] shutdown: going to close sockets...
Thu Aug 16 22:54:13 [interruptThread] shutdown: waiting for fs preallocator...
Thu Aug 16 22:54:13 [interruptThread] shutdown: lock for final commit...
Thu Aug 16 22:54:13 [interruptThread] shutdown: final commit...
Thu Aug 16 22:54:13 [interruptThread] shutdown: closing all files...
Thu Aug 16 22:54:13 [interruptThread] closeAllFiles() finished
Thu Aug 16 22:54:13 [interruptThread] journalCleanup...
Thu Aug 16 22:54:13 [interruptThread] removeJournalFiles
Thu Aug 16 22:54:13 [interruptThread] shutdown: removing fs lock...
Thu Aug 16 22:54:13 dbexit: really exiting now运行了./mongo出现了错误如下所示:
root@ubuntu:/usr/bin# ./mongo
MongoDB shell version: 2.0.7
connecting to: test
Thu Aug 16 22:54:37 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
其实这个时候你要先打开一个终端在其运行./mongod --dbpath=/data/db如下所示:root@ubuntu:/usr/bin# ./mongod --dbpath=/data/db
Thu Aug 16 23:10:43
Thu Aug 16 23:10:43 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Aug 16 23:10:43
Thu Aug 16 23:10:43 [initandlisten] MongoDB starting : pid=5256 port=27017 dbpath=/data/db 32-bit host=ubuntu
Thu Aug 16 23:10:43 [initandlisten]
Thu Aug 16 23:10:43 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Aug 16 23:10:43 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Aug 16 23:10:43 [initandlisten] ** with --journal, the limit is lower
Thu Aug 16 23:10:43 [initandlisten]
Thu Aug 16 23:10:43 [initandlisten] db version v2.0.7, pdfile version 4.5
Thu Aug 16 23:10:43 [initandlisten] git version: 875033920e8869d284f32119413543fa475227bf
Thu Aug 16 23:10:43 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_41
Thu Aug 16 23:10:43 [initandlisten] options: { dbpath: "/data/db" }
Thu Aug 16 23:10:43 [websvr] admin web console waiting for connections on port 28017
Thu Aug 16 23:10:43 [initandlisten] waiting for connections on port 27017
Thu Aug 16 23:11:43 [clientcursormon] mem (MB) res:12 virt:82 mapped:0
Thu Aug 16 23:16:43 [clientcursormon] mem (MB) res:12 virt:82 mapped:0
Thu Aug 16 23:17:48 [initandlisten] connection accepted from 127.0.0.1:56485 #1
Thu Aug 16 23:19:46 [FileAllocator] allocating new datafile /data/db/test.ns, filling with zeroes...
Thu Aug 16 23:19:46 [FileAllocator] creating directory /data/db/_tmp
Thu Aug 16 23:19:46 [FileAllocator] done allocating datafile /data/db/test.ns, size: 16MB, took 0.091 secs
Thu Aug 16 23:19:46 [FileAllocator] allocating new datafile /data/db/test.0, filling with zeroes...
Thu Aug 16 23:19:46 [FileAllocator] done allocating datafile /data/db/test.0, size: 16MB, took 0.082 secs
Thu Aug 16 23:19:46 [FileAllocator] allocating new datafile /data/db/test.1, filling with zeroes...
Thu Aug 16 23:19:46 [conn1] build index test.foo { _id: 1 }
Thu Aug 16 23:19:46 [conn1] build index done 0 records 0 secs
Thu Aug 16 23:19:46 [FileAllocator] done allocating datafile /data/db/test.1, size: 32MB, took 0.089 secs
Thu Aug 16 23:19:46 [conn1] insert test.foo 397ms
Thu Aug 16 23:20:20 [conn1] end connection 127.0.0.1:56485
Thu Aug 16 23:20:43 [clientcursormon] mem (MB) res:28 virt:115 mapped:32
然后在开一个终端,mongo运行如下所示:music@ubuntu:~$ mongo
MongoDB shell version: 2.0.7
connecting to: test
>
这个时候配置成功。注意:一定要让你的./mongod在你的超级用户下启动,然后在运行你的mongo命令,这样就不会出现84错误了!谢谢这个网站:
http://codingstandards.iteye.com/blog/1203070