MongoDB分布式
安装
scp mongodb-linux-x86_64-2.6.0.tgz user@host:/home/user/ ssh user@host tar zxvf mongodb-linux-x86_64-2.6.0.tgz mv mongodb-linux-x86_64-2.6.0 mongodb cd mongodb/ mkdir db
配置环境
sudo vi /etc/profile #mango export MANGO_HOME=/home/user/mongodb export PATH=$MANGO_HOME/bin:$MANGO_HOME:$PATH source /etc/profile
运行
(Pic src:http://docs.mongodb.org/manual/core/sharding-introduction/)
Diagram of a sample sharded cluster for production purposes. Contains exactly 3 config servers, 2 or more mongos query routers, and at least 2 shards. The shards are replica sets.
(pic src:http://blog.fens.me/mongodb-shard/)
#所有从服务器slave运行一个/两个终端 export LC_ALL="en_US.UTF-8" mongod --dbpath ~/hadoop/mongodb/db/ mongo #主服务器hdp001 运行3个终端 mongos --configdb hdp001 mongod --configsvr mongo
shard
#添加节点 sh.addShard("hdp002:27017") sh.enableSharding("test") sh.shardCollection("test.people", {user_id:1}) db.ss.insert( { name : "mongo" }) 然后在hdp002就有同步的数据了。其他从服务器类似 #删除节点 use admin db.runCommand({ movePrimary : "test", to : "config" }) db.runCommand( { removeShard :"shard0000"})