You need know the IP or hostname of the Mongo database which should be acted as a master, and you can ping the port 27017 from the mongo database which should be acted as a slave.
Here are some commands might be helpful:
- To know the external IP of the server:
- To ping the server which you want to connect, on the specific port ( for example: 27017 ):
Machine A (Master): Run Mongo Daemon as master:
Machine B (Slave): If mongod is running, which is the default behavior when installed, you should stop it before the following steps:
Run Mongo Daemon as slave:
Probably you need to specify the dbpath, in case you have any disk space limitation:
mongo to open a mongo shell, then config for replication:
1 2 3
Then you run
show dbs in the mongo shell:
You will find the databasename which we typed behind the
only key above displayed.
You may need to run the command multiple times to make sure the replication is going on. For example:
1 2 3 4 5
You can also run the following commands to show the information of the replication on master and slave side:
1 2 3 4 5
Besides, you can run the following command to get a defail status of the server:
You might neet to run resync to recover replication:
Written with StackEdit.