MongoDB Windows Cluster Configuration
First, the experimental environment:
Win7 (X64), MongoDB 3.0.3
Two or one sets of Win7 computers, the configuration scheme is as follows:
1.3 Shard sharding
2. Each shard consists of 3 nodes consisting of 1 Master 2 prepared replica sets
3.3 Configuration Nodes Configsever
4.1 Routing nodes MONGOs
Shard Replica set A (three shard nodes constitute a replica set):
127.0.0.1:10000 127.0.0.1:10001 127.0.0.1:10002
Shard Replica set B (three shard nodes constitute a replica set):
127.0.0.1:20000 127.0.0.1:20001 127.0.0.1:20002
Shard Replica set C (three shard nodes constitute a replica set):
127.0.0.1:30000 127.0.0.1:30001 127.0.0.1:30002
CONFIGSVC (three configuration server nodes):
127.0.0.1:40000 127.0.0.1:40001 127.0.0.1:4002
MONGOs (one routing node):
127.0.0.1:50000
Three, detailed operation steps:
1. Download MongoDB 3.0.3, storage path: D:\MongoDB\mongodb3.0.3
2. Create a directory of data and log files
To create a data file directory:
Data/a/r0
Data/a/r1
Data/a/r2
Data/b/r0
Data/b/r1
Data/b/r2
Data/c/r0
Data/c/r1
Data/c/r2
Data/configsvr/r0
Data/configsvr/r1
Data/configsvr/r2
To create a log file directory:
log/a
Log/b
Log/c
Log/configsvr
Log/route
3. Creating shards and replication sets
3.1 Configure the first set of Seta:
Configuration file Sharea_r0.config:
Dbpath=. /data/a/r0
Logpath=. /log/a/r0.log
Logappend=true
Replset=seta
port=10000
Shardsvr=true
Journal=true
Configuration file Sharea_r1.config
Dbpath=. /data/a/r1
Logpath=. /log/a/r1.log
Logappend=true
Replset=seta
port=10001
Shardsvr=true
Journal=true
Configuration file Sharea_r2.config
Dbpath=. /data/a/r2
Logpath=. /log/a/r2.log
Logappend=true
Replset=seta
port=10002
Shardsvr=true
Journal=true
Start SHAREA_R0,SHAREA_R1,SHAREA_R2 separately
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/sharea_r0.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/sharea_r1.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/sharea_r2.config
After starting the above Shard node, use the MONGO command line to initialize the replication set
D:\mongodb\mongodb3.0.3\bin>callmongo.exe 127.0.0.1:10000/admin
2016-10-13t10:56:09.898+0800 I CONTROL Hotfix KB2731284 or later update is not
installed, would zero-out data files
MongoDB Shell version:3.0.3
Connecting To:127.0.0.1:10000/admin
> config={_id: ' SetA ', members:[{_id:0,host: ' 127.0.0.1:10000 '},{_id:1,host: ' 127
.0.0.1:10001 '},{_id:2,host: ' 127.0.0.1:10002 '}]}
{
"_id": "SetA",
"Members": [
{
"_id": 0,
"Host": "127.0.0.1:10000"
},
{
"_id": 1,
"Host": "127.0.0.1:10001"
},
{
"_id": 2,
"Host": "127.0.0.1:10002"
}
]
}
> rs.initiate (config)
{"OK": 1}
3.2 Configure the second set of SETB:
Configuration file Shareb_r0.config:
Dbpath=. /data/b/r0
Logpath=. /log/b/r0.log
Logappend=true
Replset=setb
port=20000
Shardsvr=true
Journal=true
Configuration file Shareb_r1.config:
Dbpath=. /data/b/r1
Logpath=. /log/b/r1.log
Logappend=true
Replset=setb
port=20001
Shardsvr=true
Journal=true
Configuration file Shareb_r2.config:
Dbpath=. /data/b/r2
Logpath=. /log/b/r2.log
Logappend=true
Replset=setb
port=20002
Shardsvr=true
Journal=true
Start SHAREB_R0,SHAREB_R1,SHAREB_R2 separately
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/shareb_r0.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/shareb_r1.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/shareb_r2.config
After starting the above Shard node, use the MONGO command line to initialize the replication set
D:\mongodb\mongodb3.0.3\bin>callmongo.exe 127.0.0.1:20000/admin
2016-10-13t11:17:41.626+0800 I CONTROL Hotfix KB2731284 or later update is not
installed, would zero-out data files
MongoDB Shell version:3.0.3
Connecting To:127.0.0.1:20000/admin
> config={_id: ' Setb ', members:[{_id:0,host: ' 127.0.0.1:20000 '},{_id:1,host: ' 127
.0.0.1:20001 '},{_id:2,host: ' 127.0.0.1:20002 '}]}
{
"_id": "Setb",
"Members": [
{
"_id": 0,
"Host": "127.0.0.1:20000"
},
{
"_id": 1,
"Host": "127.0.0.1:20001"
},
{
"_id": 2,
"Host": "127.0.0.1:20002"
}
]
}
> rs.initiate (config)
{"OK": 1}
3.3 Configure the third set of SETC:
Configuration file Sharec_r0.config:
Dbpath=. /data/c/r0
Logpath=. /log/c/r0.log
Logappend=true
Replset=setc
port=30000
Shardsvr=true
Journal=true
Configuration file Sharec_r1.config:
Dbpath=. /data/c/r1
Logpath=. /log/c/r1.log
Logappend=true
Replset=setc
port=30001
Shardsvr=true
Journal=true
Configuration file Sharec_r2.config:
Dbpath=. /data/c/r2
Logpath=. /log/c/r2.log
Logappend=true
Replset=setc
port=30002
Shardsvr=true
Journal=true
Start SHAREC_R0,SHAREC_R1,SHAREC_R2 separately
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/sharec_r0.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/sharec_r1.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/sharec_r2.config
After starting the above Shard node, use the MONGO command line to initialize the replication set
D:\mongodb\mongodb3.0.3\bin>callmongo.exe 127.0.0.1:30000/admin
2016-10-13t11:17:41.626+0800 I CONTROL Hotfix KB2731284 or later update is not
installed, would zero-out data files
MongoDB Shell version:3.0.3
Connecting To:127.0.0.1:30000/admin
> config={_id: ' setc ', members:[{_id:0,host: ' 127.0.0.1:30000 '},{_id:1,host: ' 127
.0.0.1:30001 '},{_id:2,host: ' 127.0.0.1:30002 '}]}
{
"_id": "SetC",
"Members": [
{
"_id": 0,
"Host": "127.0.0.1:30000"
},
{
"_id": 1,
"Host": "127.0.0.1:30001"
},
{
"_id": 2,
"Host": "127.0.0.1:30002"
}
]
}
> rs.initiate (config)
{"OK": 1}
3.4 Start three Configuration service nodes Configsvr
configuration file configsvr_r0.config:
Dbpath=. /data/configsvr/r0
Logpath=. /log/configsvr/r0.log
Logappend=true
port=40000
Configsvr=true
Journal=true
configuration file configsvr_r1.config:
Dbpath=. /data/configsvr/r1
Logpath=. /log/configsvr/r1.log
Logappend=true
port=40001
Configsvr=true
Journal=true
configuration file configsvr_r2.config:
Dbpath=. /data/configsvr/r2
Logpath=. /log/configsvr/r2.log
Logappend=true
port=40002
Configsvr=true
Journal=true
Start CONFIGSVR_R0,CONFIGSVR_R1,CONFIGSVR_R2 separately
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/configsvr/configsvr_r0.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/configsvr/configsvr_r1.config
D:\mongodb\mongodb3.0.3\bin>mongod-f. /config/configsvr/configsvr_r2.config
3.5 Start the Routing node
Configuration file Route.config:
configdb=127.0.0.1:40000,127.0.0.1:40001,127.0.0.1:40002
port=50000
Chunksize=1
Logpath=. /log/route/mongos.log
Logappend=true
To start the routing node:
D:\mongodb\mongodb3.0.3\bin>mongos-f. /config/routeconfig/route.config
3.6 Configuring Shards
Shard Command:
Db.runcommand ({addshard: "seta/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1
: 10002 ", Name:" Shardseta "})
Db.runcommand ({addshard: "setb/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1
: 20002 ", Name:" Shardsetb "})
Db.runcommand ({addshard: "setc/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:
30002 ", Name:" Shardsetc "})
Printshardingstatus ()
d:\mongodb\mongodb3.0.3\bin>mongo127.0.0.1:50000
2016-10-13t14:26:08.284+0800 I CONTROL Hotfix KB2731284 or later update is not
installed, would zero-out data files
MongoDB Shell version:3.0.3
Connecting To:127.0.0.1:50000/test
mongos> Use admin
Switched to DB admin
Mongos> Db.runcommand ({addshard: "seta/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1
: 10002 ", Name:" Shardseta "})
{"shardadded": "Shardseta", "OK": 1}
Mongos> Db.runcommand ({addshard: "setb/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1
: 20002 ", Name:" Shardsetb "})
{"shardadded": "Shardsetb", "OK": 1}
Mongos>db.runcommand ({addshard: "setc/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:
30002 ", Name:" Shardsetc "})
{"shardadded": "Shardsetc", "OK": 1}
Mongos> Printshardingstatus ()
---sharding Status---
Sharding version: {
"_id": 1,
"Mincompatibleversion": 5,
"CurrentVersion": 6,
"Clusterid": ObjectId ("57ff2830daabed7a3028cf41")
}
Shards:
{"_id": "Shardseta", "host": "Seta/127.0.0.1:10000,127.0.0.1:10001,
127.0.0.1:10002 "}
{"_id": "Shardsetb", "host": "Setb/127.0.0.1:20000,127.0.0.1:20001,
127.0.0.1:20002 "}
{"_id": "Shardsetc", "host": "Setb/127.0.0.1:30000,127.0.0.1:30001,
127.0.0.1:30002 "}
Balancer
Currently Enabled:yes
Currently Running:no
Failed balancer rounds in last 5 attempts:0
Migration Results for the Last Hours:
No Recent Migrations
Databases
{"_id": "admin", "partitioned": false, "PRIMARY": "Config"}
MongoDB Windows Cluster configuration