標籤:centos7下mongodb分區配置
伺服器架構:序號 角色 ip地址 備忘1 伺服器 192.168.8.81 (config server)2 路由 192.168.8.82 (mongos)3 分區節點 192.168.8.83 (shard)4 分區節點 192.168.8.84 (shard)
伺服器配置(192.168.8.81):
a. 修改設定檔:
vim /etc/mongod.conffork = truepidfilepath = /var/run/mongodb/mongod.pidlogpath = /var/log/mongodb/mongod.logunixSocketPrefix = /var/run/mongodbdbpath = /var/lib/mongodbport=27017configsvr=true
b. 啟動服務:
systemctl start mongod
路由配置(192.168.8.82):
a. 修改設定檔:
vim /etc /mongod.conffork = truepidfilepath = /var/run/mongodb/mongod.pidlogpath = /var/log/mongodb/mongod.logunixSocketPrefix = /var/run/mongodb#dbpath = /var/lib/mongodb (注釋掉資料庫)port=27017configdb=192.168.8.81:27017
b. 刪除資料庫中的檔案:
rm -rf /var/lib/mongodb/*
c. 啟動服務:
mongos -f /etc/mongod.conf
分區機配置(192.168.8.83/84):
a. 修改設定檔:
vim /etc/mongod.conffork = truepidfilepath = /var/run/mongodb/mongod.pidlogpath = /var/log/mongodb/mongod.logunixSocketPrefix = /var/run/mongodbdbpath = /var/lib/mongodb
b. 啟動服務:
systemctl start mongod
測試:
a. 路由機(192.168.8.82):
a-1. 進入終端:mongo
a-2. 添加分區機:
sh.addShard("192.168.8.83:27017")sh.addShard("192.168.8.84:27017")
a-3. 查看分區機狀態:
sh.status()
a-4. 添加分區資料庫:
sh.enableSharding("testdb")
a-5. 添加索引:
sh.shardCollection("testdb.user",{name:1,age:1})
a-6. 添加測試資料:
for (i = 1;i < 100000; i++) { db.user.insert({name:‘user‘+i,age:(i%150),addr:‘#‘+i} }
b. 分區機(192.168.8.83/84):
b-1. 進入終端:
mongo
b-2. 查看經過分區處理的資料:
use testdbdb.user.find()
centos7下mongodb分區配置