91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mongodb之副本集的實現及故障自動轉移

發布時間:2020-06-26 12:28:46 來源:網絡 閱讀:803 作者:落軒易離落 欄目:MongoDB數據庫

Mongodb之副本集的實現----repliSet

準備三個節點:

RS1192.168.1.15527017

RS2192.168.1.11:27017

node1:192.168.1.112:27017

1、時間同步

ntpdate192.168.1.11

2、安裝mongodb服務

rpm包地址:https://repo.mongodb.org/yum/redhat

yum –y localinstall*.rpm

mkdir –p/mongodb/data

chown –Rmongod:mongod /mongodb/data

usermod –d/mongodb/data mongod

3、修改配置文件

vim /etc/mongod.conf

#dbPath:/var/lib/mongo

  dbPath: /mongodb/data

replication:啟用這項

  replSetName: testrs:給副本集定義一個名稱

然后同步到另外兩個節點

4、啟動mongod服務

service mongodstart

選擇192.168.1.155:27017這個服務登錄

mongo

help---àrs.help()---àrs.initiate()用此命令進行初始化

發現報錯如下:

mongodb之副本集的實現及故障自動轉移

該主機映射不到節點上,進行谷歌搜索查到原因,由于配置文件bindip綁定的是127.0.0.1上,而/etc/hosts文件中127.0.0.1hostname---RS1并沒有指定關聯于是做此修改

127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4 RS1

在最后加上hostname,于是重新初始化,發現果然解決問題

5、由于上步驟已經把服務都啟動起來了,于是繼續在192.168.1.155上進行添加主機

Rs.add(‘192.168.1.11:27017’)--à發現又報錯,如下圖

mongodb之副本集的實現及故障自動轉移

可以看出連接不上另外的節點,在155節點上進行嘗試登陸

mongo  --host 192.168.1.11 –port 27017發現還是登陸不上,翻看很多文章,描述的都不是很詳細,于是一個群友解決了疑惑,由于配置文件中bindip并沒有進行修改只是監聽的127.0.0.1,在一個系統中配置三個實例mongodb這種方式可以不用修改,但是現在是三臺不同的系統ip,于是得進行修改

net:

  port: 27017

  bindIp: 192.168.1.155將其他兩個節點也進行修改,添加為本機ip,而不是127.0.0.1,(當然bindip也可以綁定多個ip:192.168.1.155 127.0.0.1)然后在hosts文件中加入:

192.168.1.155  RS1

192.168.1.11  RS2

192.168.1.112  node1

完成以上步驟之后,然后進行再次添加

rs.add(‘192.168.1.11:27017’)-à

testrs:PRIMARY>rs.add('192.168.1.11:27017')

{ "ok": 1 }:沒有報錯于是成功

然后再次添加下個節點

rs.add(‘192.168.1.112:27017’)

rs.status():進行查看節點間的狀態

testrs:PRIMARY>rs.status()

{

      "set" : "testrs",

      "date" : ISODate("2016-07-26T04:21:32.729Z"),

      "myState" : 1,

      "term" : NumberLong(3),

      "heartbeatIntervalMillis" :NumberLong(2000),

      "members" : [

           {

                 "_id" : 0,

                 "name" :"RS1:27017",

                 "health" : 1,

                 "state" : 1,

                 "stateStr" :"PRIMARY",:主節點

                 "uptime" : 346,

                 "optime" : {

                      "ts" :Timestamp(1469506890, 1),

                      "t" :NumberLong(3)

                 },

                 "optimeDate" :ISODate("2016-07-26T04:21:30Z"),

                 "electionTime" :Timestamp(1469506554, 1),

                 "electionDate" :ISODate("2016-07-26T04:15:54Z"),

                 "configVersion" : 3,

                 "self" : true

           },

           {

                 "_id" : 1,

                 "name" :"192.168.1.11:27017",

                 "health" : 1,

                 "state" : 2,

                 "stateStr" :"SECONDARY",:從節點

                 "uptime" : 156,

                 "optime" : {

                      "ts" :Timestamp(1469506735, 1),

                      "t" :NumberLong(3)

                 },

                 "optimeDate" :ISODate("2016-07-26T04:18:55Z"),

                 "lastHeartbeat" :ISODate("2016-07-26T04:21:30.870Z"),

                 "lastHeartbeatRecv" :ISODate("2016-07-26T04:21:30.974Z"),

                 "pingMs" :NumberLong(1),

                 "configVersion" : 2

           },

           {

                 "_id" : 2,

                 "name" : "192.168.1.112:27017",

                 "health" : 1,

                 "state" : 0,

                 "stateStr" :"STARTUP",:由于是剛剛添加,正在開啟

                 "uptime" : 1,

                 "optime" : {

                      "ts" :Timestamp(0, 0),

                      "t" :NumberLong(-1)

                 },

                 "optimeDate" :ISODate("1970-01-01T00:00:00Z"),

                 "lastHeartbeat" :ISODate("2016-07-26T04:21:31.165Z"),

                 "lastHeartbeatRecv" :ISODate("2016-07-26T04:21:32.498Z"),

                 "pingMs" :NumberLong(193),

                 "configVersion" : -2

           }

      ],

      "ok" : 1

}

至此,副本集已然完成,接下來就是驗證主從是否同步?

6、在192.168.1.155:27017主節點上一次進行如下操作:

testrs:PRIMARY>use huangdb:切換到庫

switched to dbhuangdb

testrs:PRIMARY>show collections

testcoll

testrs:PRIMARY>db.testcoll.find()

{"_id" : ObjectId("5792d2a3a4769176f5babaaa"),"Name" : "huang", "Age" : 24, "Gender": "F" }

testrs:PRIMARY>db.testcoll.insert({Name:"xiaoming",Age:23,url:"www.baidu.com"})

WriteResult({"nInserted" : 1 }):添加一條文檔記錄

testrs:PRIMARY>db.testcoll.find():查看文檔記錄

{"_id" : ObjectId("5792d2a3a4769176f5babaaa"),"Name" : "huang", "Age" : 24, "Gender": "F" }

{"_id" : ObjectId("5796e7333f3249e9b0b44ded"),"Name" : "xiaoming", "Age" : 23, "url": "www.baidu.com" }

 

然后在192.168.1.11:27017上這個系統進行登錄驗證

mongo –host 192.168.1.11–port 27017

use huangdb

show collections發現報錯如下:

mongodb之副本集的實現及故障自動轉移

根據報錯提示進行

rs.slaveOk()

然后進行查看

Db.testcoll.find()于是可以看見集合的內容記錄,至此主從同步ok

7、接下來就是觀察節點間能否進行failover故障轉移

192.168.1.155mongod服務停止

[root@RS1 ~]#service mongod stop

Stoppingmongod:                                           [確定]

于是在192.168.1.11上查看副本集狀態

testrs:SECONDARY>rs.status()

{

      "set" : "testrs",

      "date" : ISODate("2016-07-26T05:06:39.686Z"),

      "myState" : 2,

      "term" : NumberLong(4),

      "syncingTo" :"192.168.1.112:27017",

      "heartbeatIntervalMillis" :NumberLong(2000),

      "members" : [

           {

                 "_id" : 0,

                 "name" :"RS1:27017",

                 "health" : 0,

                 "state" : 8,

                 "stateStr" :"(not reachable/healthy)",

                 "uptime" : 0,

                 "optime" : {

                      "ts" :Timestamp(0, 0),

                      "t" :NumberLong(-1)

                 },

                 "optimeDate" :ISODate("1970-01-01T00:00:00Z"),

                 "lastHeartbeat" :ISODate("2016-07-26T05:06:39.641Z"),

                 "lastHeartbeatRecv" :ISODate("2016-07-26T05:05:58.844Z"),

                 "pingMs" :NumberLong(2),

                 "lastHeartbeatMessage": "Connection refused",

                 "configVersion" : -1

           },

           {

                 "_id" : 1,

                 "name" :"192.168.1.11:27017",

                 "health" : 1,

                 "state" : 2,

                 "stateStr" : "SECONDARY",

                 "uptime" : 3019,

                 "optime" : {

                      "ts" :Timestamp(1469509568, 2),

                      "t" :NumberLong(4)

                 },

                 "optimeDate" :ISODate("2016-07-26T05:06:08Z"),

                 "syncingTo" :"192.168.1.112:27017",

                 "configVersion" : 3,

                 "self" : true

           },

           {

                 "_id" : 2,

                 "name" :"192.168.1.112:27017",

                 "health" : 1,

                 "state" : 1,

                 "stateStr" :"PRIMARY",

                 "uptime" : 2708,

                 "optime" : {

                      "ts" :Timestamp(1469509568, 2),

                      "t" :NumberLong(4)

                 },

                 "optimeDate" :ISODate("2016-07-26T05:06:08Z"),

                 "lastHeartbeat" :ISODate("2016-07-26T05:06:38.433Z"),

                 "lastHeartbeatRecv" :ISODate("2016-07-26T05:06:38.907Z"),

                 "pingMs" :NumberLong(1),

                 "electionTime" :Timestamp(1469509568, 1),

                 "electionDate" :ISODate("2016-07-26T05:06:08Z"),

                 "configVersion" : 3

           }

      ],

      "ok" : 1

}

根據狀態可以看出192.168.1.155狀態已經不健康了,而192.168.1.112從從節點勁升為了主節點,于是故障自動轉移成功


附件:http://down.51cto.com/data/2367981
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

榆社县| 铁力市| 京山县| 大港区| 长葛市| 志丹县| 南溪县| 奎屯市| 喀什市| 吉首市| 广元市| 五常市| 措勤县| 惠东县| 阿拉善右旗| 赤城县| 麻栗坡县| 金山区| 通渭县| 嘉善县| 弥勒县| 呼伦贝尔市| 吉木乃县| 溧阳市| 临湘市| 榆中县| 阳春市| 丹棱县| 亚东县| 大丰市| 鄢陵县| 淮安市| 宁波市| 清水河县| 突泉县| 安平县| 融水| 青海省| 利川市| 玉田县| 贵州省|