windows下MongoDB4.0的副本集搭建

复制三个MongoDB Server,一个为主节点Primary ,一个为辅节点Secondary,另一个为仲裁节点Arbiter

以无认证方式启动三个Server节点

server1> mongod --noauth --config mongod.cfg   
server2> mongod --noauth --config mongod.cfg   
server3> mongod --noauth --config mongod.cfg   

//server1   mongod.cfg
net:
  port: 27017
  bindIp: 0.0.0.0
replication:
  oplogSizeMB: 200
  replSetName: replset

//server2   mongod.cfg
net:
  port: 27018
  bindIp: 0.0.0.0
replication:
  oplogSizeMB: 200
  replSetName: replset

//server3   mongod.cfg
net:
  port: 27019
  bindIp: 0.0.0.0
replication:
  oplogSizeMB: 200
  replSetName: replset

连接server1

> mongo
> rs.initiate();   //初始化副本集设置
> rs.add('mg.imily.net:27018');    //添加server2
> rs.addArb('mg.imily.net:27019');    //添加server3
> cfg = rs.conf();
> cfg.members[0].priority = 100;   //设置server1优先级
> cfg.members[1].priority = 50;    //设置server2优先级
> rs.reconfig(cfg);   //重新配置副本集信息

按照上一篇方式创建帐号密码后,接着需要创建节点之间的认证keyfile,用来在各节点之间的认证。

> openssl.exe rand 128 -base64 -out ./keyfile
//附下载: openssl.zip

//创建后复制到server1,server2,server3的bin目录中,并在三个mongod.cfg中添加
security:
  authorization: enabled
  keyFile: keyfile

最后添加server1,server2,server3作为系统服务,启动即可

显示更多

发表回复