mongodb 副本集创建
vi install_mongo.sh
tar -zxvf mongodb-linux-x86_64-rhel62-3.2.9.tgz
mv mongodb-linux-x86_64-rhel62-3.2.9 /usr/local/mongo
cat>>/etc/profile<<EOF
export PATH=/usr/local/mongo/bin:$PATH
EOF
source /etc/profile
mongotest1
vi start27017.sh
mkdir /opt/mongo1_1
cat >>/etc/mongo_27017.conf<<EOF
port=27017
fork=true
storageEngine=wiredTiger
dbpath=/opt/mongo1_1
logpath=/opt/mongo1_1/mongo.log
wiredTigerDirectoryForIndexes=true
wiredTigerCacheSizeGB=0.3
logappend=true
replSet=rs1
oplogSize=100
EOF
mongod -f /etc/mongo_27017.conf
[root@mongotest3 etc]# cat mongo_2701
mongo_27017.conf mongo_27018.conf
[root@mongotest3 etc]# cat mongo_27018.conf
port=27018
fork=true
storageEngine=mmapv1
dbpath=/opt/mongo1_2
logpath=/opt/mongo1_2/mongo.log
replSet=rs1
logappend=true
oplogSize=100
cfg = { _id: "rs1", members:[
{ _id : 0, host : "192.168.0.109:27017"},
{ _id : 1, host : "192.168.0.110:27017"},
{ _id : 2, host : "192.168.0.111:27017"} ]
};
rs.initiate(cfg);
use online
db.test1.insert({name:'aaa'})
db.test1.find()
添加节点
rs.add('192.168.0.111:27018')
[root@mongotest3 opt]# mongo --port 27018
rs1:SECONDARY> use admin
switched to db admin
rs1:SECONDARY> use online
switched to db online
rs1:SECONDARY> rs.slaveOk()
rs1:SECONDARY> db.test1.find()
{ "_id" : ObjectId("57e943faff931e363a5a0309"), "name" : "aaa" }
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341