본문 바로가기
DB,SQL

MongoDB Sharding & Arbiter

by violetoz 2014. 6. 24.

=================================================================node2
http://www.mongodb.org/downloads
 
tar file Download
 
cd ~/Downloads
 
tar -zxvf mongodb-linux-x86_64-2.6.1.tgz
 
sudo mv mongodb-linux-x86_64-2.6.1 /opt/mongodb
 
sudo gedit ~/.bashrc
 
export PATH=/opt/mongodb/bin:$PATH
 
source ~/.bashrc
 
------------------------------------------------------------------------------
 
sudo mkdir -p /data
 
cd /data
 
sudo mkdir -p config2 shard2 shard1_s arbit3
 
sudo chmod 777 -R /data
 
mongod --configsvr --dbpath /data/config2 --port 10000
 
mongod --dbpath /data/shard2 --shardsvr --port 10001 --replSet prigent2 --oplogSize 10 --rest
mongod --dbpath /data/shard1_s --port 10002 --replSet prigent1 --oplogSize 10 --rest
mongod --dbpath /data/arbit3 --port 10003 --replSet prigent3 --oplogSize 10 --rest
 
------------------------------------------------------------------------------------
 


 =================================================================node3

tar file Download
 
cd ~/Downloads
 
tar -zxvf mongodb-linux-x86_64-2.6.1.tgz
 
sudo mv mongodb-linux-x86_64-2.6.1 /opt/mongodb
 
sudo gedit ~/.bashrc
 
export PATH=/opt/mongodb/bin:$PATH
 
source ~/.bashrc
 
------------------------------------------------------------------------------
 
sudo mkdir -p /data
 
cd /data
 
sudo mkdir -p config3 shard3 shard2_s arbit1
 
sudo chmod 777 -R /data
 
 
mongod --configsvr --dbpath /data/config3 --port 10000
 
mongod --dbpath /data/shard3 --shardsvr --port 10001 --replSet prigent3 --oplogSize 10 --rest
mongod --dbpath /data/shard2_s --port 10002 --replSet prigent2 --oplogSize 10 --rest
mongod --dbpath /data/arbit1 --port 10003 --replSet prigent1 --oplogSize 10 --rest
 
 
----------------------------------------------------------------------------------
 

 =================================================================node1

 
tar file Download 
 
cd ~/Downloads 
 
tar -zxvf mongodb-linux-x86_64-2.6.1.tgz 
 
sudo mv mongodb-linux-x86_64-2.6.1 /opt/mongodb 
 
sudo gedit ~/.bashrc 
 
export PATH=/opt/mongodb/bin:$PATH 
 
source ~/.bashrc 
 
------------------------------------------------------------------------------ 
 
sudo mkdir -p /data 
 
cd /data 
 
sudo mkdir -p config1 shard1 shard3_s arbit2 
 
sudo chmod 777 -R /data 
 
mongod --configsvr --dbpath /data/config1 --port 10000 
 
mongod --dbpath /data/shard1 --shardsvr --port 10001 --replSet prigent1 --oplogSize 10 --rest 
mongod --dbpath /data/shard3_s --port 10002 --replSet prigent3 --oplogSize 10 --rest 
mongod --dbpath /data/arbit2 --port 10003 --replSet prigent2 --oplogSize 10 --rest 
 
------------------------------------------------------------------------------------ 
 
mongos --configdb 118.217.4.61:10000,118.217.4.62:10000,118.217.4.63:10000  --port 10004 --chunkSize 1 
 
mongo 118.217.4.61:10004/admin 
 
db.runCommand({addshard:"118.217.4.61:10001"}) 
db.runCommand({addshard:"118.217.4.62:10001"}) 
db.runCommand({addshard:"118.217.4.63:10001"})  
 
--------------------------------------------------------------- 
 
mongo 118.217.4.61:10001/admin 
 
db.runCommand({"replSetInitiate":{"_id":"prigent1","members":[{"_id":1,"host":"118.217.4.61:10001"},{"_id":2,"host":"118.217.4.62:10002"},{"_id":3,"host":"118.217.4.63:10003",arbiterOnly:true}]}}) 
 
------------------------------------------------------------- 
 
mongo 118.217.4.62:10001/admin 
 
db.runCommand({"replSetInitiate":{"_id":"prigent2","members":[{"_id":1,"host":"118.217.4.62:10001"},{"_id":2,"host":"118.217.4.63:10002"},{"_id":3,"host":"118.217.4.61:10003",arbiterOnly:true}]}}) 
 
------------------------------------------------------------------- 
 
mongo 118.217.4.63:10001/admin 
 
db.runCommand({"replSetInitiate":{"_id":"prigent3","members":[{"_id":1,"host":"118.217.4.63:10001"},{"_id":2,"host":"118.217.4.61:10002"},{"_id":3,"host":"118.217.4.62:10003",arbiterOnly:true}]}}) 
 
--------------------------------------------------------------------- 
 
mongo 118.217.4.61:10004/admin 
 
db.runCommand({enablesharding:"test"}) 
 
use admin 
 
db.runCommand({shardcollection:"test.testtable",key:{testno:1}}) 
 
 
 
db.runCommand({listshards : 1}) 
 
-------------------------------------------------------------------------------------------------- 
 
mongo 118.217.4.61:10004/test 
 
for(var n = 10000; n <= 20000; n++) db.testtable.save({testno:n, testname:"test", kyj1:1000}) 
 
sh.status() 
 
 
 
mongo 118.217.4.61:10001/test 
 
db.testtable.count() 
 
 
mongo 118.217.4.62:10001/test 
 
db.testtable.count() 
 
 
mongo 118.217.4.63:10001/test 
 
db.testtable.count() 
 
------------------------------------------------------------------------------------------------- 
 
mongo 118.217.4.62:10002/admin 
 
exit 
 
mongo 118.217.4.61:10001/admin 
 
db.shutdownServer() 
 
exit 
 
mongo 118.217.4.62:10002/admin 
 
mongod --dbpath /data/shard1 --shardsvr --port 10001 --replSet prigent1 --oplogSize 10 --rest 
 
exit  
 
mongo 118.217.4.61:10001/admin 
 


'DB,SQL' 카테고리의 다른 글

MySQL C++ Connection Pool  (0) 2014.10.08
MongoDB Sharding ReplicaSet  (0) 2014.06.30
Mongodb sharding  (0) 2014.06.16
Redis 기초 명령어  (0) 2014.03.25
ZooKeeper를 활용한 Redis Cluster 관리  (0) 2014.03.21