【mongodb】mongodb的安裝

楊奇龍發表於2011-08-08
獲取mongodb安裝包解壓
[root@localhost ~]# wget
[monogdb@localhost ~]$ tar xzf mongodb-linux-x86_64-1.8.3-rc0.tgz  
建立monogdb的資料存放位置並賦予monogdb相應的許可權。
[root@localhost ~]# cd /opt
[root@localhost opt]# mkdir monogdata
[root@localhost opt]# ls
monogdata  oracle  software
[root@localhost opt]# chown monogdb:monogdb /opt/monogdata/
[root@localhost opt]# su - monogdb
[monogdb@localhost ~]$ mv mongodb-linux-x86_64-1.8.3-rc0  monogdb
[monogdb@localhost ~]$ cd monogdb/
[monogdb@localhost monogdb]$ cd bin/

[monogdb@localhost bin]$ ./mongod  -dbpath /opt/monogdata/data/ --指定monogdb資料存放的位置。並開啟monogdb的服務。
Mon Aug  8 20:45:15 [initandlisten] MongoDB starting : pid=10340 port=27017 dbpath=/opt/monogdata/data/ 64-bit 
Mon Aug  8 20:45:15 [initandlisten] db version v1.8.3-rc0, pdfile version 4.5
Mon Aug  8 20:45:15 [initandlisten] git version: 81147c1ca4cc10d9a81a0a2afdf364ab1ca8867d
Mon Aug  8 20:45:15 [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
Mon Aug  8 20:45:15 [initandlisten] waiting for connections on port 27017
Mon Aug  8 20:45:15 [websvr] web admin interface listening on port 28017
Mon Aug  8 20:47:15 [initandlisten] connection accepted from 127.0.0.1:21108 #1
Mon Aug  8 21:16:25 [conn1] end connection 127.0.0.1:21108
在另一個視窗即客戶端
/home/monogdb/monogdb/bin目錄下,執行./mongo 啟動客戶端和服務端連線,並做一些簡單的測試。
[monogdb@localhost bin]$ ./mongo 
MongoDB shell version: 1.8.3-rc0
connecting to: test
> db                                                                                                                                
test
> use test;
switched to db test
> help
        db.help()                    help on db methods
        db.mycoll.help()             help on collection methods
        rs.help()                    help on replica set methods
        help connect                 connecting to a db help
        help admin                   administrative help
        help misc                    misc things to know
        help mr                      mapreduce help

        show dbs                     show database names
        show collections             show collections in current database
        show users                   show users in current database
        show profile                 show most recent system.profile entries with time >= 1ms
        use                set current database
        db.foo.find()                list objects in collection foo
        db.foo.find( { a : 1 } )     list objects in foo where a == 1
        it                           result of the last line evaluated; use to further iterate
        DBQuery.shellBatchSize = x   set default number of items to display on shell
        exit                         quit the mongo shell

> show dbs
admin   (empty)
local   (empty)
> show users
> show profile
db.system.profile is empty
Use db.setProfilingLevel(2) will enable profiling
Use db.system.profile.find() to show raw profile entries
> exit
bye

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-704438/,如需轉載,請註明出處,否則將追究法律責任。

相關文章