您好,登錄后才能下訂單哦!
序號(hào) 角色 ip地址 備注
1 服務(wù)器 192.168.8.81 (config server)
2 路由 192.168.8.82 (mongos)
3 分片節(jié)點(diǎn) 192.168.8.83 (shard)
4 分片節(jié)點(diǎn) 192.168.8.84 (shard)
fork = true
pidfilepath = /var/run/mongodb/mongod.pid
logpath = /var/log/mongodb/mongod.log
unixSocketPrefix = /var/run/mongodb
dbpath = /var/lib/mongodb
port=27017
configsvr=true
b. 啟動(dòng)服務(wù):
systemctl start mongod
fork = true
pidfilepath = /var/run/mongodb/mongod.pid
logpath = /var/log/mongodb/mongod.log
unixSocketPrefix = /var/run/mongodb
#dbpath = /var/lib/mongodb (注釋掉數(shù)據(jù)庫(kù))
port=27017
configdb=192.168.8.81:27017
b. 刪除數(shù)據(jù)庫(kù)中的文件:
rm -rf /var/lib/mongodb/*
c. 啟動(dòng)服務(wù):
mongos -f /etc/mongod.conf
fork = true
pidfilepath = /var/run/mongodb/mongod.pid
logpath = /var/log/mongodb/mongod.log
unixSocketPrefix = /var/run/mongodb
dbpath = /var/lib/mongodb
b. 啟動(dòng)服務(wù):
systemctl start mongod
mongo
a-2. 添加分片機(jī):
sh.addShard("192.168.8.83:27017")
sh.addShard("192.168.8.84:27017")
a-3. 查看分片機(jī)狀態(tài):
sh.status()
a-4. 添加分片數(shù)據(jù)庫(kù):
sh.enableSharding("testdb")
a-5. 添加索引:
sh.shardCollection("testdb.user",{name:1,age:1})
a-6. 添加測(cè)試數(shù)據(jù):
for (i = 1;i < 100000; i++)
{
db.user.insert({name:'user'+i,age:(i%150),addr:'#'+i}
}
b. 分片機(jī)(192.168.8.83/84):
b-1. 進(jìn)入終端:
mongo
b-2. 查看經(jīng)過(guò)分片處理的數(shù)據(jù):
use testdb
db.user.find()
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。