Read-Write Configuration of mongodb Master-Slave Server

  mongodb, question

I am very happy to be on the Sibu website for the first time. I am not talented. I encountered a small problem when learning mongodb to configure the master server and the slave server today. That is, when I set the ip and port of the master server and the slave server, the login master server 192.168.1.102:27017 and the slave server 192.168.1.102

Because it is the master server that cannot achieve the effect of master and slave, I hope the big brothers can give me some advice. ! ! Thank you very much.

The steps for setting up the master-slave server are as follows:
Environment: mac Version //MongoDB version: “3.4.2

  1. Creating Database Directories db1, db2
    Create two directory paths of /Users/gavin/Desktop to suspend two mongodb servers

mkdir db1
mkdir db2
2. Suspend 2 servers respectively
mongod –bind_ip 192.168.1.102 –port 27017 –dbpath /Users/gavin/Desktop/db1 –replSet rs0
mongod –bind_ip 192.168.1.102 –port 27018 –dbpath /Users/gavin/Desktop/db2 –replSet rs0

3. Connect to the main server, and set 192.168.1.102:27017 as the main server here

mongo –host 192.168.1.102 –port 27017
rs.initiate()

4. Add replica set
rs.add(‘192.168.1.102:27018’)
5. View the configuration status rs.status ():
clipboard.png
The configuration seems to be no problem.

The link from the server is as follows:
图片描述

There is a problem with the connection method, it is better to use Mongo-Host 192.168.1.102-Port 27017 without knowing it. Embarrassment