MongoDB分布式

时间:2014-06-09 20:43:24   收藏:0   阅读:226

安装

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

配置环境

bubuko.com,布布扣
sudo vi /etc/profile

#mango
export MANGO_HOME=/home/user/mongodb
export PATH=$MANGO_HOME/bin:$MANGO_HOME:$PATH 

source  /etc/profile
bubuko.com,布布扣

运行

bubuko.com,布布扣
#所有从服务器slave运行一个/两个终端
export LC_ALL="en_US.UTF-8"
mongod --dbpath ~/hadoop/mongodb/db/
mongo
#主服务器hdp001 运行3个终端
mongos --configdb hdp001
mongod --configsvr
mongo
bubuko.com,布布扣

shard

bubuko.com,布布扣
#添加节点
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"})
bubuko.com,布布扣

 

MongoDB分布式,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!