Saturday, April 22, 2017

Installation & Configuration of Replication cluster in MongoDB– with example

Installation & Configuration of Replication cluster – with example

Ø  Imagine that we have 3 data centers

Hosts:

server1.tommy.com – DC1
server2.tommy.com – DC2
server3.tommy.com – DC3

Step 1) Plan Ahead! Pick the replica sets, Primary, Secondary, 2nd Secondary (if needed) and Arbiters

rep1a

server1.tommy.com - primary
server2.tommy.com - secondary 1st
server3.tommy.com - secondary 2nd

rep2a

server1.tommy.com - secondary 1st
server2.tommy.com - primary
server3.tommy.com - secondary 2nd

rep3a

server1.tommy.com - secondary 1st
server2.tommy.com - secondary 2nd
server3.tommy.com - primary


Step 2) Download the mongodb tar file

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-linux/

curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.2.tgz
tar -zxvf mongodb-linux-x86_64-3.4.2.tgz

mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-3.4.2/ mongodb

~/.bashrc
export PATH=<mongodb-install-directory>/bin:$PATH


Step 3) Create replica set and replica set member directories.

server1.tommy.com
cd
mkdir -p rep1a/rs1/data
mkdir -p rep2a/rs2/data
mkdir -p rep3a/rs2/data

server2.tommy.com
cd
mkdir -p rep1a/rs2/data
mkdir -p rep2a/rs1/data
mkdir -p rep3a/rs3/data

server3.tommy.com
cd
mkdir -p rep1a/rs3/data
mkdir -p rep2a/rs3/data
mkdir -p rep3a/rs1/data


Step 4) Make other necessary directories for config files(for each member)

server1.tommy.com
cd
mkdir -p rep1a/rs1/conf rep2a/rs2/conf rep3a/rs2/conf
mkdir -p rep1a/rs1/logs rep2a/rs2/logs rep3a/rs2/logs

server2.tommy.com
cd
mkdir -p rep1a/rs2/conf rep2a/rs1/conf rep3a/rs3/conf
mkdir -p rep1a/rs2/logs rep2a/rs1/logs rep3a/rs3/logs

server3.tommy.com
cd
mkdir -p rep1a/rs3/conf rep2a/rs3/conf rep3a/rs1/conf
mkdir -p rep1a/rs3/logs rep2a/rs3/logs rep3a/rs1/logs


Step 5) Create Config files(for each member)

server1.tommy.com

vi /home/tommy/rep1a/rs1/conf/mongod.conf

dbpath=/home/tommy/rep1a/rs1/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep1a/rs1/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20001
replSet = rep1a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>


vi /home/tommy/rep2a/rs2/conf/mongod.conf

dbpath=/home/tommy/rep2a/rs2/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep2a/rs2/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20002
replSet = rep1a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>

vi /home/tommy/rep3a/rs2/conf/mongod.conf

dbpath=/home/tommy/rep3a/rs2/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep3a/rs2/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20003
replSet = rep3a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>

server2.tommy.com

vi /home/tommy/rep1a/rs2/conf/mongod.conf

dbpath=/home/tommy/rep1a/rs2/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep1a/rs2/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20002
replSet = rep1a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>

vi /home/tommy/rep2a/rs1/conf/mongod.conf

dbpath=/home/tommy/rep2a/rs1/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep2a/rs1/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20001
replSet = rep1a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>

vi /home/tommy/rep3a/rs3/conf/mongod.conf

dbpath=/home/tommy/rep3a/rs3/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep3a/rs3/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20002
replSet = rep3a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>


server3.tommy.com

vi /home/tommy/rep1a/rs3/conf/mongod.conf

dbpath=/home/tommy/rep1a/rs3/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep1a/rs3/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20003
replSet = rep1a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>

vi /home/tommy/rep2a/rs3/conf/mongod.conf

dbpath=/home/tommy/rep2a/rs3/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep2a/rs3/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20002
replSet = rep1a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>

vi /home/tommy/rep3a/rs1/conf/mongod.conf

dbpath=/home/tommy/rep3a/rs1/data
#pidfilepath = /opt/mongo/rep1a/rs1/data/mongod_wiredTiger/mongod.pid
logpath = /home/tommy/rep3a/rs1/logs/mongod.log
logappend = true
nojournal = true
oplogSize = 4096

fork = true
#rest = true
#shardsvr = true
port = 20001
replSet = rep3a
#notablescan = true
#storageEngine= wiredTiger

#auth = true
#keyFile = /opt/mongo/rep1a/rs1/admin/conf/mongo.key
#mms-token = <token>
#mms-name = <server-name>
#mms-interval = <seconds>


Step 6) Create a softlink to bin folder for easy access:

ln -s /home/tommy/mongodb/mongodb-linux-x86_64-3.4.2/bin mongo_bin
ln -s /home/tommy this_host


Step 7) Start all the mongod processes

server1.tommy.com

mongo_bin/mongod -f /home/tommy/rep1a/rs1/conf/mongod.conf
mongo_bin/mongod -f /home/tommy/rep2a/rs2/conf/mongod.conf
mongo_bin/mongod -f /home/tommy/rep3a/rs2/conf/mongod.conf

server2.tommy.com

mongo_bin/mongod -f /home/tommy/rep1a/rs2/conf/mongod.conf
mongo_bin/mongod -f /home/tommy/rep2a/rs1/conf/mongod.conf
mongo_bin/mongod -f /home/tommy/rep3a/rs3/conf/mongod.conf

server3.tommy.com

mongo_bin/mongod -f /home/tommy/rep1a/rs3/conf/mongod.conf
mongo_bin/mongod -f /home/tommy/rep2a/rs3/conf/mongod.conf
mongo_bin/mongod -f /home/tommy/rep3a/rs1/conf/mongod.conf


Step 8) Check the process running

[tommy@server3.tommy.com ~]$ ps aux | grep mongod

tommy    30634  0.6  0.0 273816 43668 ?        Sl   12:41   0:00 mongo_bin/mongod -f /home/tommy/rep1a/rs3/conf/mongod.conf
tommy    31323  1.0  0.0 273812 39888 ?        Sl   12:42   0:00 mongo_bin/mongod -f /home/tommy/rep2a/rs3/conf/mongod.conf
tommy    31343  2.0  0.0 273812 41448 ?        Sl   12:42   0:00 mongo_bin/mongod -f /home/tommy/rep3a/rs1/conf/mongod.conf


Step 9) Initiate the Replica sets:

server1.tommy.com

> mongo_bin/mongo --port 20001
> rs.initiate()
> rs.add("server2.tommy.com:20002")
> rs.add("server3.tommy.com:20003")
> rs.status()

mongo_bin/mongo --port 20001
[tommy@server1.tommy.com ~]$ mongo_bin/mongo --port 20001
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:20001/
MongoDB server version: 3.4.2
Server has startup warnings:
2017-04-21T12:23:07.139-0500 I STORAGE  [initandlisten]
2017-04-21T12:23:07.139-0500 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-04-21T12:23:07.139-0500 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-04-21T12:23:07.174-0500 I CONTROL  [initandlisten]
2017-04-21T12:23:07.174-0500 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-04-21T12:23:07.174-0500 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-04-21T12:23:07.174-0500 I CONTROL  [initandlisten]
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten]
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten] ** WARNING: You are running on a NUMA machine.
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten] **          We suggest launching mongod like this to avoid performance problems:
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten] **              numactl --interleave=all mongod [other options]
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten]
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten]
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-04-21T12:23:07.175-0500 I CONTROL  [initandlisten]
> 


rs.initiate()

> rs.initiate()
{
        "info2" : "no configuration specified. Using a default configuration for the set",
        "me" : "server1.tommy.com:20001",
        "ok" : 1
}
rep1a:SECONDARY>
rep1a:PRIMARY>

rs.add()

> rs.add("server2.tommy.com:20002")

rep1a:PRIMARY> rs.add("server2.tommy.com:20002")
{ "ok" : 1 }

> rs.add("server3.tommy.com:20003")

rep1a:PRIMARY> rs.add("server3.tommy.com:20003")
{ "ok" : 1 }

rs.status()

rep1a:PRIMARY> rs.status()
{
        "set" : "rep1a",
        "date" : ISODate("2017-04-23T04:54:51.753Z"),
        "myState" : 1,
        "term" : NumberLong(1),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(0, 0),
                        "t" : NumberLong(-1)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1492923282, 1),
                        "t" : NumberLong(1)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1492923171, 1),
                        "t" : NumberLong(-1)
                }
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "server1.tommy.com:20001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 127904,
                        "optime" : {
                                "ts" : Timestamp(1492923282, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2017-04-23T04:54:42Z"),
                        "infoMessage" : "could not find member to sync from",
                        "electionTime" : Timestamp(1492923171, 2),
                        "electionDate" : ISODate("2017-04-23T04:52:51Z"),
                        "configVersion" : 3,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "server2.tommy.com:20002",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 70,
                        "optime" : {
                                "ts" : Timestamp(1492923282, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDate" : ISODate("2017-04-23T04:54:42Z"),
                        "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("2017-04-23T04:54:50.381Z"),
                        "lastHeartbeatRecv" : ISODate("2017-04-23T04:54:51.384Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "server1.tommy.com:20001",
                        "configVersion" : 3
                },
                {
                        "_id" : 2,
                        "name" : "server3.tommy.com:20003",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 61,
                        "optime" : {
                                "ts" : Timestamp(1492923282, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDate" : ISODate("2017-04-23T04:54:42Z"),
                        "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("2017-04-23T04:54:50.381Z"),
                        "lastHeartbeatRecv" : ISODate("2017-04-23T04:54:51.438Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "server1.tommy.com:20001",
                        "configVersion" : 3
                }
        ],
        "ok" : 1
}


server2.tommy.com

> mongo_bin/mongo --port 20001
> rs.initiate()
> rs.add("server1.tommy.com:20002")
> rs.add("server3.tommy.com:20003")
> rs.status()

mongo_bin/mongo --port 20001

[tommy@server2.tommy.com ~]$ mongo_bin/mongo --port 20001
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:20001/
MongoDB server version: 3.4.2
Server has startup warnings:
2017-04-21T12:36:44.248-0500 I STORAGE  [initandlisten]
2017-04-21T12:36:44.248-0500 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-04-21T12:36:44.248-0500 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-04-21T12:36:44.273-0500 I CONTROL  [initandlisten]
2017-04-21T12:36:44.273-0500 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-04-21T12:36:44.273-0500 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-04-21T12:36:44.273-0500 I CONTROL  [initandlisten]
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten]
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten] ** WARNING: You are running on a NUMA machine.
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten] **          We suggest launching mongod like this to avoid performance problems:
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten] **              numactl --interleave=all mongod [other options]
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten]
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten]
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-04-21T12:36:44.274-0500 I CONTROL  [initandlisten]
> 

rs.initiate()

> rs.initiate()
{
        "info2" : "no configuration specified. Using a default configuration for the set",
        "me" : "server2.tommy.com:20001",
        "ok" : 1
}
rep2a:SECONDARY>
rep2a:PRIMARY>

rs.add()

rep2a:PRIMARY> rs.add("server1.tommy.com:20002")
{ "ok" : 1 }

rep2a:PRIMARY> rs.add("server3.tommy.com:20003")
{ "ok" : 1 }

rs.status()

rep2a:PRIMARY> rs.status()
{
        "set" : "rep2a",
        "date" : ISODate("2017-04-23T05:23:42.579Z"),
        "myState" : 1,
        "term" : NumberLong(1),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(0, 0),
                        "t" : NumberLong(-1)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1492925019, 1),
                        "t" : NumberLong(1)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1492924928, 1),
                        "t" : NumberLong(-1)
                }
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "server2.tommy.com:20001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 159,
                        "optime" : {
                                "ts" : Timestamp(1492925019, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2017-04-23T05:23:39Z"),
                        "infoMessage" : "could not find member to sync from",
                        "electionTime" : Timestamp(1492924928, 2),
                        "electionDate" : ISODate("2017-04-23T05:22:08Z"),
                        "configVersion" : 3,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "server1.tommy.com:20002",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 66,
                        "optime" : {
                                "ts" : Timestamp(1492925019, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDate" : ISODate("2017-04-23T05:23:39Z"),
                        "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("2017-04-23T05:23:41.270Z"),
                        "lastHeartbeatRecv" : ISODate("2017-04-23T05:23:42.276Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "server2.tommy.com:20001",
                        "configVersion" : 3
                },
                {
                        "_id" : 2,
                        "name" : "server3.tommy.com:20003",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 59,
                        "optime" : {
                                "ts" : Timestamp(1492925019, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDate" : ISODate("2017-04-23T05:23:39Z"),
                        "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("2017-04-23T05:23:41.270Z"),
                        "lastHeartbeatRecv" : ISODate("2017-04-23T05:23:42.329Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "server2.tommy.com:20001",
                        "configVersion" : 3
                }
        ],
        "ok" : 1
}


server3.tommy.com
> mongo_bin/mongo --port 20001
> rs.initiate()
> rs.add("server1.tommy.com:20003")
> rs.add("server2.tommy.com:20004")
> rs.status()

mongo_bin/mongo --port 20001

[tommy@server3.tommy.com ~]$ mongo_bin/mongo --port 20001
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:20001/
MongoDB server version: 3.4.2
Server has startup warnings:
2017-04-23T00:38:04.471-0500 I STORAGE  [initandlisten]
2017-04-23T00:38:04.471-0500 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-04-23T00:38:04.471-0500 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-04-23T00:38:04.507-0500 I CONTROL  [initandlisten]
2017-04-23T00:38:04.507-0500 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-04-23T00:38:04.508-0500 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-04-23T00:38:04.508-0500 I CONTROL  [initandlisten]
2017-04-23T00:38:04.508-0500 I CONTROL  [initandlisten]
2017-04-23T00:38:04.508-0500 I CONTROL  [initandlisten] ** WARNING: You are running on a NUMA machine.
2017-04-23T00:38:04.508-0500 I CONTROL  [initandlisten] **          We suggest launching mongod like this to avoid performance problems:
2017-04-23T00:38:04.508-0500 I CONTROL  [initandlisten] **              numactl --interleave=all mongod [other options]
2017-04-23T00:38:04.509-0500 I CONTROL  [initandlisten]
2017-04-23T00:38:04.509-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-04-23T00:38:04.509-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-04-23T00:38:04.509-0500 I CONTROL  [initandlisten]
2017-04-23T00:38:04.509-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-04-23T00:38:04.509-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-04-23T00:38:04.509-0500 I CONTROL  [initandlisten]
> 


rs.initiate()

> rs.initiate()
{
        "info2" : "no configuration specified. Using a default configuration for the set",
        "me" : "server3.tommy.com:20001",
        "ok" : 1
}
rep3a:SECONDARY>
rep3a:PRIMARY>

rs.add()

> rs.add("server1.tommy.com:20003")

rep3a:PRIMARY> rs.add("server1.tommy.com:20003")
{ "ok" : 1 }

> rs.add("server2.tommy.com:20004")

rep3a:PRIMARY> rs.add("server2.tommy.com:20002")
{ "ok" : 1 }

rs.status()

rep3a:PRIMARY> rs.status()
{
        "set" : "rep3a",
        "date" : ISODate("2017-04-23T06:30:28.523Z"),
        "myState" : 1,
        "term" : NumberLong(1),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(0, 0),
                        "t" : NumberLong(-1)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1492929024, 1),
                        "t" : NumberLong(1)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1492926340, 1),
                        "t" : NumberLong(-1)
                }
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "server3.tommy.com:20001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 3144,
                        "optime" : {
                                "ts" : Timestamp(1492929024, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2017-04-23T06:30:24Z"),
                        "electionTime" : Timestamp(1492926340, 2),
                        "electionDate" : ISODate("2017-04-23T05:45:40Z"),
                        "configVersion" : 5,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "server1.tommy.com:20003",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 2559,
                        "optime" : {
                                "ts" : Timestamp(1492929024, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDate" : ISODate("2017-04-23T06:30:24Z"),
                        "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("2017-04-23T06:30:28.084Z"),
                        "lastHeartbeatRecv" : ISODate("2017-04-23T06:30:24.086Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "server3.tommy.com:20001",
                        "configVersion" : 5
                },
                {
                        "_id" : 2,
                        "name" : "server2.tommy.com:20004",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 4,
                        "optime" : {
                                "ts" : Timestamp(1492929024, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDate" : ISODate("2017-04-23T06:30:24Z"),
                        "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("2017-04-23T06:30:28.084Z"),
                        "lastHeartbeatRecv" : ISODate("2017-04-23T06:30:24.128Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "server3.tommy.com:20001",
                        "configVersion" : 5
                }
        ],
        "ok" : 1

}

3 comments:

  1. Well Described...Well documented also...
    Here there are total 9 nodes/server/machine right?
    Thanks Tom for assisting on MongoDB...

    ReplyDelete
  2. It's very nice to share with us this content. Thank you for providing an example and a lot of information. Continue uploading such content

    fantasy cricket app development

    ReplyDelete