MongoDB复制集配置

配置文件

# vim /etc/mongod.conf
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)
posted @ 2017-09-12 16:20  胡成龙的博客  阅读(387)  评论(0编辑  收藏  举报