Setup Shard Config Server (mongo-shard-config):

Once the installation is done on all the systems, we have to configure the Shard config server process and start accordingly.

# create required directories for mongo-shard-config server
$ sudo mkdir -p /srv/mongo-shard-config/data
$ sudo mkdir -p /srv/mongo-shard-config/logs

# start mongodb config server process
$ sudo mongod --configsvr --replSet configrs --enableMajorityReadConcern --dbpath /srv/mongo-shard-config/data --bind_ip 0.0.0.0 --logpath /srv/mongo-shard-config/logs/mongo-shard-config.log --fork

Now the shard config server should be ready to use and output should look like as follows:

MongoDB Shard Config Server

Now let’s configure the Shard Config server with the initial configurations as follows:

$ mongo localhost:27019

MongoDB shell version v4.0.5
connecting to: mongodb://localhost:27019/test?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5207abec-5464-4029-b3fe-2018cdf2ebe3") }
MongoDB server version: 4.0.5
Server has startup warnings: 
2019-01-18T08:32:46.512+0530 I STORAGE [initandlisten] 
2019-01-18T08:32:46.512+0530 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-01-18T08:32:46.512+0530 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-01-18T08:32:47.349+0530 I CONTROL [initandlisten] 
2019-01-18T08:32:47.349+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-18T08:32:47.349+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-01-18T08:32:47.349+0530 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-01-18T08:32:47.349+0530 I CONTROL [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

> use admin
switched to db admin

> rs.initiate(
...     {
...         _id: "configrs",
...         members: [
...             { _id: 0, host : "172.16.1.4:27019" }
...         ]
...     }
... )
{
    "ok" : 1,
    "operationTime" : Timestamp(1548057311, 1),
    "$gleStats" : {
        "lastOpTime" : Timestamp(1548057311, 1),
        "electionId" : ObjectId("000000000000000000000000")
    },
    "lastCommittedOpTime" : Timestamp(0, 0),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1548057311, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}

Part 3: Setup Mongos Router Server (mongos-router)