Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mongodb shard

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

ServerA:172.16.200.200

/ data/mongodb/db/ {shard1_200,shard2_200,shard3_200,config}

/ data1/logs/mongodb/

ServerB:172.16.200.201

/ data/mongodb/db/ {shard1_201,shard2_201,shard3_201,config}

/ data1/logs/mongodb/

ServerC:172.16.200.202

/ data/mongodb/db/ {shard1_202,shard2_202,shard3_202,config}

/ data1/logs/mongodb/

ServerA:./mongod-shardsvr-replSet shard1-port 29001-dbpath=/data/mongodb/db/shard1_200/-oplogSize 10240-logpath=/data1/logs/mongodb/shard1_200.log-logappend-fork-nohttpinterface-directoryperdb

ServerB:

/ mongod-- shardsvr-- replSet shard1-- port 29001-- dbpath=/data/mongodb/db/shard1_201/-- oplogSize 10240-- logpath=/data1/logs/mongodb/shard1_201.log-- logappend-- fork-- nohttpinterface-- directoryperdbserverC:

/ mongod-- shardsvr-- replSet shard1-- port 29001-- dbpath=/data/mongodb/db/shard1_202/-- oplogSize 10240-- logpath=/data1/logs/mongodb/shard1_202.log-- logappend-- fork-- nohttpinterface-directoryperdb

Log in to mongo./mongo-- port 29001 > config = {_ id: 'shard1', members: [

... = 'class1' > {_ id: 0, host: '172.16.200.200vl 29001 priority1}

... = 'class3' > {_ id: 1, host: '172.16.200.201purl 29001please priority0}

... = 'class1' > {_ id: 2, host: '172.16.200.202 29001]}

{

"_ id": "shard1"

"members": [

{

"_ id": 0

"host": "172.16.200.200pur29001"

"priority": 1

}

{

"_ id": 1

"host": "172.16.200.201pur29001"

"priority": 0

}

{

"_ id": 2

"host": "172.16.200.202purl 29001"

"arbiterOnly": true

}

]

}

> rs.initiate (config)

{

Info: "Config now saved locally. Should come online in about a minute."

"ok": 1

}

>

Shard1:SECONDARY >

Shard1:SECONDARY > serverA:./mongod-shardsvr-replSet shard2-port 29002-dbpath=/data/mongodb/db/shard2_200/-oplogSize 10240-logpath=/data1/logs/mongodb/shard2_201.log-logappend-fork-nohttpinterface-directoryperdbserverB:

/ mongod-- shardsvr-- replSet shard2-- port 29002-- dbpath=/data/mongodb/db/shard2_201/-- oplogSize 10240-- logpath=/data1/logs/mongodb/shard2_201.log-- logappend-- fork-- nohttpinterface-- directoryperdbserverC:./mongod-- shardsvr-- replSet shard2-- port 29002-- dbpath=/data/mongodb/db/shard2_202-- oplogSize 10240-- logpath=/data1/logs/mongodb/shard2_202.log-- logappend-- fork-- nohttpinterface-- directoryperdb login Record mong./mongo-port 29002 [root@serverA bin] #. / mongo-port 29002

MongoDB shell version: 2.6.0

Connecting to: 127.0.0.1:29002/test

> config = {_ id: 'shard2', members: [

... = 'class1' > {_ id: 0, host: '172.16.200.200vl 29002 priority1}

... = 'class2' > {_ id: 1, host: '172.16.200.201purl 29002

... = 'class1' > {_ id: 2, host: '172.16.200.202 purl 29002]}

{

"_ id": "shard2"

"members": [

{

"_ id": 0

"host": "172.16.200.200pur29002"

"priority": 1

}

{

"_ id": 1

"host": "172.16.200.201pur29002"

"priority": 0

}

{

"_ id": 2

"host": "172.16.200.202purl 29002"

"arbiterOnly": true

}

]

}

> rs.initiate (config)

{

Info: "Config now saved locally. Should come online in about a minute."

"ok": 1

}

>

Shard2:SECONDARY > shard2:PRIMARY > serverA:./mongod-shardsvr-replSet shard3-port 29003-dbpath=/data/mongodb/db/shard3_200/-oplogSize 10240-logpath=/data1/logs/mongodb/shard3_200.log-logappend-fork-nohttpinterface-directoryperdb

ServerB:./mongod-- shardsvr-- replSet shard3-- port 29003-- dbpath=/data/mongodb/db/shard3_201/-- oplogSize 10240-- logpath=/data1/logs/mongodb/shard3_201.log-- logappend-- fork-- nohttpinterface-- directoryperdbserverC:./mongod-- shardsvr-- port 29003-- dbpath=/data/mongodb/db/shard3_202/-- oplogSize 10240-- logpath=/data1/logs/mongodb/shard3_202.log-- logappend-- fork-- nohttpinterface -directoryperdb [root@serverA bin] #. / mongo-port 29003

MongoDB shell version: 2.6.0

Connecting to: 127.0.0.1:29003/test

> config = {_ id: 'shard3', members: [

... = 'class1' > {_ id: 0, host: '172.16.200.200vl 29003

... = 'class3' > {_ id: 1, host: '172.16.200.201purl 29003

... = 'class1' > {_ id: 2, host: '172.16.200.202 purl 29003]}

{

"_ id": "shard3"

"members": [

{

"_ id": 0

"host": "172.16.200.200pur29003"

"priority": 1

}

{

"_ id": 1

"host": "172.16.200.201pur29003"

"priority": 0

}

{

"_ id": 2

"host": "172.16.200.202purl 29003"

"arbiterOnly": true

}

]

}

> rs.initiate (config)

{

Info: "Config now saved locally. Should come online in about a minute."

"ok": 1

}

>

Shard3:SECONDARY >

Shard3:SECONDARY >

Shard3:SECONDARY >

Shard3:PRIMARY > start configserverA:./mongod-- configsvr-- dbpath=/data/mongodb/db/config/-- port 29000-- logpath=/data1/logs/mongodb/config_200.log-- logappend-- fork-- nohttpinterface-- directoryperdb

ServerB:./mongod-- configsvr-- dbpath=/data/mongodb/db/config/-- port 29000-- logpath=/data1/logs/mongodb/config_201.log-- logappend-- fork-- nohttpinterface-- directoryperdbserverC:./mongod-- configsvr-- dbpath=/data/mongodb/db/config/-- port 29000-- logpath=/data1/logs/mongodb/config_202.log-- logappend-- fork-- nohttpinterface-- directoryperdb launch mongosserverA:

. / mongos-- configdb 172.16.200.200VOV 29000172.16.200.201VOR 29000172.16.200.202Rod 29000-- port 27001-- chunkSize 8-- logpath=/data1/logs/mongodb/mongos_200.log-- logappend-- fork-- nohttpinterface

ServerB:./mongos-- configdb 172.16.200.200VZ 29000172.16.200.2012JV 29000-- port 27001-- chunkSize 8-- logpath=/data1/logs/mongodb/mongos_201.log-- logappend-- fork-- nohttpinterfaceserverC:./mongos-- configdb 172.16.200.200VZ 29000172.16.200.2012Rd 29000-port 27001-- chunkSize 8-- logpath=/data1/logs/mongodb/mongos_202.log-- logappend-fork-nohttpinterface

Configure sharding. / mono-- port 27001mongos > use admin

Switched to db admindb.runCommand ({addshard: "shard1/172.16.200.200:29001172.16.200.201:29001172.16.200.202:29001", name: "S1"})

{"shardAdded": "S1", "ok": 1}

Mongos > db.runCommand ({addshard: "shard2/172.16.200.201:29002172.16.200.202:29002172.16.200.200:29002", name: "S2"})

{"shardAdded": "S2", "ok": 1}

Mongos > db.runCommand ({addshard: "shard3/172.16.200.202:29003172.16.200.200:29003172.16.200.201:29003", name: "S3"})

{"shardAdded": "S3", "ok": 1}

Mongos > [root@serverA bin] #. / mongo-- port 27001

MongoDB shell version: 2.6.0

Connecting to: 127.0.0.1:27001/test

Mongos >

Mongos > show dbs

Admin 0.016GB

Config 0.016GB

Congig (empty) mongos > use configswitched to db config

Mongos > show collections

Changelog

Chunks

Collections

Databases

Lockpings

Locks

Mongos

Settings

Shards

System.indexes

Tags

Version

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report