Hướng dẫn connect replica set mongodb
Docs Home → MongoDB Manual Show This tutorial describes how to create a three-member replica set from three existing
To deploy a replica set with enabled access control, see Deploy Replica Set With Keyfile Authentication. If you wish to deploy a replica set from a single MongoDB instance, see Convert a Standalone to a Replica Set. For more information on replica set deployments, see the Replication and Replica Set Deployment Architectures documentation. Three member replica sets provide enough redundancy to survive most network partitions and other system failures. These sets also have sufficient capacity for many distributed read operations. Replica sets should always have an odd number of members. This ensures that elections will proceed smoothly. For more about designing replica sets, see the Replication overview. For production deployments, you should maintain as much
separation between members as possible by hosting the Before you can deploy a replica set, you must install MongoDB on each system that will be part of your replica set. If you have not already installed MongoDB, see the installation tutorials. In production, deploy
each member of the replica set to its own machine and if possible bind to the standard MongoDB port of See Replica Set Deployment Architectures for more information. ImportantTo avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members. Use hostnames instead of IP addresses to configure clusters across a split network horizon. Starting in MongoDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start. Use the Changed in version 3.6: WarningMongoDB binaries, WarningFor example, the following
In order to connect to this instance, remote clients must specify the hostname or its associated IP address
Ensure that network traffic can pass securely between all members of the set and all clients in the network . Consider the following:
Ensure that each member of a replica set is accessible by way of resolvable DNS or hostnames. You should either configure your DNS names appropriately or set up your systems' Each member must be able to connect to every other member. For instructions on how to check your connection, see Test Connections Between all Members. Create the directory where MongoDB stores data files before deploying MongoDB. Specify the For more information about configuration options, see Configuration File Options. The following procedure outlines the steps to deploy a replica set when access control is disabled. For each member, start a Set Set Set any other settings as appropriate for your deployment. In this tutorial, the three
Replica Set Member Hostname Member 0 Member 1 Member 2 The following example specifies the replica set name and the ip binding through the Warning
For Alternatively, you can also specify the
To start
In production deployments, you can configure a init script to manage this process. Init scripts are beyond the scope of this document. From the same machine where one of the
Depending on your path, you may need to specify the path to the If your From ImportantImportantTo avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members. Use hostnames instead of IP addresses to configure clusters across a split network horizon. Starting in MongoDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.
MongoDB initiates a replica set, using the default replica set configuration. Use
The replica set configuration object resembles the following:
Use
TipSee also: |