開源雲計算技術系列三(10gen)安裝配置
10gen 是一套雲計算平臺,可以爲web應用提供可以擴展的高性能的數據存儲解決方案。10gen的開源項目是mongoDB,主要功能是解決website的操作性數據存儲,session對象的存儲,數據緩存,高效率的實時計數(比如統計pv,uv),並支持ruby,python,java,c++,php等衆多的頁面語言。
MongoDB主要特徵是存儲數據非常方便,不在是傳統的object-relational mapping的模式,高性能,可以存儲大對象數據,比如視頻等,可以自動複製和failover。
技術需要實踐,讓我們一起來從實踐中體會mongoDB的衆多優越的特性。
首先建立一臺虛擬機rhel 5.2.
下載符合版本的軟件,
http://www.mongodb.org/display/DOCS/Downloads
curl -O http://downloads.mongodb.org/linux/mongodb-linux-i686-latest.tgz
安裝非常簡單,解壓好就可以使用,非常方便。
tar xvzf mongodb-linux-i686-latest.tgz
解壓後的目錄結構如下:
|-- bin | |-- mongo (the database shell) | |-- mongod (the database) | |-- mongodump (dump/export utility) | `-- mongorestore (restore/import utility) |-- include (c++ driver include files) | `-- mongo | |-- client | |-- db | |-- grid | `-- util |-- lib |-- lib64
在啓動之前,先建立數據庫存放的目錄 。
mkdir –p /data/db
接着後臺啓動mongoDB
bin/mongod run &
[1] 5673
[root@rac01 mongodb-linux-i686-2009-06-14]# Mon Jun 15 20:27:32 Mongo DB : starting : pid = 5673 port = 27017 dbpath = /data/db/ master = 0 slave = 0
Mon Jun 15 20:27:32 db version v0.9.4+, pdfile version 4.4
Mon Jun 15 20:27:32 git version: 004cd26deee50b7fdf060c06605bbce37bc09794
Mon Jun 15 20:27:32 sys 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
Mon Jun 15 20:27:32 waiting for connections on port 27017
Mon Jun 15 20:27:32 web admin interface listening on port 28017
ok,啓動完畢,我們用mongoDB自帶的客戶端連接上。
bin/mongo
url: test
connecting to: test
type "help" for help
Mon Jun 15 20:28:09 connection accepted from 127.0.0.1:19943
> help
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 <db name> set curent database to <db name>
db.help() help on DB methods
db.foo.help() help on collection methods
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
> show dbs
admin
local
test
幫助的層次非常清楚。
我們來檢查一下mongoDB是否運行正常。
bin/mongo
url: test
connecting to: test
type "help" for help
Mon Jun 15 20:28:56 connection accepted from 127.0.0.1:31975
> db.foo.save( { a : 1 } )
> db.foo.findOne()
{"_id" : "4a3631b14ae1a7d3e24cab82" , "a" : 1}
到這一步,這個強大的mongoDB就安裝配置好了,下一篇我們來進一步體驗一下這個開源mongoDB的強大功能要點。