首页 > 代码库 > mongodb replica set搭建

mongodb replica set搭建

1/安装mongodb

配置repo:

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

 

然后yum install mongodb-org -y

 

配置/etc/mongod.conf:

net:
port: 27017
bindIp: 192.168.88.5

replication:
replSetName: teststrs

 

然后service mongod start;

 

mongo ip:port,执行:

cfg={ _id:"teststrs", members:[ {_id:0,host:‘192.168.88.4:27017‘,priority:1},
{ _id:1,host:‘192.168.88.4:27018‘,priority:2},
{_id:2,host:‘192.168.88.5:27017‘,priority:3},
{_id:3,host:‘192.168.88.5:27018‘,priority:4},

{_id:4,host:‘192.168.88.5:27019‘,priority:5}] };


rs.initiate(cfg)

rs.status()

rs.conf()

 

注意:replica set当集群中down掉的主机数量大于集群的一半时,将无法选举,此时只可以手工干预选举:

rs.reconfig(cfg,{force: true})

 

mongodb replica set搭建