Giter Club home page Giter Club logo

mongodb-cluster-docker-compose's Introduction

MongoDB (6.0.1) Sharded Cluster with Docker Compose

Star History

Star History Chart

PSS Style (Primary -Secondary - Secondary)

  • Need PSA? Check here
  • If you need to set cluster with keyfile authentication, check here

๐Ÿ“– Table of Contents

WARNING (Windows & OS X)

The default Docker setup on Windows and OS X uses a VirtualBox VM to host the Docker daemon. Unfortunately, the mechanism VirtualBox uses to share folders between the host system and the Docker container is not compatible with the memory mapped files used by MongoDB (see vbox bug, docs.mongodb.org and related jira.mongodb.org bug). This means that it is not possible to run a MongoDB container with the data directory mapped to the host.

โ€“ Docker Hub (source here or here)


Note:

If you want to modify config files, on Windows you might need to save those file with EOL Conversion Unix (LF) mode. You can use notepad++ to do that Edit menu => EOL Conversion => Unix


โ“ Mongo Components ๐Ÿ”

  • Config Server (3 member replica set): configsvr01,configsvr02,configsvr03
  • 3 Shards (each a 3 member PSS replica set):
    • shard01-a,shard01-b, shard01-c
    • shard02-a,shard02-b, shard02-c
    • shard03-a,shard03-b, shard03-c
  • 2 Routers (mongos): router01, router02

โœจ Steps ๐Ÿ”

๐Ÿ‘‰ Step 1: Start all of the containers ๐Ÿ”

I have to remind again in case you missed ๐Ÿ˜Š If you need to set cluster with keyfile authentication, check here

Clone this repository, open powershell or cmd on the repo folder and run:

docker-compose up -d

If you get error "docker.errors.DockerException: Error while fetching server API version" and used WSL (Windows Subsystem for Linux) need to enable 'WSL Integration' for required distro in Windows Docker Desktop (Settings -> Resources-> WSL Integration -> Enable integration with required distros).

Link: https://stackoverflow.com/a/65347214/3007147

๐Ÿ‘‰ Step 2: Initialize the replica sets (config servers and shards) ๐Ÿ”

Run these command one by one:

docker-compose exec configsvr01 sh -c "mongosh < /scripts/init-configserver.js"

docker-compose exec shard01-a sh -c "mongosh < /scripts/init-shard01.js"
docker-compose exec shard02-a sh -c "mongosh < /scripts/init-shard02.js"
docker-compose exec shard03-a sh -c "mongosh < /scripts/init-shard03.js"

If you get error like "E QUERY [thread1] SyntaxError: unterminated string literal @(shellhelp2)", problem maybe due to:

On Unix, you will get this error if your script has Dos/Windows end of lines (CRLF) instead of Unix end of lines (LF).

To fix it, modify script files in scripts folder, remove newline, change multi line to one line.

Or save the file with Unix mode in notepad++ Edit menu => EOL Conversion => Unix

Link: https://stackoverflow.com/a/51728442/3007147

๐Ÿ‘‰ Step 3: Initializing the router ๐Ÿ”

Note: Wait a bit for the config server and shards to elect their primaries before initializing the router

docker-compose exec router01 sh -c "mongosh < /scripts/init-router.js"

๐Ÿ‘‰ Step 4: Enable sharding and setup sharding-key ๐Ÿ”

docker-compose exec router01 mongosh --port 27017

// Enable sharding for database `MyDatabase`
sh.enableSharding("MyDatabase")

// Setup shardingKey for collection `MyCollection`**
db.adminCommand( { shardCollection: "MyDatabase.MyCollection", key: { oemNumber: "hashed", zipCode: 1, supplierId: 1 } } )

โœ”๏ธ Done !!!

But before you start inserting data you should verify them first

Btw, here is mongodb connection string if you want to try to connect mongodb cluster with MongoDB Compass from your host computer (which is running docker)

mongodb://127.0.0.1:27117,127.0.0.1:27118

And if you are .NET developer there is a sample READ/WRITE data in mongodb cluster here: https://github.com/minhhungit/mongodb-cluster-docker-compose/tree/master/client


๐Ÿ“‹ Verify ๐Ÿ”

โœ… Verify the status of the sharded cluster ๐Ÿ”

docker-compose exec router01 mongosh --port 27017
sh.status()

Sample Result:

  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5d38fb010eac1e03397c355a")
  }
  shards:
        {  "_id" : "rs-shard-01",  "host" : "rs-shard-01/shard01-a:27017,shard01-b:27017,shard01-c:27017",  "state" : 1 }
        {  "_id" : "rs-shard-02",  "host" : "rs-shard-02/shard02-a:27017,shard02-b:27017,shard02-c:27017",  "state" : 1 }
        {  "_id" : "rs-shard-03",  "host" : "rs-shard-03/shard03-a:27017,shard03-b:27017,shard03-c:27017",  "state" : 1 }
  active mongoses:
        "4.0.10" : 2
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }

โœ… Verify status of replica set for each shard ๐Ÿ”

You should see 1 PRIMARY, 2 SECONDARY

docker exec -it shard-01-node-a bash -c "echo 'rs.status()' | mongosh --port 27017" 
docker exec -it shard-02-node-a bash -c "echo 'rs.status()' | mongosh --port 27017" 
docker exec -it shard-03-node-a bash -c "echo 'rs.status()' | mongosh --port 27017" 

Sample Result:

MongoDB shell version v4.0.11
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("dcfe5d8f-75ef-45f7-9595-9d72dc8a81fc") }
MongoDB server version: 4.0.11
{
        "set" : "rs-shard-01",
        "date" : ISODate("2019-08-01T06:53:59.175Z"),
        "myState" : 1,
        "term" : NumberLong(1),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1564642438, 1),
                        "t" : NumberLong(1)
                },
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1564642438, 1),
                        "t" : NumberLong(1)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1564642438, 1),
                        "t" : NumberLong(1)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1564642438, 1),
                        "t" : NumberLong(1)
                }
        },
        "lastStableCheckpointTimestamp" : Timestamp(1564642428, 1),
        "members" : [
                {
                        "_id" : 0,
                        "name" : "shard01-a:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 390,
                        "optime" : {
                                "ts" : Timestamp(1564642438, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2019-08-01T06:53:58Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1564642306, 1),
                        "electionDate" : ISODate("2019-08-01T06:51:46Z"),
                        "configVersion" : 2,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 1,
                        "name" : "shard01-b:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 142,
                        "optime" : {
                                "ts" : Timestamp(1564642428, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1564642428, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2019-08-01T06:53:48Z"),
                        "optimeDurableDate" : ISODate("2019-08-01T06:53:48Z"),
                        "lastHeartbeat" : ISODate("2019-08-01T06:53:57.953Z"),
                        "lastHeartbeatRecv" : ISODate("2019-08-01T06:53:57.967Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "shard01-a:27017",
                        "syncSourceHost" : "shard01-a:27017",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 2
                },
                {
                        "_id" : 2,
                        "name" : "shard01-c:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 142,
                        "optime" : {
                                "ts" : Timestamp(1564642428, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1564642428, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2019-08-01T06:53:48Z"),
                        "optimeDurableDate" : ISODate("2019-08-01T06:53:48Z"),
                        "lastHeartbeat" : ISODate("2019-08-01T06:53:57.952Z"),
                        "lastHeartbeatRecv" : ISODate("2019-08-01T06:53:57.968Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "shard01-a:27017",
                        "syncSourceHost" : "shard01-a:27017",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 2
                }
        ],
        "ok" : 1,
        "operationTime" : Timestamp(1564642438, 1),
        "$gleStats" : {
                "lastOpTime" : Timestamp(0, 0),
                "electionId" : ObjectId("7fffffff0000000000000001")
        },
        "lastCommittedOpTime" : Timestamp(1564642438, 1),
        "$configServerState" : {
                "opTime" : {
                        "ts" : Timestamp(1564642426, 2),
                        "t" : NumberLong(1)
                }
        },
        "$clusterTime" : {
                "clusterTime" : Timestamp(1564642438, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}
bye

โœ… Check database status ๐Ÿ”

docker-compose exec router01 mongosh --port 27017
use MyDatabase
db.stats()
db.MyCollection.getShardDistribution()

Sample Result:

{
        "raw" : {
                "rs-shard-01/shard01-a:27017,shard01-b:27017,shard01-c:27017" : {
                        "db" : "MyDatabase",
                        "collections" : 1,
                        "views" : 0,
                        "objects" : 0,
                        "avgObjSize" : 0,
                        "dataSize" : 0,
                        "storageSize" : 4096,
                        "numExtents" : 0,
                        "indexes" : 2,
                        "indexSize" : 8192,
                        "fsUsedSize" : 12439990272,
                        "fsTotalSize" : 62725787648,
                        "ok" : 1
                },
                "rs-shard-03/shard03-a:27017,shard03-b:27017,shard03-c:27017" : {
                        "db" : "MyDatabase",
                        "collections" : 1,
                        "views" : 0,
                        "objects" : 0,
                        "avgObjSize" : 0,
                        "dataSize" : 0,
                        "storageSize" : 4096,
                        "numExtents" : 0,
                        "indexes" : 2,
                        "indexSize" : 8192,
                        "fsUsedSize" : 12439994368,
                        "fsTotalSize" : 62725787648,
                        "ok" : 1
                },
                "rs-shard-02/shard02-a:27017,shard02-b:27017,shard02-c:27017" : {
                        "db" : "MyDatabase",
                        "collections" : 1,
                        "views" : 0,
                        "objects" : 0,
                        "avgObjSize" : 0,
                        "dataSize" : 0,
                        "storageSize" : 4096,
                        "numExtents" : 0,
                        "indexes" : 2,
                        "indexSize" : 8192,
                        "fsUsedSize" : 12439994368,
                        "fsTotalSize" : 62725787648,
                        "ok" : 1
                }
        },
        "objects" : 0,
        "avgObjSize" : 0,
        "dataSize" : 0,
        "storageSize" : 12288,
        "numExtents" : 0,
        "indexes" : 6,
        "indexSize" : 24576,
        "fileSize" : 0,
        "extentFreeList" : {
                "num" : 0,
                "totalSize" : 0
        },
        "ok" : 1,
        "operationTime" : Timestamp(1564004884, 36),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1564004888, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

๐Ÿ”Ž More commands ๐Ÿ”

docker exec -it mongo-config-01 bash -c "echo 'rs.status()' | mongosh --port 27017"


docker exec -it shard-01-node-a bash -c "echo 'rs.help()' | mongosh --port 27017"
docker exec -it shard-01-node-a bash -c "echo 'rs.status()' | mongosh --port 27017" 
docker exec -it shard-01-node-a bash -c "echo 'rs.printReplicationInfo()' | mongosh --port 27017" 
docker exec -it shard-01-node-a bash -c "echo 'rs.printSlaveReplicationInfo()' | mongosh --port 27017"

โœฆ Normal Startup ๐Ÿ”

The cluster only has to be initialized on the first run.

Subsequent startup can be achieved simply with docker-compose up or docker-compose up -d

โœฆ Resetting the Cluster ๐Ÿ”

To remove all data and re-initialize the cluster, make sure the containers are stopped and then:

docker-compose rm

โœฆ Clean up docker-compose ๐Ÿ”

docker-compose down -v --rmi all --remove-orphans

๐Ÿ“บ Screenshot ๐Ÿ”


๐Ÿ‘Œ Donate ^^ ๐Ÿ”

If you like my works and would like to support then you can buy me a coffee โ˜•๏ธ anytime

Buy Me a Coffee at ko-fi.com

I would appreciate it โค๏ธโค๏ธโค๏ธ


๐Ÿ“š Refrences ๐Ÿ”

mongodb-cluster-docker-compose's People

Contributors

minhhungit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongodb-cluster-docker-compose's Issues

failed to initiallized

I tried to initialize the cluster and it threw me an error
docker compose exec configsvr01 bash "/scripts/init-configserver.js"
/scripts/init-configserver.js: line 1: syntax error near unexpected token {' /scripts/init-configserver.js: line 1: rs.initiate({ _id: "rs-config-server", configsvr: true, version: 1, members: [ { _id: 0, host : 'configsvr01:27017' }, { _id: 1, host : 'configsvr02:27017' }, { _id: 2, host : 'configsvr03:27017' } ] })'

The syntax looks fine to me. I run it on Ubuntu 20.04LTS btw.

Authentication for cluster

How can i set username and password for connect to cluster. Set env to all service in docker compose like this ??

router01:
..
environment:
MONGO_INITDB_ROOT_USERNAME: $MONGO_ROOT
MONGO_INITDB_ROOT_PASSWORD: $MONGO_PASSWORD

Error when change image in 'with-keyfile-auth' docker compose file

I changed the docker image in with-keyfile-auth/docker-compose.yml from jin-mongo:6.0.2 to mongo:5.0.13. Then it throws the below error,

router-01 | {"t":{"$date":"2023-06-26T17:25:52.595+00:00"},"s":"I", "c":"ACCESS", "id":20254, "ctx":"main","msg":"Read security file failed","attr":{"error":{"code":30,"codeName":"InvalidPath","errmsg":"Error reading file /data/mongodb-keyfile: No such file or directory"}}}
router-01 | {"t":{"$date":"2023-06-26T17:25:52.595+00:00"},"s":"F", "c":"-", "id":22866, "ctx":"main","msg":"Error creating service context","attr":{"error":"Location5579201: Unable to acquire security key[s]"}}
router-01 | {"t":{"$date":"2023-06-26T17:25:52.595+00:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"main","msg":"Shutting down","attr":{"exitCode":14}}`

Can you help me to figure out the reason for the error

No shards found

Hello
i have follow your instructions and when i try to create a database, i have this error :
**Failed to create database 'm'.

Error:
Unable to initialize targeter for write op for collection m.temp :: caused by :: Database m not found :: caused by :: No shards found**

My script :

def deploy(self, stack_name):
        try:
            #Step 1: Start all of the containers
            print(':::::: Step 1: Start all of the containers')
            os.system('docker stack deploy -c {0}/scripts/mongo/docker-compose.yml {1}'.format(root, stack_name))


            #Step 2: Initialize the replica sets (config servers and shards) and routers
            print(':::::: Step 2: Initialize the replica sets (config servers and shards) and routers')

            # time.sleep(60)
            configsvrs_results = self.get_containers([stack_name + '_configsvr01'])

            if len(list(configsvrs_results['containers'].keys())) == 0:
                raise ValueError(stack_name + '_configsvr01 not found')
            else:
                mongo_configsvr01 = configsvrs_results['containers'][
                    list( configsvrs_results['containers'].keys() )[0]
                ]

                print(mongo_configsvr01.exec_run('mongo --port 27017 --configsvr --replSet rs-config-server'))
                print('----' * 20)

                print(mongo_configsvr01.exec_run('mongo < /scripts/init-configserver.js'.format(root, stack_name)))
                print('----' * 20)
            

            shards_results = self.get_containers([stack_name + '_shard01-a', stack_name + '_shard02-a', stack_name + '_shard03-a'])
            if shards_results['counter'] != 3 :
                raise ValueError('all shards not founds')
            else:
                for name in shards_results['containers']:
                    ctn = shards_results['containers'][name]
                    print('<<<<<<<<<<<<>>>>>>>>>>>>>', name)
                    ref = re.match(r"_shard([0-9]+)-a", name)
                    if ref is not None:
                        print('<<<<<<<<<<<<>>>>>>>>>>>>>', ref.group(1))
                        print(ctn.exec_run('mongo < /scripts/scripts/init-shard{1}.js'.format(ref.group(1))))


            # time.sleep(60)
            #Step 3: Connect to the primary and add arbiters
            print(':::::: Step 3: Connect to the primary and add arbiters')
            for name in shards_results['containers']:
                ctn = shards_results['containers'][name]
                ref = re.match(r"_shard([0-9]+)-a", name)
                if ref is not None:
                    print('<<<<<<<<<<<<>>>>>>>>>>>>>', ref.group(1))
                    print(ctn.exec_run("echo 'rs.addArb(\""+stack_name+ "_shard{0}-x:27017\")' | mongo --port 27017".format(ref.group(1))))


            #Step 4: Initializing the router
            print('::::::: Step 4: Initializing the router')

            #Note: Wait a bit for the config server and shards to elect their primaries before initializing the router
            time.sleep(60)

            router01_results = self.get_containers([stack_name + '_router01'])
            if len(router01_results['containers']) == 0:
                raise ValueError(stack_name + '_router01 not founds')
            else:
                router01 = router01_results['containers'][list(router01_results['containers'].keys())[0]]
                print(router01.exec_run('mongo < /scripts/init-router.js'.format(root)))
            

            #Step 5: Enable sharding and setup sharding-key
            print('::::::: Step 5: Enable sharding and setup sharding-key')
            print(router01.exec_run('mongo < /scripts/enable-sharding.js'.format(root)))

            #Verify
            print('::::::: Verify')

            time.sleep(60)
            print('---- Verify the status of the sharded cluster')
            #Verify the status of the sharded cluster
            print(router01.exec_run("echo 'sh.status()' | mongo --port 27017"))


            print('---- Verify status of replica set for each shard')
            for name in shards_results['containers']:
                ctn = shards_results['containers'][name]
                #Verify status of replica set for each shard
                print('===================' )
                print(ctn.name)
                print('===================')
                print(ctn.exec_run("echo 'sh.status()' | mongo --port 27017"))
            

            print('---- Check database status')
            print(router01.exec_run("echo 'use MyDatabase' | mongo --port 27017"))
            print(router01.exec_run("echo 'db.stats()' | mongo --port 27017"))
            print(router01.exec_run("echo 'db.getUsers()' | mongo --port 27017"))
            print(router01.exec_run("echo 'db.changeUserPassword(\"admin\", \"6b65795f31\")' | mongo --port 27017"))
            print(router01.exec_run("echo 'db.MyCollection.getShardDistribution()' | mongo --port 27017"))
        except Exception as e:
            print(e)
            exit()

show an example of connecting to cluster with mongodb driver

So I have these containers running now:

CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                                            NAMES
233900e71ca8        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 3 minutes        0.0.0.0:27121->27017/tcp                         rydell-mongo-config-03
9bfd351f9cdf        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27120->27017/tcp                         rydell-mongo-config-02
94163eb82215        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27119->27017/tcp                         rydell-mongo-config-01
61e289602d5d        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27128->27017/tcp                         rydell-shard-03-node-a
dbc527b7ba24        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27118->27017/tcp                         rydell-router-02
cce70b2cb752        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27122->27017/tcp                         rydell-shard-01-node-a
db1a7f001bc3        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27125->27017/tcp                         rydell-shard-02-node-a
06f031e7b2f5        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27129->27017/tcp                         rydell-shard-03-node-b
3b83eefa2e30        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27123->27017/tcp                         rydell-shard-01-node-b
cabcd65b4092        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27124->27017/tcp                         rydell-shard-01-node-c
057dfb770b27        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27130->27017/tcp                         rydell-shard-03-node-c
66b2f9a266a6        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27117->27017/tcp                         rydell-router-01
977ff9982704        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27127->27017/tcp                         rydell-shard-02-node-c
9b607ded9559        mongo:4.0                                             "docker-entrypoint.sโ€ฆ"   4 minutes ago       Up 4 minutes        0.0.0.0:27126->27017/tcp                         rydell-shard-02-node-b

how do I know which ones I should connect in a mongod:// connection string?

getting started with this repo

This looks useful, I just want to create a cluster with a replication set using docker-compose. I cloned the repo, and ran:

docker-compose up

I got this:

rydell-router-01 | 2019-09-10T02:57:44.865+0000 I NETWORK  [mongosMain] Cannot reach any nodes for set rs-config-server. Please check network connectivity and the status of the set. This has happened for 71 checks in a row.
rydell-router-02 | 2019-09-10T02:57:44.958+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:45.069+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:45.169+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:45.169+0000 I NETWORK  [monitoring keys for HMAC] Cannot reach any nodes for set rs-config-server. Please check network connectivity and the status of the set. This has happened for 61 checks in a row.
rydell-router-01 | 2019-09-10T02:57:45.367+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:45.462+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:45.572+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:45.672+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:45.870+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:45.943+0000 W NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:45.964+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:46.075+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:46.175+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:46.372+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:46.469+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:46.579+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:46.678+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:46.875+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-02 | 2019-09-10T02:57:46.974+0000 W NETWORK  [mongosMain] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:47.081+0000 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set rs-config-server
rydell-router-01 | 2019-09-10T02:57:47.081+0000 I NETWORK  [monitoring keys for HMAC] Cannot reach any nodes for set rs-config-server. Please check network connectivity and the status of the set. This has happened for 81 checks in a row.

did I miss a step? also what is "rydell" that's not a mongodb thing right?

how to enable authentication

How do we enable authentication on the cluster? I assume it should be on router01. But it seems that only uses for shard.

Anyway, thanks for sharing. save me tons of work. much appreciated

show how to safely take down replicas

It would be nice to see how to safely remove replicas from the cluster.
I only need 1 or 2 replicas in my case. For whatever reason, ChangeStreams seem to work much slower with a lot of replicas?

Development version

Nice work on this.

I was thinking it would also be nice to have a developer version where it only uses

  • 3 x Single node Replicaset
  • 1 config server
  • 1 mongos instance

Obviously to mimic prod environment as close as possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.