Mongodb Sharding Replication 設定
Mongodb 3.x Sharding Replication 設定 (centos 6)
rs conf 範例:
cfg conf 範例:
rts conf 範例:
3台DB做Cluster,可以允許一台DB Server shut down。
3台DB為分散式架構。
Replication port: 28001、28002、28003
Config Server port: 2800 用來儲存每個
Shard 之間的狀態
Route Server:
27017 提供單一連線介面給 Client
Mongo Config 設定檔
mongo_rs1.conf -> 第一台Mongo DB Sharding Replication 設定
mongo_rs2.conf -> 第二台Mongo DB Sharding Replication 設定
mongo_rs3.conf -> 第三台Mongo DB Sharding Replication 設定
mongo_cfg.conf -> 每個 Shard 之間的設定
mongo_rts.conf -> Client 連線設定
1 Mongo 啟動程序
1.1 Linux設定
ulimit -n 64000
1.2 啟動三台DB 的Replication,Config Server
numactl --interleave=all /usr/bin/mongod -f /etc/mongo_rs1.conf
numactl --interleave=all /usr/bin/mongod -f /etc/mongo_rs2.conf
numactl --interleave=all /usr/bin/mongod -f /etc/mongo_rs3.conf
numactl --interleave=all /usr/bin/mongod -f /etc/mongo_cfg.conf
1.3 三台皆啟動完成後,啟動三台DB 的Route Server
numactl --interleave=all /usr/bin/mongos -f /etc/mongo_rts.conf
2 Mongo 重啟程序
2.1 關閉三台DB的Route Server
進入mongo命令列執行:
use admin
db.shutdownServer()
2.2 三台Route Server關閉成功後,關閉Replication,Config Server
/usr/bin/mongod -f /etc/mongo_cfg.conf --shutdown
/usr/bin/mongod -f /etc/mongo_rs3.conf --shutdown
/usr/bin/mongod -f /etc/mongo_rs2.conf --shutdown
/usr/bin/mongod -f /etc/mongo_rs1.conf --shutdown
2.3 關閉成功後,執行【啟動程序】
3 Mongo Replication 設定
3.1 設定Replication 1
mongo --host 172.16.80.201 --port 28001
rs.initiate() //Initiate the replica set
rs.conf() //Replication 設定檔
rs.add("172.16.80.202:28001")
rs.addArb("172.16.80.203:28001")
rs.status() //查看Replication狀態
3.2 設定Replication 2
mongo --host 172.16.80.202 --port 28002
rs.initiate() //Initiate the replica set
rs.conf() //Replication 設定檔
rs.addArb("172.16.80.201:28002")
rs.add("172.16.80.203:28002")
rs.status() //查看Replication狀態
3.3 設定Replication 3
mongo --host 172.16.80.203 --port 28003
rs.initiate() //Initiate the replica set
rs.conf() //Replication 設定檔
rs.addArb("172.16.80.202:28003")
rs.add("172.16.80.201:28003")
rs.status() //查看Replication狀態
4 Mongo sharding設定
4.1 Sharding 設定
mongo --host 127.0.0.1 --port 27017
sh.status() //查看shard狀態
sh.addShard( "rs1/172.16.80.201:28001,172.16.80.202:28001,172.16.80.203:28001" )
sh.addShard( "rs2/172.16.80.201:28002,172.16.80.202:28002,172.16.80.203:28002" )
sh.addShard( "rs3/172.16.80.201:28003,172.16.80.202:28003,172.16.80.203:28003" )
4.2 將要執行shard的資料庫加入
sh.enableSharding('test')
sh.shardCollection("test.tset", { _id:"hashed" } )
rs conf 範例:
storage:
journal:
enabled: true
dbPath: "/var/lib/mongo/rs1data"
engine: "wiredTiger"
wiredTiger:
engineConfig:
cacheSizeGB: 14
directoryForIndexes: true
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true
directoryPerDB: true
systemLog:
destination: file
path: "/var/log/mongo/rs1.log"
logAppend: true
timeStampFormat: iso8601-utc
processManagement:
pidFilePath: /var/run/mongo/rs1.pid
fork: true
net:
bindIp: "172.16.80.201"
port: 28001
replication:
replSetName: "rs1"
sharding:
clusterRole: "shardsvr"
cfg conf 範例:
storage:
journal:
enabled: true
dbPath: "/var/lib/mongo/config"
engine: "wiredTiger"
wiredTiger:
engineConfig:
cacheSizeGB: 14
directoryForIndexes: true
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true
directoryPerDB: true
systemLog:
destination: file
path: "/var/log/mongo/cfg.log"
logAppend: true
timeStampFormat: iso8601-utc
processManagement:
pidFilePath: /var/run/mongo/cfg.pid
fork: true
net:
bindIp: "172.16.80.201"
port: 28000
sharding:
clusterRole: "configsvr"
rts conf 範例:
systemLog:
destination: file
path: "/var/log/mongo/rts.log"
logAppend: true
timeStampFormat: iso8601-utc
processManagement:
pidFilePath: /var/run/mongo/rts.pid
fork: true
net:
bindIp: "172.16.80.201,127.0.0.1"
port: 27017
sharding:
configDB: 172.16.80.201:28000,172.16.80.202:28000,172.16.80.203:28000
chunkSize: 200
留言
張貼留言