<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] > [參考](https://www.ibm.com/developerworks/cn/opensource/os-mongodb-sharded-cluster/index.html) ## 概述 接下來我們開始準備部署一個具有 2 個 shard(3 節點副本集)加 1 個 config server(3 節點副本集)加 2 個 mongos 的分片集群 ### 創建配置副本集(>=1 臺) ``` mongod --port=30000 --configsvr --replSet rep_confsvr --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\shard\config" --bind_ip_all mongod --port=30001 --configsvr --replSet rep_confsvr --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\shard\config1" --bind_ip_all mongod --port=30002 --configsvr --replSet rep_confsvr --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\shard\config2" --bind_ip_all ``` 選擇其中一個連接 ``` > mongo --port 30000 rs.initiate( { _id: "rep_confsvr", configsvr: true, members: [ { _id : 0, host : "192.168.0.130:30000" }, { _id : 1, host : "192.168.0.130:30001" }, { _id : 2, host : "192.168.0.130:30002" }, ] } ) //后期,添加成員 rs.add("192.168.0.130:30003") ``` ### 添加分片服務器(>=1 臺)-shard1 ``` mongod --port 27002 --shardsvr --replSet shard1 --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\data2" --bind_ip_all mongod --port 27003 --shardsvr --replSet shard1 --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\data3" --bind_ip_all mongod --port 27004 --shardsvr --replSet shard1 --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\data4" --bind_ip_all ``` 選擇其中一個連接 ``` > mongo --port 27002 // 初始化 rs.initiate( { _id : "shard1", members: [ { _id : 0, host : "192.168.0.130:27002" }, { _id : 1, host : "192.168.0.130:27003" }, { _id : 2, host : "192.168.0.130:27004" } ] } ) //添加成員 // rs.add("192.168.0.130:27005") //刪除成員,在集群啟動時也可刪除 // rs.remove("192.168.0.130:27005") ``` ### 添加分片服務器(>=1 臺)-shard2 ``` mongod --port 27005 --shardsvr --replSet shard2 --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\data11" --bind_ip_all mongod --port 27006 --shardsvr --replSet shard2 --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\data12" --bind_ip_all mongod --port 27007 --shardsvr --replSet shard2 --dbpath "D:\Program Files (x86)\mongodb-win32-x86_64-2012plus-4.2.2\data13" --bind_ip_all ``` 選擇其中一個連接 ``` mongo --port 27005 // 初始化 > rs.initiate( { _id : "shard2", members: [ { _id : 0, host : "192.168.0.130:27005" }, { _id : 1, host : "192.168.0.130:27006" }, { _id : 2, host : "192.168.0.130:27007" } ] } ) ``` ### 創建 mongos路由(可創建多個) ``` mongos --port 30010 --configdb rep_confsvr/192.168.0.130:30000,192.168.0.130:30001,192.168.0.130:30002 --bind_ip_all ``` 連接 mongos ``` mongo --port 30010 >sh.addShard("shard1/192.168.0.130:27002,192.168.0.130:27003,192.168.0.130:27004") > sh.addShard("shard2/192.168.0.130:27005,192.168.0.130:27006,192.168.0.130:27007") > sh.enableSharding("notice_set") //指定分片數據庫 > sh.shardCollection("notice_set.test_shard",{"age": "hashed"}) // 第二參數 {"age":`1} ,表示根據范圍 > sh.status() // 查看集群狀態 ``` ### 連接mongodb 連接的端口和ip 為 mongos 的端口與ip ### 在集群中已有數據時,新增分片 ``` //檢查 balancer 是否開啟 mongos> sh.getBalancerState() // true //開啟balancer mongos > sh.startBalancer(); mongos > sh.addShard("shard1/192.168.0.130:27002"); ``` > 新增分片的數據會自動遷移,原分片數據,需要過一會才能顯示正確遷移后數據 ## 測試數據 根據范圍的測試 ``` for (i = 1; i <= 20000; i++) db.test_shard.insert({age:(i%100), name:"user"+i, create_at:new Date()}) ``` 根據hash的測試 ``` for (i = 1; i <= 20000; i++) db.test_shard.insert({age:(i), name:"user"+i, create_at:new Date()}) ```
                  <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>

                              哎呀哎呀视频在线观看