如何配置 mongodb 删除副本集副本集

$&cat&/etc/redhat-release&
CentOS&Linux&release&7.0.1406&(Core)&
$&uname&-a
Linux&zhaopin-2-201&3.10.0-123.el7.x86_64&#1&SMP&Mon&Jun&30&12:09:22&UTC&&x86_64&x86_64&GNU/Linux
$&mongo&--version
MongoDB&shell&version:&3.0.6
1.创建目录
$&sudo&mkdir&-p&/data/mongodb/{data/db0,backup/db0,log/db0,conf/db0}
2.编写配置文件
[wenhang.pan@zhaopin-2-201&~]$&sudo&vim&/data/mongodb/conf/db0/mongodb.conf
port&=&27017
maxConns&=&800&
filePermissions&=&0700
fork&=&true
noauth&=&true
dbpath&=&/data/mongodb/data/db0
pidfilepath&=&/data/mongodb/data/db0/mongodb.pid
journal&=&true
#&security
nohttpinterface&=&true
rest&=&false
logpath&=&/data/mongodb/log/db0/mongodb.log
logRotate&=&rename
logappend&=&true
slowms&=&50
replSet&=&rs0
三、配置副本集
1.配置primary
$&sudo&/opt/mongodb/bin/mongod&--config&/data/mongodb/conf/db0/mongodb.conf&&
about&to&fork&child&process,&waiting&until&server&is&ready&for&connections.
forked&process:&48583
child&process&started&successfully,&parent&exiting
[wenhang.pan@zhaopin-2-201&~]$&mongo
MongoDB&shell&version:&3.0.6
connecting&to:&test
&&rs.status();
&&&&&&&&"info"&:&"run&rs.initiate(...)&if&not&yet&done&for&the&set",
&&&&&&&&"ok"&:&0,
&&&&&&&&"errmsg"&:&"no&replset&config&has&been&received",
&&&&&&&&"code"&:&94
&&cfg={_id:"rs0",&members:[&{_id:0,host:"172.30.2.201:27017"}]&}
&&&&&&&&"_id"&:&"rs0",
&&&&&&&&"members"&:&[
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&&&&&"_id"&:&0,
&&&&&&&&&&&&&&&&&&&&&&&&"host"&:&"172.30.2.201:27017"
&&&&&&&&&&&&&&&&}
&&rs.initiate(&cfg&);
{&"ok"&:&1&}
rs0:OTHER&&rs.status();
&&&&&&&&"set"&:&"rs0",
&&&&&&&&"date"&:&ISODate("T08:31:36.354Z"),
&&&&&&&&"myState"&:&1,
&&&&&&&&"members"&:&[
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&&&&&"_id"&:&0,
&&&&&&&&&&&&&&&&&&&&&&&&"name"&:&"172.30.2.201:27017",
&&&&&&&&&&&&&&&&&&&&&&&&"health"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"state"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"stateStr"&:&"PRIMARY",
&&&&&&&&&&&&&&&&&&&&&&&&"uptime"&:&112,
&&&&&&&&&&&&&&&&&&&&&&&&"optime"&:&Timestamp(,&1),
&&&&&&&&&&&&&&&&&&&&&&&&"optimeDate"&:&ISODate("T08:31:31Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"electionTime"&:&Timestamp(,&2),
&&&&&&&&&&&&&&&&&&&&&&&&"electionDate"&:&ISODate("T08:31:31Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"configVersion"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"self"&:&true
&&&&&&&&&&&&&&&&}
&&&&&&&&],
&&&&&&&&"ok"&:&1
2.添加节点
1)启动新的节点
$&sudo&/opt/mongodb/bin/mongod&--config&/data/mongodb/conf/db0/mongodb.conf
about&to&fork&child&process,&waiting&until&server&is&ready&for&connections.
forked&process:&41794
child&process&started&successfully,&parent&exiting
$&sudo&/opt/mongodb/bin/mongod&--config&/data/mongodb/conf/db0/mongodb.conf
about&to&fork&child&process,&waiting&until&server&is&ready&for&connections.
forked&process:&3761
child&process&started&successfully,&parent&exiting
2)添加新的节点
在primary上执行:
rs0:PRIMARY&&rs.add(&"172.30.2.202:27017"&);
{&"ok"&:&1&}
rs0:PRIMARY&&rs.status();
&&&&&&&&"set"&:&"rs0",
&&&&&&&&"date"&:&ISODate("T08:34:48.161Z"),
&&&&&&&&"myState"&:&1,
&&&&&&&&"members"&:&[
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&&&&&"_id"&:&0,
&&&&&&&&&&&&&&&&&&&&&&&&"name"&:&"172.30.2.201:27017",
&&&&&&&&&&&&&&&&&&&&&&&&"health"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"state"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"stateStr"&:&"PRIMARY",
&&&&&&&&&&&&&&&&&&&&&&&&"uptime"&:&304,
&&&&&&&&&&&&&&&&&&&&&&&&"optime"&:&Timestamp(,&1),
&&&&&&&&&&&&&&&&&&&&&&&&"optimeDate"&:&ISODate("T08:34:20Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"electionTime"&:&Timestamp(,&2),
&&&&&&&&&&&&&&&&&&&&&&&&"electionDate"&:&ISODate("T08:31:31Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"configVersion"&:&2,
&&&&&&&&&&&&&&&&&&&&&&&&"self"&:&true
&&&&&&&&&&&&&&&&},
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&&&&&"_id"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"name"&:&"172.30.2.202:27017",
&&&&&&&&&&&&&&&&&&&&&&&&"health"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"state"&:&2,
&&&&&&&&&&&&&&&&&&&&&&&&"stateStr"&:&"SECONDARY",
&&&&&&&&&&&&&&&&&&&&&&&&"uptime"&:&27,
&&&&&&&&&&&&&&&&&&&&&&&&"optime"&:&Timestamp(,&1),
&&&&&&&&&&&&&&&&&&&&&&&&"optimeDate"&:&ISODate("T08:34:20Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"lastHeartbeat"&:&ISODate("T08:34:46.884Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"lastHeartbeatRecv"&:&ISODate("T08:34:46.896Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"pingMs"&:&0,
&&&&&&&&&&&&&&&&&&&&&&&&"configVersion"&:&2
&&&&&&&&&&&&&&&&}
&&&&&&&&],
&&&&&&&&"ok"&:&1
rs0:PRIMARY&&rs.add(&"172.30.2.203:27017"&);
{&"ok"&:&1&}
rs0:PRIMARY&&rs.status();
&&&&&&&&"set"&:&"rs0",
&&&&&&&&"date"&:&ISODate("T08:36:22.579Z"),
&&&&&&&&"myState"&:&1,
&&&&&&&&"members"&:&[
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&&&&&"_id"&:&0,
&&&&&&&&&&&&&&&&&&&&&&&&"name"&:&"172.30.2.201:27017",
&&&&&&&&&&&&&&&&&&&&&&&&"health"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"state"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"stateStr"&:&"PRIMARY",
&&&&&&&&&&&&&&&&&&&&&&&&"uptime"&:&398,
&&&&&&&&&&&&&&&&&&&&&&&&"optime"&:&Timestamp(,&1),
&&&&&&&&&&&&&&&&&&&&&&&&"optimeDate"&:&ISODate("T08:35:58Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"electionTime"&:&Timestamp(,&2),
&&&&&&&&&&&&&&&&&&&&&&&&"electionDate"&:&ISODate("T08:31:31Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"configVersion"&:&3,
&&&&&&&&&&&&&&&&&&&&&&&&"self"&:&true
&&&&&&&&&&&&&&&&},
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&&&&&"_id"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"name"&:&"172.30.2.202:27017",
&&&&&&&&&&&&&&&&&&&&&&&&"health"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"state"&:&2,
&&&&&&&&&&&&&&&&&&&&&&&&"stateStr"&:&"SECONDARY",
&&&&&&&&&&&&&&&&&&&&&&&&"uptime"&:&121,
&&&&&&&&&&&&&&&&&&&&&&&&"optime"&:&Timestamp(,&1),
&&&&&&&&&&&&&&&&&&&&&&&&"optimeDate"&:&ISODate("T08:35:58Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"lastHeartbeat"&:&ISODate("T08:36:22.268Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"lastHeartbeatRecv"&:&ISODate("T08:36:20.949Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"pingMs"&:&0,
&&&&&&&&&&&&&&&&&&&&&&&&"syncingTo"&:&"172.30.2.201:27017",
&&&&&&&&&&&&&&&&&&&&&&&&"configVersion"&:&3
&&&&&&&&&&&&&&&&},
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&&&&&"_id"&:&2,
&&&&&&&&&&&&&&&&&&&&&&&&"name"&:&"172.30.2.203:27017",
&&&&&&&&&&&&&&&&&&&&&&&&"health"&:&1,
&&&&&&&&&&&&&&&&&&&&&&&&"state"&:&2,
&&&&&&&&&&&&&&&&&&&&&&&&"stateStr"&:&"SECONDARY",
&&&&&&&&&&&&&&&&&&&&&&&&"uptime"&:&24,
&&&&&&&&&&&&&&&&&&&&&&&&"optime"&:&Timestamp(,&1),
&&&&&&&&&&&&&&&&&&&&&&&&"optimeDate"&:&ISODate("T08:35:58Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"lastHeartbeat"&:&ISODate("T08:36:22.267Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"lastHeartbeatRecv"&:&ISODate("T08:36:22.275Z"),
&&&&&&&&&&&&&&&&&&&&&&&&"pingMs"&:&0,
&&&&&&&&&&&&&&&&&&&&&&&&"configVersion"&:&3
&&&&&&&&&&&&&&&&}
&&&&&&&&],
&&&&&&&&"ok"&:&1
1.数据同步
1) primary:
MongoDB&shell&version:&3.0.6
connecting&to:&test
rs0:PRIMARY&&use&
switched&to&db&aaa
rs0:PRIMARY&&db.createCollection(&"test"&);
{&"ok"&:&1&}
rs0:PRIMARY&&show&
system.indexes
2) secondary:
MongoDB&shell&version:&3.0.6
connecting&to:&test
rs0:SECONDARY&&rs.slaveOk();
rs0:SECONDARY&&use&
switched&to&db&aaa
rs0:SECONDARY&&show&
system.indexes
[wenhang.pan@zhaopin-2-203&~]$&mongo
MongoDB&shell&version:&3.0.6
connecting&to:&test
rs0:SECONDARY&&rs.slaveOk();
rs0:SECONDARY&&use&
switched&to&db&aaa
rs0:SECONDARY&&show&
system.indexes
2.读写验证
由上可知,primary是可读写的
在secondary上写测试:
MongoDB&shell&version:&3.0.6
connecting&to:&test
switched&to&db&aaa
&&db.createCollection("test2");
{&"note"&:&"from&execCommand",&"ok"&:&0,&"errmsg"&:&"not&master"&}
T15:57:49.240+0800&E&QUERY&&&&Error:&listCollections&failed:&{&"note"&:&"from&execCommand",&"ok"&:&0,&"errmsg"&:&"not&master"&}
&&&&at&Error&(&anonymous&)
&&&&at&DB._getCollectionInfosCommand&(src/mongo/shell/db.js:646:15)
&&&&at&DB.getCollectionInfos&(src/mongo/shell/db.js:658:20)
&&&&at&DB.getCollectionNames&(src/mongo/shell/db.js:669:17)
&&&&at&shellHelper.show&(src/mongo/shell/utils.js:625:12)
&&&&at&shellHelper&(src/mongo/shell/utils.js:524:36)
&&&&at&(shellhelp2):1:1&at&src/mongo/shell/db.js:646
&&rs.slaveOk();
system.indexes
证明secondary节点是不能写,默认也是不可读的,需要执行rs.slaveOk();或者db.getMongo().setSlaveOk();并且只对当前session有效,所以每次连接从库都需要执行。
mongodb的副本集至少需要3台以上才能实现高可用,并且节点的个数最好是基数。
阅读排行榜&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!mongodb分片与副本集详细配置方案_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
mongodb分片与副本集详细配置方案
上传于||文档简介
&&该​文​档​详​细​讲​述​了​对​三​个​服​务​器​的​m​o​n​g​o​d​b​进​行​副​本​集​与​分​片​的​部​署​和​测​试​方​案​。​对​初​学​m​o​n​g​o​d​b​集​群​的​有​所​帮​助​。
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩4页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&

我要回帖

更多关于 mongodb 副本集 分片 的文章

 

随机推荐