侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 144671 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Mongodb Sharding Cluster 三台

2023-12-23 星期六 / 0 评论 / 0 点赞 / 9 阅读 / 2492 字

/* mongodb sharding cluster reference. http://www.linuxidc.com/Linux/2015-07/119597.htm http://my.os

/*
mongodb sharding cluster reference.
http://www.linuxidc.com/Linux/2015-07/119597.htm
http://my.oschina.net/costaxu/blog/196980
http://www.open-open.com/lib/view/open1418794710573.html
http://www.csdn.net/article/2012-11-15/2811920-mongodb-quan-gong-lue
http://www.lanceyan.com/tech/arch/mongodb_shard1.html
http://my.oschina.net/zhzhenqin/blog/97268
*/

//use three machine
//ip infomation
192.168.21.1 (root/powerall)
192.168.21.2
192.168.21.3
//mongodb ip mapping
192.168.21.1   shard1 (27017)
192.168.21.2   config server(27019) mongos()
192.168.21.3   shard2 (27017)
//download 3.0.7
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.7.tgz
tar zxvf mongodb-linux-x86_64-3.0.7.tgz
cp -rf mongodb-linux-x86_64-3.0.7 /usr/local/
//start configdb at 3 machine
mkdir -p /data/mongodb/configdb
#192.168.12.3
mkdir -p /data/mongodb/shard3
mkdir -p /data/mongodb/shardlog/
/usr/local/mongodb-linux-x86_64-3.0.7/bin/mongod -shardsvr -port 27017 -dbpath=/data/mongodb/shard3/ --storageEngine wiredTiger -logpath=/data/mongodb/shardlog/shard3.log --fork
#192.168.12.1
mkdir -p /data/mongodb/shard1
chmod -R 777 /data/mongodb/shard1
mkdir -p /data/mongodb/shardlog/
/usr/local/mongodb-linux-x86_64-3.0.7/bin/mongod -shardsvr -port 27017 -dbpath=/data/mongodb/shard1/ --storageEngine wiredTiger -logpath=/data/mongodb/shardlog/shard1.log --fork
#192.168.12.2
mkdir -p /data/mongodb/configdb
/usr/local/mongodb-linux-x86_64-3.0.7/bin/mongod --configsvr --dbpath /data/mongodb/configdb --port 27019
/usr/local/mongodb-linux-x86_64-3.0.7/bin/mongos -configdb 192.168.21.2:27019 -port 30000 -chunkSize 100 -logpath=/data/mongos.log --fork
/usr/local/mongodb-linux-x86_64-3.0.7/bin/mongo 192.168.21.2:27017/admin
#add shard server
db.runCommand({"addshard":"192.168.21.1:27017"})  
db.runCommand({"addshard":"192.168.21.3:27017"})  
#set db
db.runCommand({"enablesharding": "foxconn"}) 
use foxconnxc
#set up hash
sh.shardCollection("foxconn.resume_meta_data",{_id:"hashed"})
db.printShardingStatus() 

//
use testdb
db.runCommand({"enablesharding": "testdb"})
db.runCommand( { shardcollection : "testdb.table1",key : {id: 1} } )
for (var i = 1; i <= 100000; i++) db.table1.save({id:i,"test1":"testval1"});

广告 广告

评论区