我想在本地服務器上運行分片。 請幫我一步一步來。 我想在我的cpu(16核心)上創建mongod的多個實例。 順便說一句,我是包含700萬份文件的Collection,無論他們在運行碎片時是否失蹤?單機分片
我使用這個腳本用於在一個replicaSet創建3碎片:
# clean everything up
echo "killing mongod and mongos"
killall mongod
killall mongos
echo "removing data files"
rm -rf /media/mongo/data/config
rm -rf /media/mongo/data/shard*
rm -rf /data/config
rm -rf /data/shard*
# For mac make sure rlimits are high enough to open all necessary connections
ulimit -n 2048
# start a replica set and tell it that it will be shard0
mkdir -p /media/mongo/data/shard0/rs0
mongod --replSet s0 --logpath "/var/log/mongodb/s0-r0.log" --dbpath /media/mongo/data/shard0/rs0 --port 37017 --fork --shardsvr --smallfiles
sleep 5
# connect to one server and initiate the set
mongo --port 37017 << 'EOF'
config = { _id: "s0", members:[
{ _id : 0, host : "localhost:37017" },
]};
rs.initiate(config)
EOF
# start a replicate set and tell it that it will be a shard1
mkdir -p /media/mongo/data/shard1/rs0
mongod --replSet s1 --logpath "/var/log/mongodb/s1-r0.log" --dbpath /media/mongo/data/shard1/rs0 --port 47017 --fork --shardsvr --smallfiles
sleep 5
mongo --port 47017 << 'EOF'
config = { _id: "s1", members:[
{ _id : 0, host : "localhost:47017" },
]};
rs.initiate(config)
EOF
# start a replicate set and tell it that it will be a shard2
mkdir -p /media/mongo/data/shard2/rs0
mongod --replSet s2 --logpath "/var/log/mongodb/s2-r0.log" --dbpath /media/mongo/data/shard2/rs0 --port 57017 --fork --shardsvr --smallfiles
sleep 5
mongo --port 57017 << 'EOF'
config = { _id: "s2", members:[
{ _id : 0, host : "localhost:57017" },
]};
rs.initiate(config)
EOF
# now start 3 config servers
rm cfg-a.log cfg-b.log cfg-c.log
mkdir -p /media/mongo/data/config/config-a /media/mongo/data/config/config-b /media/mongo/data/config/config-c
mongod --logpath "/var/log/mongodb/cfg-a.log" --dbpath /media/mongo/data/config/config-a --port 57040 --fork --configsvr --smallfiles
mongod --logpath "/var/log/mongodb/cfg-b.log" --dbpath /media/mongo/data/config/config-b --port 57041 --fork --configsvr --smallfiles
mongod --logpath "/var/log/mongodb/cfg-c.log" --dbpath /media/mongo/data/config/config-c --port 57042 --fork --configsvr --smallfiles
# now start the mongos on port 27018
rm mongos-1.log
sleep 5
mongos --port 27018 --logpath "/var/log/mongodb/mongos-1.log" --configdb localhost:57040,localhost:57041,localhost:57042 --fork
echo "Waiting 60 seconds for the replica sets to fully come online"
sleep 60
echo "Connnecting to mongos and enabling sharding"
# add shards and enable sharding on the test db
mongo --port 27018 << 'EOF'
db.adminCommand({ addshard : "s0/"+"localhost:37017" });
db.adminCommand({ addshard : "s1/"+"localhost:47017" });
db.adminCommand({ addshard : "s2/"+"localhost:57017" });
db.adminCommand({enableSharding: "IBSng"});
EOF
sleep 5
echo "Done setting up sharded environment on localhost"
但我不知道如何在我的集合添加片鍵。 我的速度寫/讀(I/O)非常重要。
我希望你使用它來進行測試/試用設置,因爲在單臺機器上設置分片會破壞讀/寫可擴展性的目的。 – vmr 2014-10-09 09:38:20
那我該如何在單機上改進我的查詢呢? 在我的情況下,聚合查詢比postgresql要低得多。 請指導我以快速方式執行查詢。 – user255327 2014-10-11 05:50:37
在單個強大的服務器中更快速地查詢最好的想法是什麼? – user255327 2014-10-22 08:13:07