<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### **常見的復制集** 線上環境常見的架構為副本集,可以理解為一主多從。 #### 下圖:1主2從 ![](https://img.kancloud.cn/e6/71/e6719d794c38d7bdef87c2b823db22ef_476x391.png) #### 下圖:一主一從一仲裁 ![](https://img.kancloud.cn/79/60/796011233a7ab9055cb62b618e6b2d1b_759x299.png) ### 服務器信息: 三臺機器一樣配置2核16G內存 存儲盤100G > "host" : "10.1.1.159:27020" "host" : "10.1.1.77:27020" "host" : "10.1.1.178:27020 ### 1、我們在其中一臺機器配置: [root@10-1-1-159 ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.1.tgz [root@10-1-1-159 ~]# tar -zxvf mongodb-linux-x86_64-rhel70-4.2.1.tgz -C /data/ [root@10-1-1-159 ~]# mkdir /data/mongodb/{data,logs,pid,conf} -p 配置文件: ``` [root@10-1-1-159 ~]# cat /data/mongodb/conf/mongodb.conf systemLog: destination: file logAppend: true path: /data/mongodb/logs/mongod.log storage: dbPath: /data/mongodb/data journal: enabled: true directoryPerDB: true wiredTiger: engineConfig: cacheSizeGB: 8 #如果一臺機器啟動一個實例這個可以注釋選擇默認,如果一臺機器啟動多個實例,需要設置內存大小,避免互相搶占內存 directoryForIndexes: true processManagement: fork: true pidFilePath: /data/mongodb/pid/mongod.pid net: port: 27020 bindIp: 10.1.1.159,localhost #修改為本機IP地址 maxIncomingConnections: 5000 #security: #keyFile: /data/mongodb/conf/keyfile #authorization: enabled replication: # oplogSizeMB: 1024 replSetName: rs02 ``` ### 2、將配置負復制到其他機器: [root@10-1-1-159 ~]# scp -r /data/* root@10.1.1.77:/data/ [root@10-1-1-159 ~]# scp -r /data/* root@10.1.1.178:/data/ 目錄結構: ``` [root@10-1-1-178 data]# tree mongodb mongodb ├── conf │?? └── mongodb.conf ├── data ├── logs └── pid ``` ### 3、三臺機器分別執行: >groupadd mongod useradd -g mongod mongod yum install -y libcurl openssl glibc cd /data ln -s mongodb-linux-x86_64-rhel70-4.2.1 mongodb-4.2 chown -R mongod.mongod /data sudo -u mongod /data/mongodb4.2.1/bin/mongod -f /data/mongodb/conf/mongodb.conf 配置復制集: #副本集名稱rs02和配置文件中replSetName保持一致 >config = { _id:"rs02", members:[ ? ? ? ? ? ? ? ? ? ? ?{_id:0,host:"10.1.1.159:27010",priority:90},? ? ? ? ? ? ? ? ? ? ? ?{_id:1,host:"10.1.1.77:27010",priority:90},? ? ? ? ? ? ? ? ? ? ? {_id:2,host:"10.1.1.178:27010",arbiterOnly:true} ? ? ] } #初始化 >rs.initiate(config);? ### 4、在其中一臺機器執行: ``` [root@10-1-1-159 ~]# /data/mongodb3.6.9/bin/mongo 10.1.1.159:27020 > use admin switched to db admin > config = { _id:"rs02", members:[ ... ? ? ? ? ? ? ? ? ? ? ?{_id:0,host:"10.1.1.159:27020",priority:90}, ... ? ? ? ? ? ? ? ? ? ? ?{_id:1,host:"10.1.1.77:27020",priority:90}, ... ? ? ? ? ? ? ? ? ? ? {_id:2,host:"10.1.1.178:27020",arbiterOnly:true} ... ? ? ] ... } { "_id" : "rs02", "members" : [ { "_id" : 0, "host" : "10.1.1.159:27020", "priority" : 90 }, { "_id" : 1, "host" : "10.1.1.77:27020", "priority" : 90 }, { "_id" : 2, "host" : "10.1.1.178:27020", "arbiterOnly" : true } ] } > > rs.initiate(config); 初始化副本集########eeeerrrr { "ok" : 1, "operationTime" : Timestamp(1583907929, 1), "$clusterTime" : { "clusterTime" : Timestamp(1583907929, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } } ``` ### 5、查看節點狀態 ``` rs02:PRIMARY> rs.status() { "set" : "rs02", "date" : ISODate("2020-03-13T07:11:09.427Z"), "myState" : 1, "term" : NumberLong(1), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1584083465, 1), "t" : NumberLong(1) }, "readConcernMajorityOpTime" : { "ts" : Timestamp(1584083465, 1), "t" : NumberLong(1) }, "appliedOpTime" : { "ts" : Timestamp(1584083465, 1), "t" : NumberLong(1) }, "durableOpTime" : { "ts" : Timestamp(1584083465, 1), "t" : NumberLong(1) } }, "members" : [ { "_id" : 0, "name" : "10.1.1.159:27020", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", #主節點 "uptime" : 185477, "optime" : { "ts" : Timestamp(1584083465, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2020-03-13T07:11:05Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1583907939, 1), "electionDate" : ISODate("2020-03-11T06:25:39Z"), "configVersion" : 1, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 1, "name" : "10.1.1.77:27020", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", #從節點 "uptime" : 175540, "optime" : { "ts" : Timestamp(1584083465, 1), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1584083465, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2020-03-13T07:11:05Z"), "optimeDurableDate" : ISODate("2020-03-13T07:11:05Z"), "lastHeartbeat" : ISODate("2020-03-13T07:11:08.712Z"), "lastHeartbeatRecv" : ISODate("2020-03-13T07:11:08.711Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "10.1.1.159:27020", "syncSourceHost" : "10.1.1.159:27020", "syncSourceId" : 0, "infoMessage" : "", "configVersion" : 1 }, { "_id" : 2, "name" : "10.1.1.178:27020", "health" : 1, "state" : 7, "stateStr" : "ARBITER", #仲裁節點 "uptime" : 175540, "lastHeartbeat" : ISODate("2020-03-13T07:11:08.712Z"), "lastHeartbeatRecv" : ISODate("2020-03-13T07:11:08.711Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 1 } ], "ok" : 1, "operationTime" : Timestamp(1584083465, 1), "$clusterTime" : { "clusterTime" : Timestamp(1584083465, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } } rs02:PRIMARY> ``` ### 7、現在副本集狀態: >10.1.1.178:27020 ARBITER 仲裁節點 10.1.1.77:27020 SECONDARY 從節點 10.1.1.159:27020 PRIMARY 主節點 我們插入一些數據查,然后將主節點停掉, 仲裁節點的日志 我們可以看到,當節點10.1.1.159宕機以后,重新選舉了:Member 10.1.1.77:27010 is now in state PRIMARY ``` 2020-03-18T14:34:53.636+0800 I NETWORK [conn9] end connection 10.1.1.159:49160 (1 connection now open) 2020-03-18T14:34:54.465+0800 I CONNPOOL [Replication] dropping unhealthy pooled connection to 10.1.1.159:27010 2020-03-18T14:34:54.465+0800 I CONNPOOL [Replication] after drop, pool was empty, going to spawn some connections 2020-03-18T14:34:54.465+0800 I ASIO [Replication] Connecting to 10.1.1.159:27010 ...... 2020-03-18T14:35:02.473+0800 I ASIO [Replication] Failed to connect to 10.1.1.159:27010 - HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused 2020-03-18T14:35:02.473+0800 I CONNPOOL [Replication] Dropping all pooled connections to 10.1.1.159:27010 due to HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused 2020-03-18T14:35:02.473+0800 I REPL_HB [replexec-8] Error in heartbeat (requestId: 662) to 10.1.1.159:27010, response status: HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused 2020-03-18T14:35:04.463+0800 I REPL [replexec-5] Member 10.1.1.77:27010 is now in state PRIMARY 2020-03-18T14:35:04.473+0800 I ASIO [Replication] Connecting to 10.1.1.159:27010 2020-03-18T14:35:04.473+0800 I ASIO [Replication] Failed to connect to 10.1.1.159:27010 - HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused 2020-03-18T14:35:04.473+0800 I CONNPOOL [Replication] Dropping all pooled connections to 10.1.1.159:27010 due to HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused ``` 架構也就變成了下圖: ![](https://img.kancloud.cn/c8/2b/c82b23039d94a0c230d3270479ddf11f_516x394.png) 目前副本集搭建完成,也測試了當一個節點出現問題以后(至少三個節點),并不會影響服務正常讀寫。 下一章我們開始添加用戶:
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看