January 2019
M T W T F S S
« Dec    
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories

WordPress Quotes

Cherish your visions and your dreams as they are the children of your soul, the blueprints of your ultimate achievements.
Napoleon Hill

Recent Comments

January 2019
M T W T F S S
« Dec    
 123456
78910111213
14151617181920
21222324252627
28293031  

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (34)
Ansibile (19)
Apache (133)
Asterisk (2)
cassandra (2)
Centos (209)
Centos RHEL 7 (261)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (28)
Eassy (11)
ELKS (1)
EXCHANGE (3)
Fedora (6)
ftp (5)
GIT (3)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (7)
JBOSS (32)
jenkins (1)
Kubernetes (2)
Ldap (5)
Linux (189)
Linux Commands (167)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (24)
MYSQL (84)
Nagios (5)
NaturalOil (13)
Nginx (31)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (34)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (12)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (60)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

19 visitors online now
6 guests, 13 bots, 0 members

Hit Counter provided by dental implants orange county

MongoDB replication set settings Replication Sets

MongoDB replication set settings Replication Sets

Master-Slave Master-slave replication: -master only need to add a parameter when a service starts, while another service plus -slave and -source parameters, you can achieve synchronization.

The latest version of MongoDB is no longer recommended for this program.

Replica Sets replication set: MongoDB version 1.6 for developers of new features replica set, which is stronger than some of the previous replication function, increased fault automatic switching and automatic restoration member nodes, exactly the same data between various DB, greatly reducing maintenance success. auto shard has been clearly stated does not support replication paris, we recommended replica set, replica set failover is completely automatic.

Replica Sets structure is very similar to a cluster, if one node failure occurs, the other nodes will immediately take over the business without having to shut down operations.

??MongoDB

[root@node1 ~]# vim /etc/yum.repos.d/Mongodb.repo

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/RedHat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

[root@node1 ~]# yum install -y mongodb-org

[root@node1 ~]# service mongod start
Starting mongod: [ OK ]

[root@node1 ~]# ps aux|grep mong
mongod 1361 5.7 14.8 351180 35104 ? Sl 01:26 0:01 /usr/bin/mongod -f /etc/mongod.conf

[root@node1 ~]# mkdir -p /mongodb/data
[root@node1 ~]# chown -R mongod:mongod /mongodb/
[root@node1 ~]# ll /mongodb/
total 4
drwxr-xr-x 2 mongod mongod 4096 May 18 02:04 data

[root@node1 ~]# grep -v “^#” /etc/mongod.conf |grep -v “^$”
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /mongodb/data
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
net:
port: 27017
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.

[root@node1 ~]# service mongod start
Starting mongod: [ OK ]

node2?node2

Replication Sets

–oplogSize
–dbpath
–logpath
–port
–replSet
–replSet test/
–maxConns
–fork
–logappend
–keyFile

v3.4.4

[root@node1 ~]# vim /etc/mongod.conf
replication:
oplogSizeMB: 1024
replSetName: rs0

Keyfile

openssl rand -base64 756 > chmod 400

Configuration File
If using a configuration file, set the security.keyFile option to the keyfile’s path, and the replication.replSetName option to the replica set name:
security:
keyFile: replication:
replSetName:

Command Line
If using the command line option, start the mongod with the –keyFile and –replSet parameters:

mongod –keyFile –replSet

Replication Sets?

[root@node1 ~]# openssl rand -base64 756 > /mongodb/mongokey
[root@node1 ~]# cat /mongodb/mongokey
gxpcgjyFj2qE8b9TB/0XbdRVYH9VDb55NY03AHwxCFU58MUjJMeez844i1gaUo/t
…..
…..

[root@node1 ~]# chmod 400 /mongodb/mongokey
[root@node1 ~]# chown mongod:mongod /mongodb/mongokey
[root@node1 ~]# ll /mongodb/
total 8
drwxr-xr-x 4 mongod mongod 4096 May 19 18:39 data
-r——– 1 mongod mongod 1024 May 19 18:29 mongokey

[root@node1 ~]# vim /etc/mongod.conf
#security:
security:
keyFile: /mongodb/mongokey

#operationProfiling:

#replication:
replication:
oplogSizeMB: 1024
replSetName: rs0

[root@node1 ~]# service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]

[root@node1 ~]# iptables -I INPUT 4 -m state –state NEW -p tcp –dport 27017 -j ACCEPT

hosts
[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /etc/hosts root@node2.rmohan.com:/mongodb/
[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /etc/hosts root@node3.rmohan.com:/mongodb/

[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /mongodb/mongokey root@node3.rmohan.com:/mongodb/
[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /mongodb/mongokey root@node3.rmohan.com:/mongodb/

[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /etc/mongod.conf root@node2.rmohan.com:/etc/
[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /etc/mongod.conf root@node3.rmohan.com:/etc/

rsync?openssh-clients

[root@node1 ~]# mongo
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
…..

> rs.help()
rs.status() { replSetGetStatus : 1 } checks repl set status
rs.initiate() { replSetInitiate : null } initiates set with default settings
rs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg
rs.conf() get the current configuration object from local.system.replset
…..

> rs.status()
{
“info” : “run rs.initiate(…) if not yet done for the set”,
“ok” : 0,
“errmsg” : “no replset config has been received”,
“code” : 94,
“codeName” : “NotYetInitialized”
}

> rs.initiate()
{
“info2” : “no configuration specified. Using a default configuration for the set”,
“me” : “node1.rmohan.com:27017”,
“ok” : 1
}

rs0:OTHER>
rs0:PRIMARY> rs.status()
{
“set” : “rs0”,
“date” : ISODate(“2017-05-18T17:00:49.868Z”),
“myState” : 1,
“term” : NumberLong(1),
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1495126845, 1),
“t” : NumberLong(1)
},
“appliedOpTime” : {
“ts” : Timestamp(1495126845, 1),
“t” : NumberLong(1)
},
“durableOpTime” : {
“ts” : Timestamp(1495126845, 1),
“t” : NumberLong(1)
}
},
“members” : [
{
“_id” : 0,
“name” : “node1.rmohan.com:27017”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 1239,
“optime” : {
“ts” : Timestamp(1495126845, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-05-18T17:00:45Z”),
“infoMessage” : “could not find member to sync from”,
“electionTime” : Timestamp(1495126824, 2),
“electionDate” : ISODate(“2017-05-18T17:00:24Z”),
“configVersion” : 1,
“self” : true
}
],
“ok” : 1
}

rs0:PRIMARY> rs.add(“node2.rmohan.com”)
{ “ok” : 1 }
rs0:PRIMARY> rs.add(“node3.rmohan.com”)
{ “ok” : 1 }
rs0:PRIMARY> rs.status()
{
“set” : “rs0”,
“date” : ISODate(“2017-05-18T17:08:47.724Z”),
“myState” : 1,
“term” : NumberLong(1),
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
},
“appliedOpTime” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
},
“durableOpTime” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
}
},
“members” : [
{
“_id” : 0,
“name” : “node1.rmohan.com:27017”,
“health” : 1, //
“state” : 1, //1???PRIMARY?slave
“stateStr” : “PRIMARY”, //
“uptime” : 1717,
“optime” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-05-18T17:08:45Z”),
“electionTime” : Timestamp(1495126824, 2),
“electionDate” : ISODate(“2017-05-18T17:00:24Z”),
“configVersion” : 3,
“self” : true
},
{
“_id” : 1,
“name” : “node2.rmohan.com:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 64,
“optime” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
},
“optimeDurable” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-05-18T17:08:45Z”),
“optimeDurableDate” : ISODate(“2017-05-18T17:08:45Z”),
“lastHeartbeat” : ISODate(“2017-05-18T17:08:46.106Z”),
“lastHeartbeatRecv” : ISODate(“2017-05-18T17:08:47.141Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “node1.rmohan.com:27017”,
“configVersion” : 3
},
{
“_id” : 2,
“name” : “node3.rmohan.com:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 55,
“optime” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
},
“optimeDurable” : {
“ts” : Timestamp(1495127325, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-05-18T17:08:45Z”),
“optimeDurableDate” : ISODate(“2017-05-18T17:08:45Z”),
“lastHeartbeat” : ISODate(“2017-05-18T17:08:46.195Z”),
“lastHeartbeatRecv” : ISODate(“2017-05-18T17:08:46.924Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “node2.rmohan.com:27017”,
“configVersion” : 3
}
],
“ok” : 1
}

rs0:PRIMARY> db.isMaster()
{
“hosts” : [
“node1.rmohan.com:27017”,
“node2.rmohan.com:27017”,
“node3.rmohan.com:27017”
],
“setName” : “rs0”,
“setVersion” : 3,
“ismaster” : true,
“secondary” : false,
“primary” : “node1.rmohan.com:27017”,
“me” : “node1.rmohan.com:27017”,
“electionId” : ObjectId(“7fffffff0000000000000001”),
“lastWrite” : {
“opTime” : {
“ts” : Timestamp(1495127705, 1),
“t” : NumberLong(1)
},
“lastWriteDate” : ISODate(“2017-05-18T17:15:05Z”)
},
“maxBsonObjectSize” : 16777216,
“maxMessageSizeBytes” : 48000000,
“maxWriteBatchSize” : 1000,
“localTime” : ISODate(“2017-05-18T17:15:11.146Z”),
“maxWireVersion” : 5,
“minWireVersion” : 0,
“readOnly” : false,
“ok” : 1
}

rs0:PRIMARY> use testdb
rs0:PRIMARY> show collections
testcoll
rs0:PRIMARY> db.testcoll.find()
{ “_id” : ObjectId(“591dd9f965cc255a5373aefa”), “name” : “tom”, “age” : 25 }

node2:
rs0:SECONDARY> rs.slaveOk()
rs0:SECONDARY> show dbs
admin 0.000GB
local 0.000GB
testdb 0.000GB
rs0:SECONDARY> use testdb
switched to db testdb
rs0:SECONDARY> show collections
testcoll
rs0:SECONDARY> db.testcoll.find()
{ “_id” : ObjectId(“591dd9f965cc255a5373aefa”), “name” : “tom”, “age” : 25 }
rs0:SECONDARY>

node3:

rs0:SECONDARY> rs.slaveOk()
rs0:SECONDARY> show dbs
admin 0.000GB
local 0.000GB
testdb 0.000GB
rs0:SECONDARY> use testdb
switched to db testdb
rs0:SECONDARY> show collections
testcoll
rs0:SECONDARY> db.testcoll.find()
{ “_id” : ObjectId(“591dd9f965cc255a5373aefa”), “name” : “tom”, “age” : 25 }
rs0:SECONDARY>

rs0:PRIMARY> use local
switched to db local
rs0:PRIMARY> show collections
me
oplog.rs
replset.election
replset.minvalid
startup_log
system.replset
rs0:PRIMARY> db.oplog.rs.find()
{ “ts” : Timestamp(1495126824, 1), “h” : NumberLong(“3056083863196084673”), “v” : 2, “op” : “n”, “ns” : “”, “o” : { “msg” : “initiating set” } }
{ “ts” : Timestamp(1495126825, 1), “t” : NumberLong(1), “h” : NumberLong(“7195178065440751511”), “v” : 2, “op” : “n”, “ns” : “”, “o” : { “msg” : “new primary” } }
{ “ts” : Timestamp(1495126835, 1), “t” : NumberLong(1), “h” : NumberLong(“5723995478292318850”), “v” : 2, “op” : “n”, “ns” : “”, “o” : { “msg” : “periodic noop” } }
{ “ts” : Timestamp(1495126845, 1), “t” : NumberLong(1), “h” : NumberLong(“-3772304067699003381”), “v” : 2, “op” : “n”, “ns” : “”, “o”

rs0:PRIMARY> db.printReplicationInfo()
configured oplog size: 1024MB
log length start to end: 2541secs (0.71hrs)
oplog first event time: Fri May 19 2017 01:00:24 GMT+0800 (CST)
oplog last event time: Fri May 19 2017 01:42:45 GMT+0800 (CST)
now: Fri May 19 2017 01:42:48 GMT+0800 (CST)
rs0:PRIMARY>

db.oplog.rs.find()?
db.printReplicationInfo()?
db.printSlaveReplicationInfo()?

rs0:PRIMARY> db.printSlaveReplicationInfo()
source: node2.rmohan.com:27017
syncedTo: Fri May 19 2017 01:47:15 GMT+0800 (CST)
0 secs (0 hrs) behind the primary
source: node3.rmohan.com:27017
syncedTo: Fri May 19 2017 01:47:15 GMT+0800 (CST)
0 secs (0 hrs) behind the primary

db.system.replset.find()?

rs0:PRIMARY> db.system.replset.find()
{ “_id” : “rs0”, “version” : 3, “protocolVersion” : NumberLong(1), “members” : [ { “_id” : 0, “host” : “node1.rmohan.com:27017”, “arbiterOnly” : false, “buildIndexes” : true, “hidden” : false, “priority” : 1, “tags” : { }, “slaveDelay” : NumberLong(0), “votes” : 1 }, { “_id” : 1, “host” : “node2.rmohan.com:27017”, “arbiterOnly” : false, “buildIndexes” : true, “hidden” : false, “priority” : 1, “tags” : { }, “slaveDelay” : NumberLong(0), “votes” : 1 }, { “_id” : 2, “host” : “node3.rmohan.com:27017”, “arbiterOnly” : false, “buildIndexes” : true, “hidden” : false, “priority” : 1, “tags” : { }, “slaveDelay” : NumberLong(0), “votes” : 1 } ], “settings” : { “chainingAllowed” : true, “heartbeatIntervalMillis” : 2000, “heartbeatTimeoutSecs” : 10, “electionTimeoutMillis” : 10000, “catchUpTimeoutMillis” : 2000, “getLastErrorModes” : { }, “getLastErrorDefaults” : { “w” : 1, “wtimeout” : 0 }, “replicaSetId” : ObjectId(“591dd3284fc6957e660dc933”) } }

rs0:PRIMARY> db.system.replset.find().forEach(printjson)

1 node3

rs0:SECONDARY> rs.freeze(30)
{ “ok” : 1 }

2?node1 PRIMARY
rs0:PRIMARY> rs.stepDown(30)
2017-05-19T02:09:27.945+0800 E QUERY [thread1] Error: error doing query: failed: network error while attempting to run command ‘replSetStepDown’ on host ‘127.0.0.1:27017’ :
DB.prototype.runCommand@src/mongo/shell/db.js:132:1
DB.prototype.adminCommand@src/mongo/shell/db.js:150:16
rs.stepDown@src/mongo/shell/utils.js:1261:12
@(shell):1:1
2017-05-19T02:09:27.947+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2017-05-19T02:09:27.949+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) ok

30
rs0:SECONDARY> rs.status()
{
“set” : “rs0”,
“date” : ISODate(“2017-05-18T18:12:09.732Z”),
“myState” : 2,
“term” : NumberLong(2),
“syncingTo” : “node2.rmohan.com:27017”,
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1495131128, 1),
“t” : NumberLong(2)
},
“appliedOpTime” : {
“ts” : Timestamp(1495131128, 1),
“t” : NumberLong(2)
},
“durableOpTime” : {
“ts” : Timestamp(1495131128, 1),
“t” : NumberLong(2)
}
},
“members” : [
{
“_id” : 0,
“name” : “node1.rmohan.com:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 5519,
“optime” : {
“ts” : Timestamp(1495131128, 1),
“t” : NumberLong(2)
},
“optimeDate” : ISODate(“2017-05-18T18:12:08Z”),
“syncingTo” : “node2.rmohan.com:27017”,
“configVersion” : 3,
“self” : true
},
{
“_id” : 1,
“name” : “node2.rmohan.com:27017”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 3866,
“optime” : {
“ts” : Timestamp(1495131118, 1),
“t” : NumberLong(2)
},
“optimeDurable” : {
“ts” : Timestamp(1495131118, 1),
“t” : NumberLong(2)
},
“optimeDate” : ISODate(“2017-05-18T18:11:58Z”),
“optimeDurableDate” : ISODate(“2017-05-18T18:11:58Z”),
“lastHeartbeat” : ISODate(“2017-05-18T18:12:08.333Z”),
“lastHeartbeatRecv” : ISODate(“2017-05-18T18:12:08.196Z”),
“pingMs” : NumberLong(0),
“electionTime” : Timestamp(1495130977, 1),
“electionDate” : ISODate(“2017-05-18T18:09:37Z”),
“configVersion” : 3
},
{
“_id” : 2,
“name” : “node3.rmohan.com:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 3857,
“optime” : {
“ts” : Timestamp(1495131118, 1),
“t” : NumberLong(2)
},
“optimeDurable” : {
“ts” : Timestamp(1495131118, 1),
“t” : NumberLong(2)
},
“optimeDate” : ISODate(“2017-05-18T18:11:58Z”),
“optimeDurableDate” : ISODate(“2017-05-18T18:11:58Z”),
“lastHeartbeat” : ISODate(“2017-05-18T18:12:08.486Z”),
“lastHeartbeatRecv” : ISODate(“2017-05-18T18:12:08.116Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “node2.rmohan.com:27017”,
“configVersion” : 3
}
],
“ok” : 1
}
rs0:SECONDARY>

[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /etc/hosts root@node2.rmohan.com:/etc/

[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /mongodb/mongokey root@node4.rmohan.com:/mongodb/

[root@node1 ~]# rsync -avH –progress ‘-e ssh -p 22’ /etc/mongod.conf root@node4.rmohan.com:/etc/

[root@node4 ~]# iptables -I INPUT 4 -m state –state NEW -p tcp –dport 27017 -j ACCEPT

rs0:PRIMARY> rs.add(“node4.rmohan.com”)
{ “ok” : 1 }

rs0:PRIMARY> rs.status()
{
“set” : “rs0”,
“date” : ISODate(“2017-05-19T12:12:57.697Z”),
“myState” : 1,
“term” : NumberLong(8),
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“appliedOpTime” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“durableOpTime” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
}
},
“members” : [
{
“_id” : 0,
“name” : “node1.rmohan.com:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 159,
“optime” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“optimeDurable” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“optimeDate” : ISODate(“2017-05-19T12:12:51Z”),
“optimeDurableDate” : ISODate(“2017-05-19T12:12:51Z”),
“lastHeartbeat” : ISODate(“2017-05-19T12:12:56.111Z”),
“lastHeartbeatRecv” : ISODate(“2017-05-19T12:12:57.101Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “node3.rmohan.com:27017”,
“configVersion” : 4
},
{
“_id” : 1,
“name” : “node2.rmohan.com:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 189,
“optime” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“optimeDurable” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“optimeDate” : ISODate(“2017-05-19T12:12:51Z”),
“optimeDurableDate” : ISODate(“2017-05-19T12:12:51Z”),
“lastHeartbeat” : ISODate(“2017-05-19T12:12:56.111Z”),
“lastHeartbeatRecv” : ISODate(“2017-05-19T12:12:57.103Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “node3.rmohan.com:27017”,
“configVersion” : 4
},
{
“_id” : 2,
“name” : “node3.rmohan.com:27017”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 191,
“optime” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“optimeDate” : ISODate(“2017-05-19T12:12:51Z”),
“electionTime” : Timestamp(1495195800, 1),
“electionDate” : ISODate(“2017-05-19T12:10:00Z”),
“configVersion” : 4,
“self” : true
},
{
“_id” : 3,
“name” : “node4.rmohan.com:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 71,
“optime” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“optimeDurable” : {
“ts” : Timestamp(1495195971, 1),
“t” : NumberLong(8)
},
“optimeDate” : ISODate(“2017-05-19T12:12:51Z”),
“optimeDurableDate” : ISODate(“2017-05-19T12:12:51Z”),
“lastHeartbeat” : ISODate(“2017-05-19T12:12:56.122Z”),
“lastHeartbeatRecv” : ISODate(“2017-05-19T12:12:56.821Z”),
“pingMs” : NumberLong(1),
“syncingTo” : “node3.rmohan.com:27017”,
“configVersion” : 4
}
],
“ok” : 1
}

rs0:SECONDARY> rs.slaveOk()
rs0:SECONDARY> show dbs
admin 0.000GB
local 0.000GB
testdb 0.000GB
rs0:SECONDARY> use testdb
switched to db testdb
rs0:SECONDARY> show collections
testcoll
rs0:SECONDARY> db.testcoll.find()
{ “_id” : ObjectId(“591dd9f965cc255a5373aefa”), “name” : “tom”, “age” : 25 }
rs0:SECONDARY>
rs0:SECONDARY> db.isMaster()
{
“hosts” : [
“node1.rmohan.com:27017”,
“node2.rmohan.com:27017”,
“node3.rmohan.com:27017”,
“node4.rmohan.com:27017”
],
“setName” : “rs0”,
“setVersion” : 4,
“ismaster” : false,
“secondary” : true,
“primary” : “node3.rmohan.com:27017”,
“me” : “node4.rmohan.com:27017”,
“lastWrite” : {
“opTime” : {
“ts” : Timestamp(1495196261, 1),
“t” : NumberLong(8)
},
“lastWriteDate” : ISODate(“2017-05-19T12:17:41Z”)
},
“maxBsonObjectSize” : 16777216,
“maxMessageSizeBytes” : 48000000,
“maxWriteBatchSize” : 1000,
“localTime” : ISODate(“2017-05-19T12:17:44.104Z”),
“maxWireVersion” : 5,
“minWireVersion” : 0,
“readOnly” : false,
“ok” : 1
}
rs0:SECONDARY>

2?

rs0:PRIMARY> rs.remove(“node4.rmohan.com:27017”)
{ “ok” : 1 }

rs0:PRIMARY> db.isMaster()
{
“hosts” : [
“node1.rmohan.com:27017”,
“node2.rmohan.com:27017”,
“node3.rmohan.com:27017”
],
“setName” : “rs0”,
“setVersion” : 5,
“ismaster” : true,
“secondary” : false,
“primary” : “node3.rmohan.com:27017”,
“me” : “node3.rmohan.com:27017”,
“electionId” : ObjectId(“7fffffff0000000000000008”),
“lastWrite” : {
“opTime” : {
“ts” : Timestamp(1495196531, 1),
“t” : NumberLong(8)
},
“lastWriteDate” : ISODate(“2017-05-19T12:22:11Z”)
},
“maxBsonObjectSize” : 16777216,
“maxMessageSizeBytes” : 48000000,
“maxWriteBatchSize” : 1000,
“localTime” : ISODate(“2017-05-19T12:22:19.874Z”),
“maxWireVersion” : 5,
“minWireVersion” : 0,
“readOnly” : false,
“ok” : 1
}
rs0:PRIMARY>

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Blue Captcha Image
Refresh

*

Protected by WP Anti Spam