Mongodb主从配置
一、 官网下载
1. 下载
官网下载https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.5.tgz
tar zxvf mongodb-linux-x86_64-2.6.5.tgz
2. 主从和仲裁节点配置文件
注:配置文件中的目录要先建立
1.master.conf
dbpath=../../mongodb/data/master
logpath=../../mongodb/log/master.log
pidfilepath=/export/grid/01/xiale/soft/mongodb/master.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=hostname
port=27017
oplogSize=10000
fork=true
noprealloc=true
2.slave.conf
#slaver.conf
dbpath=../../mongodb/data/slaver
logpath=../../mongodb/log/slaver.log
pidfilepath=/export/grid/01/xiale/soft/mongodb/slaver.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=hostname
port=27017
oplogSize=10000
fork=true
noprealloc=true
3. arbiter.conf
#arbiter.conf
dbpath=../../mongodb/data/arbiter
logpath=../../mongodb/log/arbiter.log
pidfilepath=/export/grid/01/xiale/soft/mongodb/arbiter.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=hostname
port=27017
oplogSize=10000
fork=true
noprealloc=true
3. 启动三台机器
./monood -f master.conf
./mongod -f slaver.conf
./mongod -f arbiter.conf
4. 配置主、备、仲裁节点
./mongo masterip:27017 #ip和port是某个节点的地址
>use admin
>cfg={ _id:"testrs", members:[{_id:0,host:'masterIP:27017',priority:2}, {_id:1,host:'slaveIP:27017',priority:1},
{_id:2,host:'arbiterIP:27017',arbiterOnly:true}]};
>rs.initiate(cfg) #使配置生效
rs.status()可以查看状态