MongoDB是开源文档数据库,提供共性能、高可用、自动扩展等。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
2
[root@linuxidc 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@linuxidc mongodb]#
3
拷贝的规划的文件夹
[root@linuxidc mongodb]# mv mongodb-linux-x86_64-2.6.7 /opt/mongodb
4
配置环境变量
[root@linuxidc ~]# vi .bash_profile
PATH=$PATH:/opt/mongodb/bin
5
数据所在文件夹
[root@linuxidc mongodb]# mkdir dbdata
6
使用户 mongod可以读写数据所在文件夹
[root@linuxidc mongodb]# useradd -r mongod
[root@linuxidc mongodb]# chown mongod:mongod dbdata/
7
启动
[root@linuxidc mongodb]# mongod --dbpath dbdata
2015-02-13T17:56:23.704+0800 [initandlisten] MongoDB starting : pid=2035 port=27017 dbpath=dbdata 64-bit host=linuxidc
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