MongoDB 基本NoSQL的大数据数据存储工具,内部数据以文档的概念存储BSON(Binary JSON)。
全部的数据存储概念均离不开“分片”(数据的横向扩展,以分离存储的方式提升数据存储、检索的性能)、“复制”(高可用,包含冗余备份、故障自检、自动恢复、读写分离等功能)。
本文不会详细介绍MongoDB基础及分布概念,读者能够自行查阅学习。html
# uname -a Linux 1ddc8b08470a 4.9.49-moby #1 SMP Thu Sep 21 05:50:41 UTC 2017 x86_64 GNU/Linux
# mongo -version MongoDB shell version v3.4.10 git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9 OpenSSL version: OpenSSL 1.0.1t 3 May 2016 allocator: tcmalloc modules: none build environment: distmod: debian81 distarch: x86_64 target_arch: x86_64
# mkdir /data/log # mkdir /data/db1 # nohup mongod --port 27020 --dbpath=/data/db1 --logpath=/data/log/rs0-1.log --logappend --fork --shardsvr --replSet=rs0 & # mkdir /data/db2 # nohup mongod --port 27021 --dbpath=/data/db2 --logpath=/data/log/rs0-2.log --logappend --fork --shardsvr --replSet=rs0 &
# mongo localhost:27020 > rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'localhost:27020'}, {_id: 1, host: 'localhost:27021'}]}) > rs.isMaster() #查看主从关系
# mkdir /data/db3 # nohup mongod --port 27030 --dbpath=/data/db3 --logpath=/data/log/rs1-1.log --logappend --fork --shardsvr --replSet=rs1 & # mkdir /data/db4 # nohup mongod --port 27031 --dbpath=/data/db4 --logpath=/data/log/rs1-2.log --logappend --fork --shardsvr --replSet=rs1 &
# mongo localhost:27030 > rs.initiate({_id: 'rs1', members: [{_id: 0, host: 'localhost:27030'}, {_id: 1, host: 'localhost:27031'}]}) > rs.isMaster() #查看主从关系
# mkdir /data/conf1 # nohup mongod --port 27100 --dbpath=/data/conf1 --logpath=/data/log/conf-1.log --logappend --fork --configsvr --replSet=conf & # mkdir /data/conf2 # nohup mongod --port 27101 --dbpath=/data/conf2 --logpath=/data/log/conf-2.log --logappend --fork --configsvr --replSet=conf &
# mongo localhost:27100 > rs.initiate({_id: 'conf', members: [{_id: 0, host: 'localhost:27100'}, {_id: 1, host: 'localhost:27101'}]}) > rs.isMaster() #查看主从关系
# nohup mongos --port 40000 --configdb conf/localhost:27100,localhost:27101 --fork --logpath=/data/log/route.log --logappend &
# mongo localhost:40000 > use admin > db.runCommand({ addshard: 'rs0/localhost:27020,localhost:27021'}) > db.runCommand({ addshard: 'rs1/localhost:27030,localhost:27031'}) > db.runCommand({ enablesharding: 'test'}) > db.runCommand({ shardcollection: 'test.user', key: {name: 1}})
经过以上步骤操做,即可以直接链接 40000端口的mongdos享用分片及复制功能。git
基本大数据分布式背景而生的产品,在分布式集群配置上仍是很简单方便的。这里仅仅是一个基本的操做演示,更多的功能还须要读者去深刻了解。mongodb