2015-12-07 16:51:06.0|分类: MongoDB|浏览量: 2045
This tutorial describes how to create a three-member replica set from three existing mongod instances running with access control disabled. To deploy a replica set with enabled access control, see Deploy Replica Set and Configure Authentication and Authorization. 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 andReplica Set Deployment Architectures documentation. OverviewThree 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. The basic procedure 程序is to start the mongod instances that will become members of the replica set, configure the replica set itself, and then add the mongod instances to it. 开启mongod进程,配置副本集,再把mongod进程增加到副本集 Requirements 要求For production deployments, you should maintain保持 as much separation 分离 between members as possible by hosting the mongod instances on separate machines. When using virtual machines for production deployments, you should place each mongod instance on a separate host server serviced by redundant power circuits and redundant network paths. Before you can deploy a replica set, you must install MongoDB on each system that will be part of yourreplica set. If you have not already installed MongoDB, see the installation tutorials. Before creating your replica set, you should verify that your network configuration allows all possible connections between each member. For a successful replica set deployment, every member must be able to connect to every other member. For instructions on how to check your connection, see Test Connections Between all Members. Considerations When Deploying a Replica SetArchitecture 架构In a production, deploy each member of the replica set to its own machine and if possible bind to the standard MongoDB port of 27017. Use the bind_ip option to ensure that MongoDB listens for connections from applications on configured addresses. For a geographically distributed replica sets, ensure that the majority of the set’s mongod instances reside in the primary site. See Replica Set Deployment Architectures for more information. Connectivity 连接Ensure that network traffic can pass between all members of the set and all clients in the network securely and efficiently. Consider the following:
Finally 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’ /etc/hosts file to reflect this configuration. Configuration 配置Specify the run time configuration on each system in a configuration file stored in /etc/mongod.conf or a related location. Create the directory where MongoDB stores data files before deploying MongoDB. For more information about the run time options used above and other configuration options, seeConfiguration File Options. ProcedureThe following procedure outlines the steps to deploy a replica set when access control is disabled. 1 Start each member of the replica set with the appropriate options.For each member, start a mongod and specify the replica set name through the replSet option. Specify any other parameters specific to your deployment. For replication-specific parameters, seeReplication Options. If your application connects to more than one replica set, each set should have a distinct name. Some drivers group replica set connections by replica set name. The following example specifies the replica set name through the --replSet command-line option: 指定副本集名称 mongod --replSet "rs0" 如果你使用debain系统,开启mongo命令是/etc/init.d/mongod start, 不能添加参数,这个参数怎么办啊??把这个参数在配置文件/etc/mongod.conf中配置 You can also specify the replica set name in the configuration file. To start mongod with a configuration file, specify the file with the --config option: 你也可以在配置文件中指定副本集名称 mongod --config $HOME/.mongodb/config In production deployments, you can configure a control script to manage this process. Control scripts are beyond the scope of this document. 2 Connect a mongo shell to a replica set member.For example, to connect to a mongod running on localhost on the default port of 27017, simply issue: mongo 3 Initiate the replica set.Use rs.initiate() on the replica set member: rs.initiate() MongoDB initiates a set that consists of the current member and that uses the default replica set configuration. 4 Verify the initial replica set configuration.Use rs.conf() to display显示 the replica set configuration object: rs.conf() The replica set configuration object resembles the following: { "_id" : "rs0", "version" : 1, "members" : [ { "_id" : 1, "host" : "mongodb0.example.net:27017" } ]} 5 Add the remaining members to the replica set.增加其余成员Add the remaining members with the rs.add() method. The following example adds two members: rs.add("mongodb1.example.net")rs.add("mongodb2.example.net") When complete, you have a fully functional replica set. The new replica set will elect a primary. 6 Check the status of the replica set.Use the rs.status() operation: rs.status() |