I want to use MongoDB in replica-set mode over 2 servers by IPs.But when I deployed the secondary one on other server, I faced the issues about connecting between 2 instance. For example, the primary located on server 192.168.1.1:27018 with hostname COM1 and the second located on server 192.168.1.2:27018 with hostname COM2. Despite of configuring like this
net:
bindIp: 0.0.0.0, COM1|192.168.1.1, COM2|192.168.1.2
port: 27018
But in MongoDB's log, it responses that cant hear from COM1:27018 or can find COM2:27018, I don't know how to map these addresses with these IPs. Please help me, thanks!
Best Answer
From your primary machine run the following command
You should be able to connect to the MongoDB running in the secondary node using the above command. If it fails to connect, check the following configuration settings
bindIp
settings of the secondary node configuration file, it should allow connection from192.168.1.1:27018
.27018
is accepting inbound connections in the secondary node. If not add an entry in IP Table.Follow the same for Primary node as well and try to connect to each machine from other machine using the first command. If everything working fine you should be able to set up your replica set.