Mongodb Windows Cluster

Source: Internet
Author: User
Tags mongodb windows

I built a Replica sets + sharding test cluster environment under a Windows machine as my next experimental platform for MongoDB to further learn.

Only one Windows machine, configuration scenario:
1, 3 shards sharding
2, each shard from 3 nodes constitute 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

The detailed procedure is as follows:

(1) Download mongodb-win32-i386-1.8.0

Download the mongodb-win32-i386-1.8.0 version of MongoDB, placed in the d:/mongodb-win32-i386-1.8.0 directory.

(2) Create a directory of data and log files

Go to the d:/mongodb-win32-i386-1.8.0 directory to create the following directory

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:

logs/a
Logs/b
Logs/c
Logs/configsvr

(3) Creating shards and replica sets

Configure the first group:

Go to the D:/mongodb-win32-i386-1.8.0/bin directory from the command line and execute the command as follows!

Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/a/r0.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ Data/a/r0--port 10000--shardsvr--replset SetA--rest--oplogsize 64
Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/a/r1.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ DATA/A/R1--port 10001--shardsvr--replset SetA--rest--oplogsize 64
Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/a/r2.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ DATA/A/R2--port 10002--shardsvr--replset SetA--rest--oplogsize 64

After starting the above Shard node, use the MONGO command line to initialize the replication set

D:/mongodb-win32-i386-1.8.0/bin>call Mongo.exe 127.0.0.1:10000/admin
MongoDB Shell version:1.8.0
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"
}
]
}
seta> rs.initiate (config);

Configure the second group:

Go to the D:/mongodb-win32-i386-1.8.0/bin directory from the command line and execute the command as follows!

Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/b/r0.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ Data/b/r0--port 20000--shardsvr--replset SETB--rest--oplogsize 64
Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/b/r1.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ DATA/B/R1--port 20001--shardsvr--replset setb--rest--oplogsize 64
Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/b/r2.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ DATA/B/R2--port 20002--shardsvr--replset setb--rest--oplogsize 64

After starting the above Shard node, use the MONGO command line to initialize the replication set

D:/mongodb-win32-i386-1.8.0/bin>call Mongo.exe 127.0.0.1:20000/admin
MongoDB Shell version:1.8.0
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);

Configure the third group:

Go to the D:/mongodb-win32-i386-1.8.0/bin directory from the command line and execute the command as follows!
Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/c/r0.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ Data/c/r0--port 30000--shardsvr--replset setc--rest--oplogsize 64
Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/c/r1.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ DATA/C/R1--port 30001--shardsvr--replset setc--rest--oplogsize 64
Mongod.exe--logpath d:/mongodb-win32-i386-1.8.0/logs/c/r2.log--logappend--dbpath d:/mongodb-win32-i386-1.8.0/ DATA/C/R2--port 30002--shardsvr--replset setc--rest--oplogsize 64
D:/mongodb-win32-i386-1.8.0/bin>call Mongo.exe 127.0.0.1:30000/admin
MongoDB Shell version:1.8.0
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);

(4) Start three Configuration service nodes Configsvr

Configure three configsvr from the command line by executing the following commands, respectively

CD D:/mongodb-win32-i386-1.8.0/bin
Call Mongod.exe--configsvr--logpath d:/mongodb-win32-i386-1.8.0/logs/configsvr/r0.log--logappend--dbpath d:/ Mongodb-win32-i386-1.8.0/data/configsvr/r0--port 40000--shardsvr

CD D:/mongodb-win32-i386-1.8.0/bin
Call Mongod.exe--configsvr--logpath d:/mongodb-win32-i386-1.8.0/logs/configsvr/r1.log--logappend--dbpath d:/ MONGODB-WIN32-I386-1.8.0/DATA/CONFIGSVR/R1--port 40001--shardsvr

CD D:/mongodb-win32-i386-1.8.0/bin
Call Mongod.exe--configsvr--logpath d:/mongodb-win32-i386-1.8.0/logs/configsvr/r2.log--logappend--dbpath d:/ MONGODB-WIN32-I386-1.8.0/DATA/CONFIGSVR/R2--port 40002--shardsvr

(5) Start a routing node MONGOs

CD D:/mongodb-win32-i386-1.8.0/bin
Call Mongos.exe--configdb 127.0.0.1:40000,127.0.0.1:40001,127.0.0.1:40002--logpath d:/mongodb-win32-i386-1.8.0/ Logs/mongos.log--logappend--port 50000

(6) Configuring shards

D:/MONGODB-WIN32-I386-1.8.0/CMD>CD D:/mongodb-win32-i386-1.8.0/bin
D:/mongodb-win32-i386-1.8.0/bin>call Mongo.exe 127.0.0.1:50000
MongoDB Shell version:1.8.0
Connecting To:127.0.0.1:50000/test
> Use admin
Switched to DB admin
> 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}
> 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}
> 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}
> Printshardingstatus ()
---sharding Status---
Sharding version: {"_id": 1, "Version": 3}
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": "Setc/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002"
}
Databases
{"_id": "admin", "partitioned": false, "PRIMARY": "Config"}

Configuration here, the cluster has been built!

After the completion of the cluster construction work, the need to do is to set up a database, set up a table, set the Shard primary key to initialize the data!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.