您好,登錄后才能下訂單哦!
共2臺服務器,每臺上面各一個路由,一個配置,一個分片,mongodb版本3.4
服務器1:10.2.4.214
服務器2:10.2.4.215
1.首先編寫2臺服務器的配置文件,并將配置文件中的路徑文件夾建立好
214的路由配置文件mongodb_rout.conf:
net: ???port:?5000 ???ipv6:?true systemLog: ???destination:?file ???path:?"/data/mongodb/formal_5000/log/route.log" ???logAppend:?true processManagement: ???fork:?true sharding: ???configDB:?rsConf/10.2.4.214:5100,10.2.4.215:5100 ...
214的配置配置文件mongodb_cfg.conf:
net: ???port:?5100 ???ipv6:?true storage: ???dbPath:?"/data/mongodb/formal_5000/data/config" ???directoryPerDB:?true systemLog: ???destination:?file ???path:?"/data/mongodb/formal_5000/log/config.log" ???logAppend:?true storage: ???journal: ??????enabled:?true processManagement: ???fork:?true sharding: ???clusterRole:?configsvr replication: ???replSetName:?rsConf ...
214的分片配置文件mongodb_s0.conf:
storage: ???dbPath:?"/data/mongodb/formal_5000/data/s0" ???directoryPerDB:?true systemLog: ???destination:?file ???path:?"/data/mongodb/formal_5000/log/s0.log" ???logAppend:?true net: ???port:?5010 ???ipv6:?true processManagement: ???fork:?true storage: ???journal: ??????enabled:?true replication: ???replSetName:?rsShardA sharding: ???clusterRole:?shardsvr ...
215的路由配置文件mongodb_rout.conf:
net: ???port:?5000 ???ipv6:?true systemLog: ???destination:?file ???path:?"/data/mongodb/formal_5000/log/route.log" ???logAppend:?true processManagement: ???fork:?true sharding: ???configDB:?rsConf/10.2.4.214:5100,10.2.4.215:5100 ...
215的配置配置文件mongodb_cfg.conf:
net: ???port:?5100 ???ipv6:?true storage: ???dbPath:?"/data/mongodb/formal_5000/data/config" ???directoryPerDB:?true systemLog: ???destination:?file ???path:?"/data/mongodb/formal_5000/log/config.log" ???logAppend:?true storage: ???journal: ??????enabled:?true processManagement: ???fork:?true sharding: ???clusterRole:?configsvr replication: ???replSetName:?rsConf ...
215的分片配置文件mongodb_s0.conf:
storage: ???dbPath:?"/data/mongodb/formal_5000/data/s0" ???directoryPerDB:?true systemLog: ???destination:?file ???path:?"/data/mongodb/formal_5000/log/s0.log" ???logAppend:?true net: ???port:?5010 ???ipv6:?true processManagement: ???fork:?true storage: ???journal: ??????enabled:?true replication: ???replSetName:?rsShardB sharding: ???clusterRole:?shardsvr ...
在2臺服務器上執行下面命令建立文件夾,否則mongodb無法啟動
mkdir?-p?/data/mongodb/formal_5000/log/ mkdir?-p?/data/mongodb/formal_5000/data/config/ mkdir?-p?/data/mongodb/formal_5000/data/s0
2.啟動2臺配置服務,并配置成副本集
#在2臺服務器上都啟動配置服務 numactl?--interleave=all??mongod?-f?/etc/mongodb/formal_5000/mongodb_cfg.conf #進入其中一臺服務進行配置 mongo?--port?5100 config={_id:"rsConf",members:[ {_id:0,host:"10.2.4.214:5100"}, {_id:1,host:"10.2.4.215:5100"} ]} rs.initiate(config) #查看副本集配置是否成功 rs.status()
3.啟動2臺分片和路由服務,并配置
#在2臺服務器上都啟動分片服務 numactl?--interleave=all??mongod?-f?/etc/mongodb/formal_5000/mongodb_s0.conf #在2臺服務器上都啟動路由服務 numactl?--interleave=all??mongos?-f?/etc/mongodb/formal_5000/mongodb_rout.conf #進入214分片并配置分片成副本集的primary mongo?--port?5010 config={_id:"rsShardA",members:[ {_id:0,host:"10.2.4.214:5010"} ]} rs.initiate(config) #進入215分片并配置分片成副本集的primary mongo?--port?5010 config={_id:"rsShardB",members:[ {_id:0,host:"10.2.4.215:5010"} ]} rs.initiate(config) #進入路由并配置分片 mongo?--port?5000 use?admin db.runCommand({addshard:"rsShardA/10.2.4.214:5010",name:"shard_0",maxSize:0}) db.runCommand({addshard:"rsShardB/10.2.4.215:5010",name:"shard_1",maxSize:0}) #查看分片配置情況 sh.status()
4.設置monitor_center可分片
use?monitor_center use?admin db.runCommand({enablesharding:"monitor_center"})
5.使用Studio-3T連接路由、配置和分片并建立用戶(這里教程省略)
6.關閉數據庫
#先關路由,進入2臺服務器的路由 mongo?--port?5000 use?admin db.shutdownServer() #再關分片,進入2臺服務器的分片 mongo?--port?5010 use?admin db.shutdownServer({force:true}) #最后關配置,進入2臺服務器的配置 mongo?--port?5100 use?admin db.shutdownServer()
7.將keyfile加入到2臺服務器的路由、配置、分片的配置文件中的最后一行里,如下所示:
214的路由配置文件mongodb_rout.conf:
net: ???port:?5000 ???ipv6:?true systemLog: ???destination:?file ???path:?"/data/mongodb/formal_5000/log/route.log" ???logAppend:?true processManagement: ???fork:?true sharding: ???configDB:?rsConf/10.2.4.214:5100,10.2.4.215:5100 security: ???keyFile:?"/data/mongodb/formal_5000/key/mongodb_key" ...
其他配置文件類似,都需要添加keyfile
#生成keyFile mkdir?-p?/data/mongodb/formal_5000/key/ cd?/data/mongodb/formal_5000/key echo?-e?"formal?mongodb?keyFile"?>?mongodb_key chmod?600?/data/mongodb/formal_5000/key/mongodb_key
8.最后依次啟動配置、分片、路由
numactl?--interleave=all??mongod?-f?/etc/mongodb/formal_5000/mongodb_cfg.conf numactl?--interleave=all??mongod?-f?/etc/mongodb/formal_5000/mongodb_s0.conf numactl?--interleave=all??mongos?-f?/etc/mongodb/formal_5000/mongodb_rout.conf
PS:
1.平衡器
sh.setBalancerState(true)?#啟動平衡器 sh.setBalancerState(false)?#關閉平衡器 sh.getBalancerState()?#查看平衡器的狀態 sh.isBalancerRunning()?#查看平衡器當前是否在運行 #設置平衡器啟動時間范圍,首先確保平衡器是啟動狀態 db.settings.update({?_id:?"balancer"?},{?$set:?{?activeWindow?:?{?start?:?"21:00",?stop?:?"08:00"?}?}?},{?upsert:?true?}) #取消平衡器啟動時間范圍 db.settings.update({?_id?:?"balancer"?},?{?$unset?:?{?activeWindow?:?true?}?})
2.建表
use?monitor_center db.createCollection("origdata_20171024")?#建表 db.origdata_20171024.createIndex({?mac:?1,?time:?1},{?background:?true})?#建索引 use?admin db.runCommand({shardcollection:"monitor_center.origdata_20171024",key:{mac:1,time:1}})?#集合是否允許分片 db.runCommand({moveChunk:"monitor_center.origdata_20171024",bounds:[{mac:MinKey,time:MinKey},{mac:MaxKey,time:MaxKey}],to:"shard_1"})?#將集合手動移到分片1
3.表的遷移
sh.enableBalancing("monitor_center.origdata_20171024")?#開啟該集合的數據平衡 sh.disableBalancing("monitor_center.origdata_20171024")?#關閉該集合的數據平衡 db.getSiblingDB("config").collections.findOne({_id?:?"monitor_center.origdata_20171024"}).noBalance?#檢查該集合是否啟動了數據平衡
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。