On the arbiter connection: I NETWORK Successfully connected to mongodb-servers-vm-1:27017 (1 connections now open to mongodb-servers-vm-1:27017 with a 5 second timeout) W NETWORK No primary detected for set rs0. Now, lets restart mongod service on the primary node sudo service mongod restart Here, the instance mongodb-servers-vm-0 is primary and mongodb-servers-vm-1 is secondary. Fail Over Demoįirst, we connect to the replica set from arbiter node mongo "mongodb://mongodb-servers-vm-0,mongodb-servers-vm-1/myDB?replicaSet=rs0" MongoDB shell version v3.4.14 connecting to: mongodb://mongodb-servers-vm-0,mongodb-servers-vm-1/myDB?replicaSet=rs0 I NETWORK Starting new replica set monitor for rs0/mongodb-servers-vm-0:27017,mongodb-servers-vm-1:27017 I NETWORK Successfully connected to mongodb-servers-vm-1:27017 (1 connections now open to mongodb-servers-vm-1:27017 with a 5 second timeout) I NETWORK Successfully connected to mongodb-servers-vm-0:27017 (1 connections now open to mongodb-servers-vm-0:27017 with a 5 second timeout) rs0:PRIMARY> This way, we get connected to the primary replica/node at first and in case of fail over, the arbiter node chooses another node as primary and the connection is established to new primary. rs0:SECONDARY>Īs we have primary and secondary replicas running, to establish mongodb connection with the replica set rather than each one, enter this command on any of the node: mongo “mongodb://mongodb-servers-vm-0,mongodb-servers-vm-1/myDB?replicaSet=rs0” On secondary: mongo MongoDB shell version v3.4.14. On primary node: mongo MongoDB shell version v3.4.14 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.14. On arbiter node: mongo MongoDB shell version v3.4.14connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.4.1 Also, SSHing into google cloud instances is easy with gcloud sdk: gcloud compute ssh -zone -project There are different ways of connecting to the mongodb replica set:Ĭonnecting to each node: On the Compute Instances page on console, hit the SSH button and new window opens with ssh connection. Also, by selecting External IP option None, we can hide the nodes from outside the specific subnet. The data on those disk are synced with each other. Now, within few minutes, the clusters are up not only with the number of replicas specified and arbiter but also with a separate disks for each node which has naming standard of mongodb-servers-vm-0-data that are attached to respective instance. Grab details about the performance difference from official optimization guide.
Its recommended to choose SSD for the data storage which has high IOPS & throughput. Also, choose a arbiter node which can be a small instance as it is utilized just for choosing the primary replica by voting.
Choose the number of nodes among which one will be primary replica and rest secondaries. Configure deployment, replica set name and disk type on the console.