mongodb之linux通用二进制包安装
MongoDB中记录是文档,其是字段和值组成的对结构。mongodb文档类似JSON对象,字段的值可以包含其它文档、数组、文档的数组。记录组织成collection,相当于表。参考下图:
使用文档的优点是:
文档对应很多编程语言的内生数据对象
内嵌文档和数组减少了join的开销
动态schema支持顺畅多态
关键功能:
高性能:
mongodb提供高性能数据持久。特别是:
支持内嵌数据模型减少了数据库系统的I/O
索引支持快速查询且内嵌文档和数组可以包含键
高可用:
mongodb提供高可用的是replica sets
自动失败切换
数据冗余
replica set是一组mongodb服务器,它们维护这同一个数据集,提供冗余,增加数据可用性。
自动水平扩展:
水平扩展是mongodb的内核功能。
在集群上自动共享分布式数据
replica sets能为低延迟,高吞吐量的应用提供最终一致性读。
安装:
0
环境
[root@host2 ~]# uname -a
Linux host2 2.6.32-504.3.3.el6.x86_64 #1 SMP Wed Dec 17 01:55:02 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@host2 ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
1
下载:
curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.7.tgz
2
[root@mgdbsvr mongodb]# tar -zxvf mongodb-linux-x86_64-2.6.7.tgz
mongodb-linux-x86_64-2.6.7/README
mongodb-linux-x86_64-2.6.7/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-2.6.7/GNU-AGPL-3.0
mongodb-linux-x86_64-2.6.7/bin/mongodump
mongodb-linux-x86_64-2.6.7/bin/mongorestore
mongodb-linux-x86_64-2.6.7/bin/mongoexport
mongodb-linux-x86_64-2.6.7/bin/mongoimport
mongodb-linux-x86_64-2.6.7/bin/mongostat
mongodb-linux-x86_64-2.6.7/bin/mongotop
mongodb-linux-x86_64-2.6.7/bin/mongooplog
mongodb-linux-x86_64-2.6.7/bin/mongofiles
mongodb-linux-x86_64-2.6.7/bin/bsondump
mongodb-linux-x86_64-2.6.7/bin/mongoperf
mongodb-linux-x86_64-2.6.7/bin/mongod
mongodb-linux-x86_64-2.6.7/bin/mongos
mongodb-linux-x86_64-2.6.7/bin/mongo
[root@mgdbsvr mongodb]#
3
拷贝的规划的文件夹
[root@mgdbsvr mongodb]# mv mongodb-linux-x86_64-2.6.7 /opt/mongodb
4
配置环境变量
[root@mgdbsvr ~]# vi .bash_profile
PATH=$PATH:/opt/mongodb/bin
5
数据所在文件夹
[root@mgdbsvr mongodb]# mkdir dbdata
6
使用户 mongod可以读写数据所在文件夹
[root@mgdbsvr mongodb]# useradd -r mongod
[root@mgdbsvr mongodb]# chown mongod:mongod dbdata/
7
启动
[root@mgdbsvr mongodb]# mongod --dbpath dbdata
2015-02-13T17:56:23.704+0800 [initandlisten] MongoDB starting : pid=2035 port=27017 dbpath=dbdata 64-bit host=mgdbsvr
2015-02-13T17:56:23.708+0800 [initandlisten] db version v2.6.7
2015-02-13T17:56:23.708+0800 [initandlisten] git version: a7d57ad27c382de82e9cb93bf983a80fd9ac9899
2015-02-13T17:56:23.708+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-02-13T17:56:23.708+0800 [initandlisten] allocator: tcmalloc
2015-02-13T17:56:23.708+0800 [initandlisten] options: { storage: { dbPath: "dbdata" } }
2015-02-13T17:56:23.738+0800 [initandlisten] journal dir=dbdata/journal
2015-02-13T17:56:23.741+0800 [initandlisten] recover : no journal files present, no recovery needed
2015-02-13T17:56:24.520+0800 [initandlisten] preallocateIsFaster=true 13.46
2015-02-13T17:56:25.273+0800 [initandlisten] preallocateIsFaster=true 12.5
2015-02-13T17:56:27.166+0800 [initandlisten] preallocateIsFaster=true 8.76
2015-02-13T17:56:27.166+0800 [initandlisten] preallocateIsFaster check took 3.423 secs
2015-02-13T17:56:27.167+0800 [initandlisten] preallocating a journal file dbdata/journal/prealloc.0
2015-02-13T17:56:30.089+0800 [initandlisten] File Preallocator Progress: 891289600/1073741824 83%
2015-02-13T17:56:31.216+0800 [initandlisten] preallocating a journal file dbdata/journal/prealloc.1
2015-02-13T17:56:34.070+0800 [initandlisten] File Preallocator Progress: 629145600/1073741824 58%
2015-02-13T17:56:35.779+0800 [initandlisten] preallocating a journal file dbdata/journal/prealloc.2
2015-02-13T17:56:38.054+0800 [initandlisten] File Preallocator Progress: 859832320/1073741824 80%
2015-02-13T17:56:39.630+0800 [initandlisten] allocating new ns file dbdata/local.ns, filling with zeroes...
2015-02-13T17:56:39.762+0800 [FileAllocator] allocating new datafile dbdata/local.0, filling with zeroes...
2015-02-13T17:56:39.763+0800 [FileAllocator] creating directory dbdata/_tmp
2015-02-13T17:56:39.797+0800 [FileAllocator] done allocating datafile dbdata/local.0, size: 64MB, took 0.002 secs
2015-02-13T17:56:39.832+0800 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2015-02-13T17:56:39.855+0800 [initandlisten] added index to empty collection
2015-02-13T17:56:39.894+0800 [initandlisten] command local.$cmd command: create { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 numYields:0 reslen:37 281ms
2015-02-13T17:56:39.897+0800 [initandlisten] waiting for connections on port 27017
8
连接,简单使用
[root@mgdbsvr ~]# mongo
MongoDB shell version: 2.6.7
connecting to: test
#查看当前数据库
> db
test
#切到数据库 mydb
> use mydb
switched to db mydb
> db
mydb
#用javascript创建两个文档
> j = { name : "mongo" }
{ "name" : "mongo" }
> k = { x : 3 }
{ "x" : 3 }
#创建mydb数据库和testdata collection
> db.testdata.insert(j)
WriteResult({ "nInserted" : 1 })
> db.testdata.insert(k);
WriteResult({ "nInserted" : 1 })
> show collections
system.indexes
testdata
> db.testdata.find()
{ "_id" : ObjectId("54ddd717d692cfe0bd20d983"), "name" : "mongo" }
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
>
>
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
>
> use hahadb
switched to db hahadb
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
> db
hahadb
> j = { name : "mongo" }
{ "name" : "mongo" }
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
> db.testdata.insert(j)
WriteResult({ "nInserted" : 1 })
> show dbs
admin (empty)
hahadb 0.078GB
local 0.078GB
mydb 0.078GB
>
> use mydb
switched to db mydb
> show collections
system.indexes
testdata
>
> db.testdata.insert(j)
WriteResult({ "nInserted" : 1 })
> db.testdata.find()
{ "_id" : ObjectId("54ddd717d692cfe0bd20d983"), "name" : "mongo" }
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
{ "_id" : ObjectId("54ddda64d692cfe0bd20d986"), "name" : "mongo" }
> db.testdata.insert(k)
WriteResult({ "nInserted" : 1 })
>
>
> db.testdata.find()
{ "_id" : ObjectId("54ddd717d692cfe0bd20d983"), "name" : "mongo" }
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
{ "_id" : ObjectId("54ddda64d692cfe0bd20d986"), "name" : "mongo" }
{ "_id" : ObjectId("54ddda7dd692cfe0bd20d987"), "x" : 3 }
>
> db.testdata.find({x:3})
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
{ "_id" : ObjectId("54ddda7dd692cfe0bd20d987"), "x" : 3 }
>
>
> exit;
[root@mgdbsvr ~]#
参考:
docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/
-----------------
blog.csdn.net/beiigang
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。