mongodb集群搭建

创建yum源

vim /etc/yum.repos.d/mongodb-org-3.2.repo

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

安装

yum install mongodb-org -y

修改mongo配置

vim /etc/mongo.conf

初始化集群

use admin
config={_id:"mgcluster",members:[{_id:0,host:"192.168.10.57:27017"}]}
rs.initiate(config);

添加节点(, priority:90为权重)

rs.add({_id:2, host:"192.168.10.58:27017", priority:90})

调整优先级

cfg = rs.conf()
cfg.members[1].priority = 85
rs.reconfig(cfg)

 

备份mongo(同时备份期间的oplog)
mongodump -h 192.168.10.3 --port 27017 --oplog -o /var/data/

恢复mongo(同时回放oplog)
mongorestore -h 127.0.0.1 --authenticationDatabase admin --oplogReplay /var/data

单独备份oplog
mongodump -h 192.168.10.3 -d local -c oplog.rs --oplog -o /var/data/

单独恢复oplog
cp local/oplog.rs.bson22.232 /var/data/oplog.bson
cp local/*23.01 /var/data/local/
mongorestore -h 127.0.0.1 --authenticationDatabase admin --oplogReplay /var/data

你可能感兴趣的:(mongodb集群搭建)