1

This is what I want to do:

  1. Create a Config Server
  2. Create 2 Shard
  3. Create a Mongos Router

I don't want to replicate my data using replica set, I want to simulate that each shard has only a part of data like it says is shard theory.

I'm following this guide, but I understood that the guide create many replicas for config server and shared server and I don't want that. So this is what I do:

Config file of Config Server:

sharding:
  clusterRole: configsvr
replication:
  replSetName: localhost
net:
  bindIp: localhost
storage:
  dbPath: /home/christian/mongo/confsvr/metadata

Execute Config Server:

mongod --config /mongo/confsvr/mongod.conf --port 27019

Now doc uses rs.initiate() for adding a replica of config server (if I understood right), so I dropped this part.

After that, I created two config file for Shard Server.

sharding:
 clusterRole: shardsvr
replication:
  replSetName: localhost
net:
  bindIp: localhost
storage:
  dbPath: /home/christian/mongo/shard[1|2]

I started two shard:

mongod --config mongo/shard[1|2]/shard.conf  --port 2703[1|2]

Created conf file for Mongos Router:

sharding:
  configDB:localhost/localhost:27019
net:
  bindIp: localhost

So i tried to start mongos:

mongos --config /home/christian/mongo/router/mongos.conf

But terminal print in loop this:

Unable to reach primary for set localhost

Cannot Reach any nodes for set localhost

Last steps were connecting to mongos, and add the Shards to DB

How could I obtain what I want?

0

1 Answer 1

0

Reference:

There are few things wrong in your approach. I suggest you first understand the concept and test every step. For example once you create your config server make sure you can connect to your Mongod and then only move to next step. Same is true for each of your shard.

My answer is pointing to those and some more reading material so you can do this by yourself.

First of all starting from MongoDB 3.6 shards must be deployed as Replica set and not stand alone:

A MongoDB sharded cluster consists of the following components:

shard: Each shard contains a subset of the sharded data. As of MongoDB 3.6, shards must be deployed as a replica set.

mongos: The mongos acts as a query router, providing an interface between client applications and the sharded cluster.

config servers: Config servers store metadata and configuration settings for the cluster. As of MongoDB 3.4, config servers must be deployed as a replica set (CSRS).

For testing and development, you can deploy a sharded cluster with a minimum number of components. These non-production clusters have the following components:

  • A replica set config server with one member.

  • At least one shard as a single-member replica set.

  • One mongos instance.

What you mentioned below is not possible. You will need Replica Set to use Sharding but for development/test you can have a one member Replica set.

I'm following this guide, but i understood that the guide create much replica for config server and shard server and i don't want that.

You are using same name for Config Server, Shard1 and Shard2 Replicaset. You need to use different name and make sure mongod is running on separate port for all instances.

If all your Mongod is running in one host you need to mention the port in your configuration file. See example here.

See the documentation for using rs.initiate() here.

I do not see you adding your shards to the cluster. See this.

2
  • I read every page you linked yet, but i don't understood still. Replica Set is used to mirror data to each server, Shard to split data between servers, so what means "shard: Each shard contains a subset of the sharded data. As of MongoDB 3.6, shards must be deployed as a replica set. "? Apr 30, 2018 at 7:07
  • Yes shards must be deployed as replica set. For tets/development you can have one member replica set. Apr 30, 2018 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.