彼此互相分散資料也互相備份
缺點是Config Server在原本設計上要另外1台
但成本考量散佈在其中三台上
其實安全性很低,純粹用來測試大資料計算用的
以下為詳細安裝紀錄
Authorization:
openssl rand -base64 741 > mongodb-keychmod 600 mongodb-key
<scp to mdb0, mdb1, mdb2, mdb3, mdb4, mdb5>
Step by Step:
MDB0-configsvr:
(到官網下載tgz檔) mongodb-linux-x86_64-2.6.3.tgz into ~/temp
tar -xvf *.tar
cp ~temp/mongodb-linux-x86_64-2.6.3/bin ~/bin -r
mkdir configdb
mkdir log
mkdir log/configsvr
~/bin/mongod --configsvr -dbpath ~/configdb/ --port 20000 --keyFile ~/bin/mongodb-key --logpath ~/log/configsvr/log --fork
MDB1-configsvr:
mongodb-linux-x86_64-2.6.3.tgz into ~/temp
tar -xvf *.tar
cp ~temp/mongodb-linux-x86_64-2.6.3/bin ~/bin -r
mkdir configdb
mkdir log
mkdir log/configsvr
~/bin/mongod --configsvr -dbpath ~/configdb/ --port 20001 --keyFile ~/bin/mongodb-key --logpath ~/log/configsvr/log --fork
MDB2-configsvr:
mongodb-linux-x86_64-2.6.3.tgz into ~/temp
tar -xvf *.tar
cp ~temp/mongodb-linux-x86_64-2.6.3/bin ~/bin -r
mkdir configdb
mkdir log
mkdir log/configsvr
~/bin/mongod --configsvr -dbpath ~/configdb/ --port 20002 --keyFile ~/bin/mongodb-key --logpath ~/log/configsvr/log --fork
MDB0-shardsvr:
mkdir ~/data
mkdir ~/log/shardsvr
~/bin/mongod --shardsvr --dbpath ~/data --port 10000 --replSet part1 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork
mkdir ~/arb
mkdir ~/log/arb
~/bin/mongod --shardsvr --dbpath ~/arb --port 30000 --replSet part1 --keyFile ~/bin/mongodb-key --logpath ~/log/arb/log --fork
MDB1-shardsvr:
mkdir ~/data
mkdir ~/log/shardsvr
~/bin/mongod --shardsvr --dbpath ~/data --port 10001 --replSet part2 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork
mkdir ~/arb
mkdir ~/log/arb
~/bin/mongod --shardsvr --dbpath ~/arb --port 30001 --replSet part2 --keyFile ~/bin/mongodb-key --logpath ~/log/arb/log --fork
MDB2-shardsvr:
mkdir ~/data
mkdir ~/log/shardsvr
~/bin/mongod --shardsvr --dbpath ~/data --port 10002 --replSet part3 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork
mkdir ~/arb
mkdir ~/log/arb
~/bin/mongod --shardsvr --dbpath ~/arb --port 30002 --replSet part3 --keyFile ~/bin/mongodb-key --logpath ~/log/arb/log --fork
MDB3-shardsvr:
mongodb-linux-x86_64-2.6.3.tgz into ~/temp
tar -xvf *.tart
cp ~temp/mongodb-linux-x86_64-2.6.3/bin ~/bin -r
mkdir ~/data
mkdir ~/log/shardsvr
~/bin/mongod --shardsvr --dbpath ~/data --port 10003 --replSet part1 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork
~/bin/mongo mdb0.test.com --port 10000
> rs.initiate({_id: "part1", members: [{_id: 0, host: "mdb0.test.com:10000"}, {_id: 3, host: "mdb3.test.com:10003"}]})
> rs.addArb("mdb0.test.com:30000")
MDB4-shardsvr:
mongodb-linux-x86_64-2.6.3.tgz into ~/temp
tar -xvf *.tart
cp ~temp/mongodb-linux-x86_64-2.6.3/bin ~/bin -r
mkdir ~/data
mkdir ~/log/shardsvr
~/bin/mongod --shardsvr --dbpath ~/data --port 10004 --replSet part2 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork
~/bin/mongo mdb1.test.com --port 10001
> rs.initiate({_id: "part2", members: [{_id: 1, host: "mdb1.test.com:10001"}, {_id: 4, host: "mdb4.test.com:10004"}]})
> rs.addArb("mdb1.test.com:30001")
MDB5-shardsvr:
mongodb-linux-x86_64-2.6.3.tgz into ~/temp
tar -xvf *.tart
cp ~temp/mongodb-linux-x86_64-2.6.3/bin ~/bin -r
mkdir ~/data
mkdir ~/log/shardsvr
~/bin/mongod --shardsvr --dbpath ~/data --port 10005 --replSet part3 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork
~/bin/mongo mdb2.test.com --port 10002
> rs.initiate({_id: "part3", members: [{_id: 2, host: "mdb2.test.com:10002"}, {_id: 5, host: "mdb5.test.com:10005"}]})
> rs.addArb("mdb2.test.com:30002")
MDB0-mongos: (First)
mkdir ~/log/mongos
~/bin/mongos --configdb mdb0.test.com:20000,mdb1.test.com:20001,mdb2.test.com:20002 --keyFile ~/bin/mongodb-key --logpath ~/log/mongos/log --fork
~/bin/mongo
> sh.addShard("part1/mdb0.test.com:10000,mdb3.test.com:10003")
> sh.addShard("part2/mdb1.test.com:10001,mdb4.test.com:10004")
> sh.addShard("part3/mdb2.test.com:10002,mdb5.test.com:10005")
> use admin
> show roles
> db.createUser({
user : <ADMIN ACCOUNT>,
pwd : <PASSWORD>,
user : <ADMIN ACCOUNT>,
pwd : <PASSWORD>,
roles:["root"]
})
> db.createUser({
user : <ADMIN ACCOUNT>,
pwd : <PASSWORD>,
pwd : <PASSWORD>,
roles:["userAdminAnyDatabase"]
})
> db.createUser({
user : 'test',
pwd : 'test123',
roles:[
{role: "dbOwner", db: "test" },
{role: "readWrite", db: "test2" },
{role: "read", db: "test1" },
]
})
pwd : 'test123',
roles:[
{role: "dbOwner", db: "test" },
{role: "readWrite", db: "test2" },
{role: "read", db: "test1" },
]
})
MDB1-mongos: (Second)
mkdir ~/log/mongos
~/bin/mongos --configdb mdb0.test.com:20000,mdb1.test.com:20001,mdb2.test.com:20002 --keyFile ~/bin/mongodb-key --logpath ~/log/mongos/log --fork
MDB3-mongos: (Third)
mkdir ~/log/mongos
~/bin/mongos --configdb mdb0.test.com:20000,mdb1.test.com:20001,mdb2.test.com:20002 --keyFile ~/bin/mongodb-key --logpath ~/log/mongos/log --fork
Done.
Structure of 6 Mongo DBs:
cs = config serve, ms = master server(mongos), ss = sharding server, part? = cluster of replicate serverscs[m0, m1, m2] <=> ms[m0, m1, m3] <=> ss[ part1(m0, m3), part2(m1, m4), part3(m2, m5) ]
Function Testing:
- Replicating with Sharding Process目的: 檢查塞入資料是否分散在各個shard & replicate server中
操作: 將10000筆資料塞入 db(test).collection(test)中
方法:use test; db.test.save({'key': <%range(10000)%>, 'value': <%range(10000)%> })
結果:不確定. 全部data都集中在Part1
改善嘗試:- 設定sharding db
sh.enableSharding('test') - 設定sharding key
sh.shardCollection("test.test", { "key": 1, "_id": 1 })
- 設定sharding db
- Ensure Sharding目的: 檢查塞入資料是否分散在各個shard & replicate server中
操作: 將10000筆大內容資料塞入 db(test).collection(test)中
方法:use test; db.test.save({'key': <%range(10000)%>, 'value': <%range(10000)%> })
結果:一開始會依照內容分成part1和part2, 直到資料量大到一定程度, 就會切割更多chuck, 若嫌資料不夠平均, 可以用sh.shardAt("<%database%>.<%collection%>",{"key":<%shard key%>})來強制切割- 需再嘗試:
- 測試開啟不同DB是否會啟用不同的shard
- 測試DB斷線是否正常
- DB Disconnection
測試目的:測試在shard斷線後是否能夠正常執行
方法:在塞入資料過程中將mdb0斷線
結果:可正常執行。在Client端沒有發現異常,資料全在mdb3中, 再次塞入資料會放置到part2中 - Create New DB
目的:建立新的DB是否會分散在不同的partition
操作:建立新的DB並塞入資料
結果:Seccuess. DB會建立在不同Partition(part3). 但這次沒有加入sh.enableSharding可能不會做資料切割.
rc.local Settings:
開機自動啟動設定MDB0:
su ubuntu -c "~/bin/mongod --configsvr -dbpath ~/configdb/ --port 20000 --keyFile ~/bin/mongodb-key --logpath ~/log/configsvr/log --fork"
su ubuntu -c "~/bin/mongod --shardsvr --dbpath ~/data --port 10000 --replSet part1 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork"
su ubuntu -c "~/bin/mongod --shardsvr --dbpath ~/arb --port 30000 --replSet part1 --keyFile ~/bin/mongodb-key --logpath ~/log/arb/log --fork"
su ubuntu -c "~/bin/mongos --configdb mdb0.test.com:20000,mdb1.test.com:20001,mdb2.test.com:20002 --keyFile ~/bin/mongodb-key --logpath ~/log/mongos/log --fork"
MDB1:
su ubuntu -c "~/bin/mongod --configsvr -dbpath ~/configdb/ --port 20001 --keyFile ~/bin/mongodb-key --logpath ~/log/configsvr/log --fork"
su ubuntu -c "~/bin/mongod --shardsvr --dbpath ~/data --port 10001 --replSet part2 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork"
su ubuntu -c "~/bin/mongod --shardsvr --dbpath ~/arb --port 30001 --replSet part2 --keyFile ~/bin/mongodb-key --logpath ~/log/arb/log --fork"
su ubuntu -c "~/bin/mongos --configdb mdb0.test.com:20000,mdb1.test.com:20001,mdb2.test.com:20002 --keyFile ~/bin/mongodb-key --logpath ~/log/mongos/log --fork"
MDB2:
su ubuntu -c "~/bin/mongod --configsvr -dbpath ~/configdb/ --port 20002 --keyFile ~/bin/mongodb-key --logpath ~/log/configsvr/log --fork"
su ubuntu -c "~/bin/mongod --shardsvr --dbpath ~/data --port 10002 --replSet part3 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork"
su ubuntu -c "~/bin/mongod --shardsvr --dbpath ~/arb --port 30002 --replSet part3 --keyFile ~/bin/mongodb-key --logpath ~/log/arb/log --fork"
MDB3:
su tech -c "~/bin/mongod --shardsvr --dbpath ~/data --port 10003 --replSet part1 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork"
su tech -c "~/bin/mongos --configdb mdb0.test.com:20000,mdb1.test.com:20001,mdb2.test.com:20002 --keyFile ~/bin/mongodb-key --logpath ~/log/mongos/log --fork"
MDB4:
su tech -c "~/bin/mongod --shardsvr --dbpath ~/data --port 10004 --replSet part2 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork"
MDB5:
su tech -c "~/bin/mongod --shardsvr --dbpath ~/data --port 10005 --replSet part3 --keyFile ~/bin/mongodb-key --logpath ~/log/shardsvr/log --fork"
沒有留言:
張貼留言