Skip to content

Instantly share code, notes, and snippets.

@mberberoglu
Created June 15, 2015 14:39
Show Gist options
  • Save mberberoglu/c9cbd0a21516f7f2fa22 to your computer and use it in GitHub Desktop.
Save mberberoglu/c9cbd0a21516f7f2fa22 to your computer and use it in GitHub Desktop.
MongoDB Sharding
sudo service mongodb stop
// /etc/init/mongo.conf u açıp --configsvr ekleyin
sudo vim /etc/init/mongodb.conf
"exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf;"
//Üstteki satır ile değistirin
"exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --configsvr --config /etc/mongodb.conf;"
//mongodb servisini başlatın
sudo service mongodb start
//Büyük boyutta veri girme
mongos> data = "";while ( data.length < 100000 )data += "MongoDB Sharding";for ( var num = 0; num < 10000; num++ ){db.ShardedData.save( { data : data } );}
mongos> use config
//Tüm chunkları görüntüleme
mongos> db.chunks.find();
//Sharded Cluster'ın durumunu görüntüleme
mongos> db.printShardingStatus();
--- Sharding Status ---
sharding version: { "_id" : 1, "version" : 3 }
shards:
{ "_id" : "Shard_Galactica", "host" : "SHARD_1_IP:27018" }
{ "_id" : "Shard_Pegasus", "host" : "SHARD_2_IP:27018" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "ShardDB", "partitioned" : true, "primary" : "Shard_Galactica" }
ShardDB.ShardedData chunks:
Shard_Galactica 15
Shard_Pegasus 12
too many chunks to print, use verbose if you want to force print
mongos>
sudo service mongodb stop
//config server'ı ayarlamak için, mongos'u configdb parametresi ile başlatın
mongos --configdb IP-ADRESI
//Aşağıdaki gibi bir mesaj almalısınız:
//”config servers and shards contacted successfully”
//Aynı server'a tekrar başlanıp admin veritabanına girin
mongo admin
//Routing server'a shard serverları ekleyin
mongos>db.runCommand( { addshard : "SHARD_1_IP:27018", name : "Shard_Galactica" } );
mongos>db.runCommand( { addshard : "SHARD_2_IP:27018", name : "Shard_Pegasus" } );
// "ShardDB" veritabanında sharding'i aktifleştirin
mongos> db.runCommand( { enablesharding : "ShardDB" } );
{ "ok" : 1 }
//"ShardedData" Collection'ında shard edebilmek için bir key seçilmeli
mongos> db.runCommand( { shardcollection : "ShardDB.ShardedData", key : { _id : 1 } } );
#output
{ "collectionsharded" : "ShardDB.ShardedData", "ok" : 1 }
mongos> show dbs
admin (empty)
config 0.046875GB
ShardDB 0.203125GB
sudo service mongodb stop
// /etc/init/mongo.conf u açıp --shardsvr ekleyin
sudo vi /etc/init/mongodb.conf
"exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf;"
//Üstteki satır ile değistirin
"exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --shardsvr --config /etc/mongodb.conf;"
// mongodb servisini başlatın
sudo service mongodb start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment