本文演示:(一个主服务器,一个备份服务器,三个仲裁服务器)
官方推荐副本集的成员数量为奇数,最多12个副本集节点,最多7个节点参与选举。
本文演示基于本机,用端口区分服务(每个服务器下新建db文件夹用于存储数据,mongodb.conf文件配置启动参数)
各个服务器配置文件内容如下:
27000主服务器
dbpath=D:\MongoDB\Server27000\3.2\db
port=27000
replSet=datamip/127.0.0.1:27001
//副本集下面有其他服务器27001
27001备份服务器
dbpath=D:\MongoDB\Server27001\3.2\db
port=27001
replSet=datamip/127.0.0.1:27000
//主服务器
27002仲裁服务器
dbpath=D:\MongoDB\Server27002\3.2\db
port=27002
replSet=datamip/127.0.0.1:27001
//主服务器
27003仲裁服务器
dbpath=D:\MongoDB\Server27003\3.2\db
port=27003
replSet=datamip/127.0.0.1:27001
//主服务器
27004仲裁服务器
dbpath=D:\MongoDB\Server27004\3.2\db
port=27004
replSet=datamip/127.0.0.1:27001
//主服务器
27000主服务器27001备份服务器27002仲裁服务器27003仲裁服务器27004仲裁服务器创建服务sc.exe create MongoDB27000 binPath= “C:\MongoDB\Server27000\bin\mongod.exe –service –config=\”C:\MongoDB\Server27000\mongodb.conf”” DisplayName= “MongoDB27000” start= “auto”sc.exe create MongoDB27001 binPath= “C:\MongoDB\Server27001\bin\mongod.exe –service –config=\”C:\MongoDB\Server27001\mongodb.conf”” DisplayName= “MongoDB27001” start= “auto”sc.exe create MongoDB27002 binPath= “C:\MongoDB\Server27002\bin\mongod.exe –service –config=\”C:\MongoDB\Server27002\mongodb.conf”” DisplayName= “MongoDB27002” start= “auto”sc.exe create MongoDB27003 binPath= “C:\MongoDB\Server27003\bin\mongod.exe –service –config=\”C:\MongoDB\Server27003\mongodb.conf”” DisplayName= “MongoDB27003” start= “auto”sc.exe create MongoDB27004 binPath= “C:\MongoDB\Server27004\bin\mongod.exe –service –config=\”C:\MongoDB\Server27004\mongodb.conf”” DisplayName= “MongoDB27004” start= “auto”启动服务>mongo 192.168.200.111:27000/admin//连接primary>db.runCommand({“replSetInitiate”:{“_id”:”datamip”,”members”:[{“_id”:1,”host”:”192.168.200.111:27000″},{“_id”:2,”host”:”192.168.200.111:27001″}]}}) 稍等片刻,等待27000变为primary时添加如下配置>mongo 192.168.200.111:27000/admin>rs.addArb(“192.168.200.111:27002”)>rs.addArb(“192.168.200.11127003”)>rs.addArb(“192.168.200.111:27004”)