激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數(shù)據(jù)庫(kù)技術(shù)|

服務(wù)器之家 - 數(shù)據(jù)庫(kù) - MongoDB - MongoDB搭建高可用集群的完整步驟(3個(gè)分片+3個(gè)副本)

MongoDB搭建高可用集群的完整步驟(3個(gè)分片+3個(gè)副本)

2020-05-24 15:51For DBA MongoDB

這篇文章主要給大家介紹了關(guān)于MongoDB搭建高可用集群(3個(gè)分片+3個(gè)副本)的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MongoDB具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

配置腳本以及目錄下載:點(diǎn)我下載

一、規(guī)劃好端口ip

    架構(gòu)圖如下,任意抽取每個(gè)副本集中的一個(gè)分片(非仲裁節(jié)點(diǎn))可以組成一份完整的數(shù)據(jù)。

MongoDB搭建高可用集群的完整步驟(3個(gè)分片+3個(gè)副本)

    1. 第一個(gè)副本集rs1

?
1
2
3
share1 10.0.0.7:30011:/data/share_rs/share_rs1/share1/data/
share2 10.0.0.7:40011:/data/share_rs/share_rs1/share2/data/
share3 10.0.0.7:50011:/data/share_rs/share_rs1/share3/data/

    2. 第二個(gè)副本集rs2

?
1
2
3
share1 10.0.0.7:30012:/data/share_rs/share_rs2/share1/data/
share2 10.0.0.7:40012:/data/share_rs/share_rs2/share2/data/
share3 10.0.0.7:50012:/data/share_rs/share_rs2/share3/data/

    3. 第三個(gè)副本集rs3

?
1
2
3
share1 10.0.0.7:30013:/data/share_rs/share_rs3/share1/data/
share2 10.0.0.7:40013:/data/share_rs/share_rs3/share2/data/
share3 10.0.0.7:50013:/data/share_rs/share_rs3/share3/data/

    4.config server

?
1
2
3
config1 10.0.0.7:30002:/data/share_rs/config/config1/data/
config2 10.0.0.7:30002:/data/share_rs/config/config2/data/
config3 10.0.0.7:30002:/data/share_rs/config/config3/data/

    5. mongos

?
1
2
3
mongos1 10.0.0.7:30001:/data/share_rs/mongos/mongos1/data/
mongos2 10.0.0.7:30001:/data/share_rs/mongos/mongos2/data/
mongos3 10.0.0.7:30001:/data/share_rs/mongos/mongos3/data/

二、創(chuàng)建相應(yīng)的目錄

?
1
2
3
mkdir -p /data/share_rs/{share_rs1,share_rs2,share_rs3}/{share1,share2,share3}/{data,log}
mkdir -p /data/share_rs/mongos/{mongos1,mongos2,mongos3}/{data,log}
mkdir -p /data/share_rs/config/{config1,config2,config3}/{data,log}

三、配置mongs和config的配置文件(其他副本參考修改端口以及ip)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[mongo@mongo config1]$ cat mongo.conf
dbpath=/data/share_rs/config/config1/data/
logpath=/data/share_rs/config/config1/log/mongo.log
logappend=true
port=30002
fork=true
rest=true
httpinterface=true
configsvr=true
 
[mongo@mongo mongs1]$ cat mongo.conf
logpath=/data/share_rs/mongos/mongos1/log/mongo.log
logappend=true
port=30001
fork=true
configdb=10.0.0.7:30002,10.0.0.7:40002,10.0.0.7:50002
chunkSize=1

四、依次啟動(dòng)三個(gè)副本上的config服務(wù)器以及mongs服務(wù)器

?
1
2
3
4
5
6
7
mongod -f /data/share_rs/config/config1/mongo.conf
mongod -f /data/share_rs/config/config2/mongo.conf
mongod -f /data/share_rs/config/config3/mongo.conf
 
mongos -f /data/share_rs/mongos/mongos1/mongo.conf
mongos -f /data/share_rs/mongos/mongos2/mongo.conf
mongos -f /data/share_rs/mongos/mongos3/mongo.conf

五、配置mong分片的的配置文件(其他副本參考修改端口以及ip),同一個(gè)分片的副本集名稱(chēng)一樣,即replSet。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
第一個(gè)副本集的一個(gè)分片
[mongo@mongo share_rs1]$ cat share1/mongo.conf
dbpath=/data/share_rs/share_rs1/share1/data
logpath=/data/share_rs/share_rs1/share1/log/mongo.log
logappend=true
port=30011
fork=true
rest=true
httpinterface=true
replSet=rs1
shardsvr=true
 
第二個(gè)副本集的一個(gè)分片
[mongo@mongo share_rs2]$ cat share1/mongo.conf
dbpath=/data/share_rs/share_rs2/share1/data
logpath=/data/share_rs/share_rs2/share1/log/mongo.log
logappend=true
port=30012
fork=true
rest=true
httpinterface=true
replSet=rs2
shardsvr=true
 
第三個(gè)副本集的一個(gè)分片
[mongo@mongo share_rs1]$ cat share1/mongo.conf
dbpath=/data/share_rs/share_rs3/share1/data
logpath=/data/share_rs/share_rs3/share1/log/mongo.log
logappend=true
port=30013
fork=true
rest=true
httpinterface=true
replSet=rs3
shardsvr=true

六、啟動(dòng)各個(gè)分片以及相應(yīng)的副本

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mongod -f /data/share_rs/share_rs1/share1/mongo.conf
mongod -f /data/share_rs/share_rs1/share2/mongo.conf
mongod -f /data/share_rs/share_rs1/share3/mongo.conf
mongod -f /data/share_rs/share_rs2/share1/mongo.conf
mongod -f /data/share_rs/share_rs2/share2/mongo.conf
mongod -f /data/share_rs/share_rs2/share3/mongo.conf
mongod -f /data/share_rs/share_rs3/share1/mongo.conf
mongod -f /data/share_rs/share_rs3/share2/mongo.conf
mongod -f /data/share_rs/share_rs3/share3/mongo.conf
 
[mongo@mongo share_rs]$ ps -ef | grep mongo | grep share | grep -v grep
mongo  2480  1 0 12:50 ?  00:00:03 mongod -f /data/share_rs/share_rs1/share1/mongo.conf
mongo  2506  1 0 12:50 ?  00:00:03 mongod -f /data/share_rs/share_rs1/share2/mongo.conf
mongo  2532  1 0 12:50 ?  00:00:02 mongod -f /data/share_rs/share_rs1/share3/mongo.conf
mongo  2558  1 0 12:50 ?  00:00:03 mongod -f /data/share_rs/share_rs2/share1/mongo.conf
mongo  2584  1 0 12:50 ?  00:00:03 mongod -f /data/share_rs/share_rs2/share2/mongo.conf
mongo  2610  1 0 12:50 ?  00:00:02 mongod -f /data/share_rs/share_rs2/share3/mongo.conf
mongo  2636  1 0 12:50 ?  00:00:01 mongod -f /data/share_rs/share_rs3/share1/mongo.conf
mongo  2662  1 0 12:50 ?  00:00:01 mongod -f /data/share_rs/share_rs3/share2/mongo.conf
mongo  2688  1 0 12:50 ?  00:00:01 mongod -f /data/share_rs/share_rs3/share3/mongo.conf
mongo  3469  1 0 13:17 ?  00:00:00 mongod -f /data/share_rs/config/config1/mongo.conf
mongo  3485  1 0 13:17 ?  00:00:00 mongod -f /data/share_rs/config/config2/mongo.conf
mongo  3513  1 0 13:17 ?  00:00:00 mongod -f /data/share_rs/config/config3/mongo.conf
mongo  3535  1 0 13:18 ?  00:00:00 mongos -f /data/share_rs/mongos/mongos1/mongo.conf
mongo  3629  1 0 13:22 ?  00:00:00 mongos -f /data/share_rs/mongos/mongos2/mongo.conf
mongo  3678  1 0 13:22 ?  00:00:00 mongos -f /data/share_rs/mongos/mongos3/mongo.conf

七、設(shè)置副本集

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
1.登錄第一個(gè)副本的一個(gè)分片,為其設(shè)置副本集
mongo 127.0.0.1:30011/admin
config = { _id:"rs1", members:[
      {_id:0,host:"10.0.0.7:30011"},
      {_id:1,host:"10.0.0.7:40011"},
      {_id:2,host:"10.0.0.7:50011",arbiterOnly:true}
    ]
   }
 
-- >; 注意:這里id rs1 需要與副本集中的名稱(chēng)一樣即replSet的值
rs.initiate(config)
{ "ok" : 1 } -- >; 提示這個(gè)說(shuō)明初始化成功
 
2.登錄第二個(gè)副本的一個(gè)分片,為其設(shè)置副本集
 
mongo 127.0.0.1:30012/admin
config = { _id:"rs2", members:[
      {_id:0,host:"10.0.0.7:30012"},
      {_id:1,host:"10.0.0.7:40012"},
      {_id:2,host:"10.0.0.7:50012",arbiterOnly:true}
    ]
   }
rs.initiate(config)
{ "ok" : 1 } -- >; 提示這個(gè)說(shuō)明初始化成功
 
3.登錄第三個(gè)副本的一個(gè)分片,為其設(shè)置副本集
 
mongo 127.0.0.1:30013/admin
config = { _id:"rs3", members:[
      {_id:0,host:"10.0.0.7:30013"},
      {_id:1,host:"10.0.0.7:40013"},
      {_id:2,host:"10.0.0.7:50013",arbiterOnly:true}
    ]
   }
rs.initiate(config)
{ "ok" : 1 } -- >; 提示這個(gè)說(shuō)明初始化成功

八、目前前搭建了mongodb配置服務(wù)器、路由服務(wù)器,各個(gè)分片服務(wù)器,不過(guò)應(yīng)用程序連接mongos 路由服務(wù)器并不能使用分片機(jī)制,還需要在程序里設(shè)置分片配置,讓分片生效。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
連接到第一個(gè)mongos上
mongo 10.0.0.7:30001/admin
db.runCommand({addshard:"rs1/10.0.0.7:30011,10.0.0.7:40011,10.0.0.7:50011",allowLocal:true});
db.runCommand({addshard:"rs2/10.0.0.7:30012,10.0.0.7:40012,10.0.0.7:50012"});
db.runCommand({addshard:"rs3/10.0.0.7:30013,10.0.0.7:40013,10.0.0.7:50013"});
 
-- >; 將第一個(gè)分片的所有副本全部加入
-- >; 如里shard是單臺(tái)服務(wù)器,用 db.runCommand( { addshard : "[: ]" } )這樣的命令加入
-- >; 如果shard是副本集,用db.runCommand( { addshard : "replicaSetName/[:port][,serverhostname2[:port],…]" });這樣的格式表示.
 
mongos>; sh.status()
--- Sharding Status ---
 sharding version: {
  "_id" : 1,
  "minCompatibleVersion" : 5,
  "currentVersion" : 6,
  "clusterId" : ObjectId("57f33f4d35d9c494714adfa7")
}
 shards:
  { "_id" : "rs1", "host" : "rs1/10.0.0.7:30011,10.0.0.7:40011" }
  { "_id" : "rs2", "host" : "rs2/10.0.0.7:30012,10.0.0.7:40012" }
  { "_id" : "rs3", "host" : "rs3/10.0.0.7:30013,10.0.0.7:40013" }
 active mongoses:
  "3.2.7" : 3
 balancer:
  Currently enabled: yes
  Currently running: no
  Failed balancer rounds in last 5 attempts: 0
  Migration Results for the last 24 hours:
    No recent migrations
 databases:

九、將集合進(jìn)行分片。

?
1
2
3
4
5
6
7
8
9
db.runCommand({enablesharding:"testcol"});
-- >; 指定testdb分片生效
 
db.runCommand({shardcollection: "testcol.testdoc",key : {id: 1} } )
-- >; 指定數(shù)據(jù)庫(kù)里需要分片的集合和片鍵
 
-->; 插入測(cè)試數(shù)據(jù)
for (var i = 1; i <;= 100000; i++){ db.testdoc.save({id:i,"name":"harvey"})}; -- >; 查看該集合的狀態(tài)
db.testcol.stats();

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)服務(wù)器之家的支持。

原文鏈接:http://www.fordba.com/mongo_share_rs.html

延伸 · 閱讀

精彩推薦
  • MongoDB遷移sqlserver數(shù)據(jù)到MongoDb的方法

    遷移sqlserver數(shù)據(jù)到MongoDb的方法

    這篇文章主要介紹了遷移sqlserver數(shù)據(jù)到MongoDb的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下...

    聽(tīng)楓xl9682021-01-03
  • MongoDBMongoDB 內(nèi)存使用情況分析

    MongoDB 內(nèi)存使用情況分析

    都說(shuō) MongoDB 是個(gè)內(nèi)存大戶,但是怎么知道它到底用了多少內(nèi)存呢...

    MongoDB教程網(wǎng)10002020-09-29
  • MongoDB分布式文檔存儲(chǔ)數(shù)據(jù)庫(kù)之MongoDB分片集群的問(wèn)題

    分布式文檔存儲(chǔ)數(shù)據(jù)庫(kù)之MongoDB分片集群的問(wèn)題

    這篇文章主要介紹了分布式文檔存儲(chǔ)數(shù)據(jù)庫(kù)之MongoDB分片集群的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋...

    Linux-18743072020-12-20
  • MongoDBmongodb基本命令實(shí)例小結(jié)

    mongodb基本命令實(shí)例小結(jié)

    這篇文章主要介紹了mongodb基本命令,結(jié)合實(shí)例形式總結(jié)分析了MongoDB數(shù)據(jù)庫(kù)切換、查看、刪除、查詢等基本命令用法與操作注意事項(xiàng),需要的朋友可以參考下...

    dawn-liu3652020-05-26
  • MongoDBMongoDB憑什么躋身數(shù)據(jù)庫(kù)排行前五

    MongoDB憑什么躋身數(shù)據(jù)庫(kù)排行前五

    MongoDB以比去年同期超出65.96分的成績(jī)繼續(xù)雄踞榜單前五,這個(gè)增幅在全榜僅次于PostgreSQL的77.99,而其相對(duì)于4月份的6.10分的增長(zhǎng)也是僅次于微軟SQL Server排名...

    孫浩峰3892020-05-22
  • MongoDBMongoDB中javascript腳本編程簡(jiǎn)介和入門(mén)實(shí)例

    MongoDB中javascript腳本編程簡(jiǎn)介和入門(mén)實(shí)例

    作為一個(gè)數(shù)據(jù)庫(kù),MongoDB有一個(gè)很大的優(yōu)勢(shì)——它使用js管理數(shù)據(jù)庫(kù),所以也能夠使用js腳本進(jìn)行復(fù)雜的管理——這種方法非常靈活 ...

    MongoDB教程網(wǎng)6982020-04-24
  • MongoDBMongodb實(shí)現(xiàn)定時(shí)備份與恢復(fù)的方法教程

    Mongodb實(shí)現(xiàn)定時(shí)備份與恢復(fù)的方法教程

    這篇文章主要給大家介紹了Mongodb實(shí)現(xiàn)定時(shí)備份與恢復(fù)的方法教程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面...

    chenjsh364522020-05-13
  • MongoDBMongoDB安裝圖文教程

    MongoDB安裝圖文教程

    這篇文章主要為大家詳細(xì)介紹了MongoDB安裝圖文教程,分為兩大部分為大家介紹下載MongoDB和安裝MongoDB的方法,感興趣的小伙伴們可以參考一下 ...

    Yangyi.He6132020-05-07
主站蜘蛛池模板: 久久视频在线免费观看 | 中文字幕精品在线播放 | 久久亚洲精品11p | 噜噜色av| 精品一区二区三区欧美 | 鲁丝一区二区三区不属 | 色视频一区二区 | 国产精品av久久久久久网址 | 亚洲va在线 | 亚洲精品无码不卡在线播放he | 中文字幕在线观看91 | 视频一区二区精品 | 羞羞视频免费入口网站 | 亚洲一区二区中文 | 成人小视频免费在线观看 | 中文字幕一区二区三区久久 | 日本成人一区二区三区 | 国产午夜电影在线观看 | 国产精品久久久久久久久久尿 | 91网站链接| 久久成人国产精品 | av一二三四区 | 免费a级黄色片 | 欧美日韩精品不卡一区二区三区 | 国产亚洲精久久久久久蜜臀 | 国产色视频一区 | 爽爽淫人网 | 成人免费福利视频 | 国产精品久久久久久久久久三级 | 日韩av在线网址 | 免费在线观看成人av | 久草在线观看资源 | 国产女同疯狂激烈互摸 | 一区国产在线观看 | 成人在线视频在线观看 | 西川av在线一区二区三区 | 91久久久久久久久久久久久久 | 可以免费看av | 91免费在线视频 | 国产美女视频一区二区三区 | h色网站在线观看 |