Prerequisites:
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:
1
|
|
- To ping the server which you want to connect, on the specific port ( for example: 27017 ):
1
|
|
Practices:
Machine A (Master): Run Mongo Daemon as master:
1
|
|
Machine B (Slave): If mongod is running, which is the default behavior when installed, you should stop it before the following steps:
1 2 |
|
Run Mongo Daemon as slave:
1
|
|
Probably you need to specify the dbpath, in case you have any disk space limitation:
1
|
|
Run mongo
to open a mongo shell, then config for replication:
1 2 3 |
|
Then you run show dbs
in the mongo shell:
1
|
|
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:
1
|
|
You might neet to run resync to recover replication:
1 2 |
|
References:
Written with StackEdit.