MongoDB sharding Cluster Setup

Source: Internet
Author: User
Tags mongodb sharding mongo shell

Create a virtual machine, if you are using copy to install the system, remember to modify the machine name, otherwise all machine names are the same, will cause installation failure

At the same time, shut down the firewall, all the machine timing to match, master and slave heartbeat interval can not exceed three seconds, or cause the startup MONGOs failed, this can view MONGOs log

Install under D:\mongodb using MongoDB 3.02 or a later version of the installation package. If you are your own MongoDB related program obtained through source code compilation, you need to build D:\mongodb\bin and copy the Mongod.exe, Mongo.exe, Mongos.exe to it below (PS: In order to support NG full-text index search, You need to replace Mongod.exe,mongo.exe,mongos.exe with a compiled v3.0.6 version binary file).

Cluster monitoring tool https://cloud.mongodb.com trial period of 30 days (personally think this monitoring tool is still relatively useful)

Installation steps look a lot, actually very simple, is the step more points, more patience is good

1.1.1 Preparatory work

We will create the respective directories on each of the three machines above

Unzip the mongodb.zip into the D:\mongodb

Create the D:\mongodb\cluster\shard1 directory, under which you create the data, log subdirectory;

To create a finished catalog listing:

D:\mongodb\cluster\shard1\data

D:\mongodb\cluster\shard1\log

D:\mongodb\bin

On 192.168.33.92, 192.168.33.93 and 192.168.33.94, create a config.conf text file under D:\mongodb\cluster\shard1, and put the following in the file, Note that indents can only be made with spaces and cannot be tab:

Systemlog:

Destination:file

Path:d:\mongodb\cluster\shard1\log\shard1.log

Logappend:true

Logrotate:rename

Storage

Dbpath:d:\mongodb\cluster\shard1\data

Journal

Enabled:true

Directoryperdb:true

Engine:mmapv1

Replication

oplogsizemb:10000

Replsetname:shard1

Sharding:

Clusterrole:shardsvr

Net

port:22001

Here, the preparation is completed.

1.1.2 Configuration Replica

Three member instances are started on three machines by command line, respectively.

Hold down SHIFT and then right-click on the Unpacked D:\mongodb folder to open the DOS window from the opening command window

D:\mongodb\bin\mongod--config d:\mongodb\cluster\shard1\config.conf

1.1.3 initializes the replica set and adds the replica set member:

Log in to 192.168.33.92:22001 using MONGO shell (mongo.exe) or other tools.

D:\dev\software\mongo-master\bin>mongo 192.168.33.92:22001//This command must be performed on a non-arbiter machine

2015-04-29t11:37:58.375-

MongoDB Shell version:3.1.2-pre-

Connecting To:192.168.33.92:22001/test

> Use admin

> cfg = {_id: "Shard1", members:[

{_id:0,host: "192.168.33.92:22001", priority:1000},

{_id:1,host: "192.168.33.93:22001", priority:999},

{_id:2,host: "192.168.33.94:22001", priority:800, Arbiteronly:true}

]

}

> rs.initiate (CFG); This command must be performed on a non-arbiter machine

2 Configuring Config server:

Config server is a special Mongod instance and a database that holds cluster metadata for shard information. Config server is not directly associated with other Mongod instances in cluster as a database server, and it stores chunk storage and migration information.

We will create the respective directories on each of the three machines above

In 192.168.33.92, 192.168.33.93, 192.168.33.94 do the following

Create the D:\mongodb\cluster\configsvr\ directory, under which you create the data, log subdirectory;

To create a finished catalog listing:

D:\mongodb\cluster\configsvr\data

D:\mongodb\cluster\configsvr\log

Confirm that the Mongod.exe is in the D:\mongodb\bin directory, if you are installing the installation package to the D:\mongodb directory, Mongod.exe should already be in D:\mongodb\bin

2. 1 Edit the configuration file:

On 192.168.33.92, 192.168.33.93, 192.168.33.94, create a config.conf text file under D:\mongodb\cluster\ Configsvr, put the following in the file, Note that indents can only be made with spaces and cannot be tab:

Version 3.0:

Systemlog:

Destination:file

Path:d:\mongodb\cluster\configsvr\log\configsvr.log

Logappend:true

Logrotate:rename

Storage

Dbpath:d:\mongodb\cluster\configsvr\data

Journal

Enabled:true

Directoryperdb:true

Engine:mmapv1

Sharding:

Clusterrole:configsvr

Net

port:21110

2.2 Starting three config servers

Use command line on three machines to start the three-member MONGO config server instance with the following commands:

D:\mongodb\bin\mongod--config d:\mongodb\cluster\ configsvr\config.conf

2.3 Configuring MONGOs

The MONGOs instance is the entry for the application to access cluster. MONGOs can also configure multiple to increase system fault tolerance. If multiple MONGOs are used, all MONGOs config server configuration items must be identical.

In this document, we will use three MONGOs instances, each placed in 192.168.33.92:21100, 192.168.33.93:21100, and 192.168.33.94:21100

2.4 Creating a Directory

We will create the respective directories on each of the three machines above

In 192.168.33.92, 192.168.33.93, 192.168.33.94 do the following

Create the D:\mongodb\cluster\mongos\ directory under which the log subdirectory is created;

To create a finished catalog listing:

D:\mongodb\cluster\ MONGOs \log

Confirm that the Mongos.exe is in the D:\mongodb\bin directory, if you are installing the installation package to the D:\mongodb directory, MONGOs should already be in D:\mongodb\bin

2.5 Edit the configuration file:

On 192.168.33.92, 192.168.33.93, 192.168.33.94, create a config.conf text file under D:\mongodb\cluster\ MONGOs, put the following in the file, Note that indents can only be made with spaces and cannot be tab:

For version 3.0:

#YAML format

Systemlog:

Destination:file

Path:d:\mongodb\cluster\mongos\log\mongos.log

Logappend:true

Logrotate:rename

Sharding:

configdb:192.168.33.92:21110,192.168.33.93:21110,192.168.33.94:21110

Net

port:21100

2.6 Start three x MONGOs

Use command line on three machines to start the MONGOs instance separately.

At 192.168.33.92, 192.168.33.93, 192.168.33.94:

D:\mongodb\bin\mongos--config d:\mongodb\cluster\ mongos\config.conf

3 Adding Shard nodes to cluster

Now while each application (3 Shard1 replica set members, 3 Config server, 3 MONGOs) is running, cluster is empty and no database server is added. That is to say, Shard1 and has not been added into the cluster.

If you use the MONGO shell to log into any of the MONGOs, run the sh.status () command, you will see the following result:

D:\dev\software\mongo-master\bin>mongo 192.168.33.92:21100

2015-05-01t10:47:30.337-0400

MongoDB Shell version:3.1.2-pre-

Connecting To:192.168.33.92:21100/test

Mongos> Show DBS

Admin (empty)

Config (empty)

Mongos> Sh.status ()

---sharding Status---

Sharding version: {

"_id": 1,

"Mincompatibleversion": 5,

"CurrentVersion": 6,

"Clusterid": ObjectId ("5542e946bfcdf8ecc8ae22da")

}

Shards:

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

Mongos>

Shards is empty in the above results, indicating that we do not have any shard. Let's add shard1 to cluster.

Add Shard1 to Cluster

You can use the MONGO shell to log on to any mongos to complete the Shard add operation. Here we log in to 192.168.33.92:21100.

Sh.addshard ("shard1/192.168.33.92:22001"). Any member of the Replica set can be used as a seed here.

MONGOs will automatically identify, search, and add all of the members that entered the replica set

At this point, cluster has been established.

3.2 Adding a new Shard and adding to the cluster

So far we have actually only one node in our cluster. A replica set is a node for cluster. Because at any moment, only the primary in the replica set can accept the write operation. So in order to play cluster

, we need to add more than one replica set so that MONGOs can read and write multiple replica sets in parallel.

Refer to the replica set deployment document to create the new replica set you want and add it to the cluster in the previous steps in this document. In the test of this document, we added Shard2, and shard3 two replica set.

If a collection has been fragmented (the shardcollection command has been executed), adding a new shard will trigger the migration of the data.

In the deployment of 3 machines, we put Shard1 's primary in 192.168.33.92:22001, Shard2 Primary on 192.168.33.93:22002, Shard3 's primary on 192.168.33.94:22003. So three machines can be written in parallel.

If MongoDB has the following error log:access control is not enabled and no--bind_ip have been specified.

Is that the machine's firewall is not shutting down.

MongoDB sharding Cluster Setup

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.