配置文件
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
security:
keyFile: /var/lib/mongodb/mongodb-keyfile
replication:
replSetName: rs0
在主节点初始化复制集配置
rs.initiate( {
_id : "rs0",
members: [ { _id : 0, host : "ubuntu-mongodb-node1:27017" } ]
})
在主节点上添加从节点
rs.add("ubuntu-mongodb-node2:27017")
rs.add("ubuntu-mongodb-node3:27017")
修改节点的优先级,设置为0则不会被选为主
cfg = rs.conf()
cfg.members[2].priority = 0
rs.reconfig(cfg)