• Wed. Dec 7th, 2022

SoftwareMile.com

Latest Software News and Hacks

Replica Set connection through SSH TCP forwarding

Byadmin

May 31, 2022

Hi, I am trying to add a replicaset member to my cluster through a SSH TCP forwarding connection. However, when I play some tests on virtual machines, adding the same member through SSH TCP forwarding instead of a “normal” network connection give me “replica set IDs” error.

Service running:

ssh -L -N :27001:vm3:27017 

rs.conf() 

{ “_id” : “rs0”, “version” : 31, “protocolVersion” : NumberLong(1), “members” : [ { “_id” : 0, “host” : “vm1:27017”, “arbiterOnly” : false, “buildIndexes” : true, “hidden” : false, “priority” : 1, “tags” : {

 }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 1, "host" : "vm2:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 0.5, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : 60000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("xxxxxxxxxxxxxxxxxxxxxxxx") } 

Then, when I add the new member with a direct network connection:

rs0:PRIMARY> rs.add({host:"vm3:27017",priority:0.5}) { "ok" : 1 } rs0:PRIMARY> rs.status() { "set" : "rs0", "date" : ISODate("2022-05-31T13:56:15.556Z"), "myState" : 1, "term" : NumberLong(1), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) }, "appliedOpTime" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) }, "durableOpTime" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) } }, "members" : [ { "_id" : 0, "name" : "vm1:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 19685, "optime" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-05-31T13:56:10Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1653985697, 1), "electionDate" : ISODate("2022-05-31T08:28:17Z"), "configVersion" : 33, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 1, "name" : "vm2:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 19667, "optime" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-05-31T13:56:10Z"), "optimeDurableDate" : ISODate("2022-05-31T13:56:10Z"), "lastHeartbeat" : ISODate("2022-05-31T13:56:14.277Z"), "lastHeartbeatRecv" : ISODate("2022-05-31T13:56:15.352Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 33 }, { "_id" : 2, "name" : "vm3:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 5, "optime" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1654005370, 2), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-05-31T13:56:10Z"), "optimeDurableDate" : ISODate("2022-05-31T13:56:10Z"), "lastHeartbeat" : ISODate("2022-05-31T13:56:14.301Z"), "lastHeartbeatRecv" : ISODate("2022-05-31T13:56:11.053Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 33 } ], "ok" : 1 } 

All is ok and the vm3 replicaset member is SECONDARY. But when I add the same member through SSH TCP forwarding:

#/etc/hosts 

[…] 127.0.0.1 vm3-ssh […]

rs0:PRIMARY> rs.add({host:"vm3-ssh:27001",priority:0.5}) { "ok" : 1 } rs0:PRIMARY> rs.status() { "set" : "rs0", "date" : ISODate("2022-05-31T14:04:11.568Z"), "myState" : 1, "term" : NumberLong(1), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1654005850, 1), "t" : NumberLong(1) }, "appliedOpTime" : { "ts" : Timestamp(1654005850, 1), "t" : NumberLong(1) }, "durableOpTime" : { "ts" : Timestamp(1654005850, 1), "t" : NumberLong(1) } }, "members" : [ { "_id" : 0, "name" : "vm1:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 20161, "optime" : { "ts" : Timestamp(1654005850, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-05-31T14:04:10Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1653985697, 1), "electionDate" : ISODate("2022-05-31T08:28:17Z"), "configVersion" : 35, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 1, "name" : "vm2:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 20143, "optime" : { "ts" : Timestamp(1654005850, 1), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1654005850, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-05-31T14:04:10Z"), "optimeDurableDate" : ISODate("2022-05-31T14:04:10Z"), "lastHeartbeat" : ISODate("2022-05-31T14:04:10.700Z"), "lastHeartbeatRecv" : ISODate("2022-05-31T14:04:10.791Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "vm1:27017", "syncSourceHost" : "vm1:27017", "syncSourceId" : 0, "infoMessage" : "", "configVersion" : 35 }, { "_id" : 2, "name" : "vm3-ssh:27001", "health" : 0, "state" : 8, "stateStr" : "(not reachable/healthy)", "uptime" : 0, "optime" : { "ts" : Timestamp(0, 0), "t" : NumberLong(-1) }, "optimeDurable" : { "ts" : Timestamp(0, 0), "t" : NumberLong(-1) }, "optimeDate" : ISODate("1970-01-01T00:00:00Z"), "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"), "lastHeartbeat" : ISODate("2022-05-31T14:04:10.886Z"), "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "replica set IDs do not match, ours: XXXXXXXXXXXXXXXXXXXXXXXXX; remote node's: YYYYYYYYYYYYYYYYYYYYYYYY", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : -1 } ], "ok" : 1 } 

I always try it on new instances on new VMs. I don’t understand why I get different replica set IDs through SSH TCP forwarding (I tell it again: the same mongodb instance is behind these too connection ways). Can anyone help me? Do you know how replica sets IDs are generated ?

Thank you for your help !

submitted by /u/simee02
[link] [comments]


Go to Source of this post
Author Of this post: /u/simee02
Title Of post: Replica Set connection through SSH TCP forwarding
Author Link: {authorlink}