"MongoDB" under Windows to establish a dual-machine master-Slave

Source: Internet
Author: User
Tags mongodb version mongo shell

"Dual-machine configuration"

Service side:

Two Dell R730 dual E5 servers

Use an intranet environment, network segment, ping test interoperability

Main service ip:192.168.20.176:27017

From service ip:192.168.20.178:27015

Client: ThinkPad t460p

"System Environment"

Service side: Windows Server R2

Client: Win10

MongoDB version 3.2.10

"Folder Creation"

Dual-machine master and slave configuration is recommended to keep the folder configuration of the two machines consistent, but for MONGODB configuration This can be less attention.

It took 5 minutes to learn and found that it was a given time to request synchronization from the machine to the host. The internal mechanism of synchronization, such as empty a little research source.

Here my folder is established as D:\Mongos\ as the entire MongoDB root directory, the data directory is also placed here temporarily.

Data Catalog:. \db\ the data for the main service is placed in this folder. \master, the data from the service corresponds to the. \slave

The logs are under. \log\

"Script and Run Effects"

MongoDB configuration script is very simple, here is the command to

First come to the main clothing, be sure to use--master to mark.

27017

From service:

192.168. 20.176 27015 5

Where slavedelay specifies how many seconds to perform synchronization from the service.

Run effect

Main service:

Startup success

It is necessary to state that the bottom piece of information is a connection to the main service since the start of the service, so there is a connection accepted.

Next comes the service from:

You can see that the information in the bottom group of red boxes appears every 5s, representing the information that is synchronizing the main service.

"Starting the primary and standby service"

Run Mongo.exe on the main suit and automatically connect to test, which is the same as a single machine.

Waited for a long time, did not see MONGO Shell appeared, indicating that the boot did not succeed.

It is said that the first start is slow, do not know how slow

Wait a long time, suddenly good.

Before a few clients are unable to access, next test for what reason.

Start Mongo.exe from the same service, but specify the port from the service, which is 27015

This is to test if the synchronization is successful, so access the local test.

"Sync Test"

The party that writes the data operates from the client (ThinkPad) and then reads the synchronization on two server clients at a time.
To facilitate the distinction, read once from the service, and then read it again after a write operation, 5s.

The client's write operation is performed on the main service.

The insert operation is simple, and we can "send the command by the client" under test.

You can see that the query results are correct.

We execute the FIND () command from the service:

You can see that it was an error before.

In fact, slave mode is not allowed to be accessed and manipulated directly from the server. But we can configure a read permission for slave service, i.e. Rs.slaveok ()

Then you can check it out. Two records because I'm driving under the main suit. The client also executes a query.

This proves that the master-slave deployment is successful.

"Waiting to be solved"

Finally, there are some problems:

Officially, I should be able to access the slave from the client (another PC) by specifying the IP and port, since it is also so accessed from the service itself.

However, my connection request was rejected from the service, a bit strange.

"MongoDB" under Windows to establish a dual-machine master-Slave

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.