[JAVA-2211] Connect to ReplicaSet through SSH tunneling Created: 08/Jun/16 Updated: 11/Sep/19 Resolved: 20/Sep/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Connection Management |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Enrico Candino [X] | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I've a remote ReplicaSet and I'm trying to connect through an SSH tunnel, but after the discovery of the cluster, since the localhost is not mapped, it's going to remove itself and fail the connection to the server. Should I map something in the hosts file? Some logs that will probably explain the situation: INFO org.mongodb.driver.connection - Opened connection [connectionId {localValue:1, serverValue:606}] to localhost:28888 , minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, roundTripTimeNanos=30898970, setName='datalyticsReplSet', canonicalAddress=mongo1.example.com:27017, hosts=[mongo1.example.com:27017, mongo3.example.com:27017, mongo2.example.com:27017], passives=[], arbiters=[], primary='mongo1.example.com:27017', tagSet=TagSet {[]}, electionId=7fffffff000000000000000f, setVersion=8} |
| Comments |
| Comment by Jeffrey Yemin [ 08/Jun/16 ] | ||||||
|
Hi Enrico, I've never tried this, but you might be able to do this if you put each replica set member on a different port, e.g., in your replica set configuration, use:
and in /etc/hosts:
and then set up port forwarding to mongo1.example.com:27017 on 127.0.0.1:27017, mongo2.example.com:27018 on 127.0.0.1:27018, and mongo3.example.com:27019 on 127.0.0.1:27019. Also, if you are willing to connect directly to a single known member of the set, you can do this by using one of the MongoClient constructors that takes a single ServerAddress instead of a List<ServerAddress>. These constructors make direct connections to servers and don't attempt any discovery of the other replica set members, which is what's getting you into trouble. Another option, of course, is to set up a VPN, but I assume that's not an option for you. |