mongodb安装和测试

来源:互联网 发布:macbook 撤销windows 编辑:程序博客网 时间:2024/04/28 03:49

        今天又看了看MONGODB的版本发现又变更了,这个版本发布的速度也真够快的,于是又下载了一个新的来进行安装,之前的是安装在WINDOWS下的,下了个LINUX 86版本的,按照LINUX安装和测试的官方网站教程:http://www.mongodb.org/display/DOCS/Quickstart+Unix,亲自测试了下,将安装和测试过程记录如下:

查看我的环境:

[root@localhost /]# uname -a
Linux localhost 2.6.18-194.el5PAE #1 SMP Fri Apr 2 15:37:44 EDT 2010 i686 i686 i386 GNU/Linux

[root@localhost /]# cat /etc/redhat-release 
CentOS release 5.5 (Final)

添加用户:

[root@localhost ~]# useradd mongodb 
[root@localhost ~]# passwd mongodb

Changing password for user mongodb.
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.

创建NOSQL存储目录,默认存储在/data/db下,因此预先建立好目录,并且更改目录用户所有者:

By default MongoDB will store data in /data/db, but it won't automatically create that directory. To create it, do:

[root@localhost ~]#mkdir -p /data/db/

[root@localhost /]# chown -R mongodb /data/db/


拷贝文件到用户目录:

[root@localhost ~]# mv mongodb-linux-i686-2.0.0.tgz /home/mongodb/
[root@localhost ~]# chown mongodb /home/mongodb/mongodb-linux-i686-2.0.0.tgz 

[root@localhost /]# ll /data
总计 4
drwxr-xr-x 3 mongodb root 4096 10-13 18:43 db

切换用户,解压文件:
[root@localhost ~]# su - mongodb
[mongodb@localhost ~]$ ls
mongodb-linux-i686-2.0.0.tgz

[mongodb@localhost ~]$ ll
总计 37112
drwxr-xr-x 3 mongodb mongodb      4096 09-12 00:06 mongodb-linux-i686-2.0.0
-rw-r--r-- 1 mongodb oinstall 37949452 10-12 16:41 mongodb-linux-i686-2.0.0.tgz

启动服务端进程:

[mongodb@localhost db]$ cd ~/mongodb-linux-i686-2.0.0/bin/
[mongodb@localhost bin]$ pwd
/home/mongodb/mongodb-linux-i686-2.0.0/bin
[mongodb@localhost bin]$ ./mongod
./mongod --help for help and startup options
Thu Oct 13 18:40:08 
Thu Oct 13 18:40:08 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 13 18:40:08 
Thu Oct 13 18:40:08 [initandlisten] MongoDB starting : pid=4481 port=27017 dbpath=/data/db/ 32-bit host=localhost
Thu Oct 13 18:40:08 [initandlisten] 
Thu Oct 13 18:40:08 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 13 18:40:08 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 13 18:40:08 [initandlisten] **       with --journal, the limit is lower
Thu Oct 13 18:40:08 [initandlisten] 
Thu Oct 13 18:40:08 [initandlisten] db version v2.0.0, pdfile version 4.5
Thu Oct 13 18:40:08 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Thu Oct 13 18:40:08 [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_37
Thu Oct 13 18:40:08 [initandlisten] options: {}
Thu Oct 13 18:40:08 [initandlisten] waiting for connections on port 27017
Thu Oct 13 18:40:08 [websvr] admin web console waiting for connections on port 28017
Thu Oct 13 18:41:08 [clientcursormon] mem (MB) res:12 virt:93 mapped:0
Thu Oct 13 18:41:47 [initandlisten] connection accepted from 127.0.0.1:5317 #1
Thu Oct 13 18:42:34 [conn1] end connection 127.0.0.1:5317
Thu Oct 13 18:42:37 [initandlisten] connection accepted from 127.0.0.1:62867 #2
Thu Oct 13 18:43:14 [FileAllocator] allocating new datafile /data/db/test.ns, filling with zeroes...
Thu Oct 13 18:43:14 [FileAllocator] creating directory /data/db/_tmp
Thu Oct 13 18:43:14 [FileAllocator] done allocating datafile /data/db/test.ns, size: 16MB,  took 0.134 secs
Thu Oct 13 18:43:14 [FileAllocator] allocating new datafile /data/db/test.0, filling with zeroes...
Thu Oct 13 18:43:14 [FileAllocator] done allocating datafile /data/db/test.0, size: 16MB,  took 0.156 secs
Thu Oct 13 18:43:14 [FileAllocator] allocating new datafile /data/db/test.1, filling with zeroes...
Thu Oct 13 18:43:14 [conn2] build index test.foo { _id: 1 }
Thu Oct 13 18:43:14 [conn2] build index done 0 records 0 secs
Thu Oct 13 18:43:14 [conn2] insert test.foo 303ms
Thu Oct 13 18:43:15 [FileAllocator] done allocating datafile /data/db/test.1, size: 32MB,  took 0.484 secs
Thu Oct 13 18:44:08 [clientcursormon] mem (MB) res:28 virt:126 mapped:32


再开一个SHELL终端,连接客户端查看服务器进程:

[mongodb@localhost ~]$ ps -ef | grep mong
root      4360  4296  0 18:32 pts/1    00:00:00 su - mongodb
mongodb   4361  4360  0 18:32 pts/1    00:00:00 -bash
mongodb   4481  4361  0 18:40 pts/1    00:00:00 ./mongod

启动客户端进程,插入一条记录和查看该记录:

[mongodb@localhost ~]$ ./mongodb-linux-i686-2.0.0/bin/mongo
MongoDB shell version: 2.0.0
connecting to: test

> db.foo.safe({a:1})
Thu Oct 13 18:42:51 TypeError: db.foo.safe is not a function (shell):1
>  db.foo.save({a:1})
> db.foo.find()
{ "_id" : ObjectId("4e96c0c2deaea34d48ebda61"), "a" : 1 }
> exit
bye