MongoDB replica sets搭建及使用
由于机器紧张,没办法搞分片(sharding),而只是用了复制集这个功能,一下介绍下自己这几天的实验。
环境:
目录结构
mongo_data
|--conf
|--config.js
|--rs0.cnf
|--rs1.cnf
|--rs2.cnf
|--data
|--r0
|--r1
|--r2
|--key
|--r0
|--r1
|--r2
|--log
|--r0.log
|--r1.log
|--r2.log
|--run
|--run_config.sh
|--run_rs0.sh
|--run_rs1.sh
|--run_rs2.sh
举几个文件,其他类似:
rs0.cnf:
- replSet=rs1
- keyFile=/home/madding/output/mongodb/replica_set/key/r0
- dbpath=/home/madding/output/mongodb/replica_set/data/r0
- logpath=/home/madding/output/mongodb/replica_set/log/r0.log
- port=10240
config.js:
- var config_rs1={
- _id:'rs1',
- members:[
- {_id:0, host:'127.0.0.1:10240', priority:1},
- {_id:1, host:'127.0.0.1:11240'},
- {_id:2, host:'127.0.0.1:12240'}]
- }
- rs.initiate(config_rs1);
- rs.slaveOk();
- printjson('status info:');
- printjson(rs.status());
- printjson('result info: ');
- printjson(rs.isMaster());
r0:
- ANKDIUOJHKJDLKFJHDOUDOJFKLDJ
随便复杂,保证r0,r1,r2一致即可
run_config.sh:
- !/bin/bash
- MONGODB_HOME=/usr/mytools/mongodb
- $MONGODB_HOME/bin/mongo ../conf/config.js --port 10240 --quiet
- exit
run_rs0.sh:
- #!/bin/bash
- MONGODB_HOME=/usr/mytools/mongodb
- $MONGODB_HOME/bin/mongod -f ../conf/rs0.cnf --logappend --fork
- exit
相关推荐
大秦铁骑 2020-08-19
thatway 2020-08-19
lovecodeblog 2020-08-19
lbyd0 2020-11-17
BigYellow 2020-11-16
sushuanglei 2020-11-12
我心似明月 2020-11-09
zhushenghan 2020-11-09
sunnnyduan 2020-10-16
不要皱眉 2020-10-14
xiaohai 2020-09-29
songxiugongwang 2020-09-22
萌亖 2020-09-17
LuckyLXG 2020-09-08
sdmzhu 2020-09-01
mkhhxxttxs 2020-09-16
xiaohai 2020-09-16
newcome 2020-09-09