文档章节

mongodb副本集介绍、mongodb副本集搭建、 mongodb副本集测试

Linux_Anna
 Linux_Anna
发布于 2017/10/20 19:04
字数 3114
阅读 205
收藏 0

mongodb副本集介绍

  • MongoDB早期版本使用master-slave,一主一从和MySQL主从基本是一致的,但salve在此架构中为只读,当主库宕机后,从库不能自动切换为主.
  • 目前已经淘汰master-salve模式,改为副本集,副本集架构也是为了实现MongoDB的高可用,这种模式下有一个主(primary),和多个从(secondary)只读,支持他们设置权重,当主宕机后,权重最高的从切换为主.
  • 在此架构中还可以建立一个仲裁(arbiter)的角色,它只负责裁决,而不存储数据.
  • 在此架构中读写数据都是在主上,要想实现负载均衡的目的需要手动指定读库的目标server.

MongoDB副本集架构图

原理很简单一个primary,secondary至少是一个,也可以是多个secondary,除了多个secondary之外,还可以加一个Arbiter,Arbiter叫做仲裁,当Primary宕机后,Arbiter可以很准确的告知Primary宕掉了,但可能Primary认为自己没有宕掉,这样的话就会出现脑裂,为了防止脑裂就增加了Arbiter这个角色,尤其是数据库坚决不能出现脑裂的状态,脑裂会导致数据会紊乱,数据一旦紊乱恢复就非常麻烦.

 

变迁图

说明:Primary宕机后,其中secondary就成为一个新的Primary,另外一个secondary依然是secondary的角色. 对于MySQL主从来讲,即使做一主多从,万一master宕机后,可以让从成为新的主,但这过程是需要手动的更改的. 但是在MongoDB副本集架构当中呢,它完全都是自动的,rimary宕机后,其中secondary就成为一个新的Primary,另外一个secondary可以自动识别新的primary.

 

mongodb副本集搭建

准备三台机器: 192.168.2.115 (primary)
                      192.168.2.116 (secondary)                    
                      192.168.2.117 (secondary)
三台机器都需要安装MongoDB,primary已安装过,两台secondary需要安装,因步骤一样,在此不做演示.

编辑三台机器的配置文件

Primary机器:
[root@root-01 ~]# vim /etc/mongod.conf

net:
  port: 27017
  bindIp: 127.0.0.1,192.168.2.115 # Listen to local interface only, comment to listen on all interfaces.

说明:做副本集bindIp 要监听本机IP和内网IP


#replication:    //把#去掉,并增两行

replication:
  oplogSizeMB: 20            
  replSetName: annalinux      //定义副本集的名字


重启MongoDB服务:
[root@root-01 ~]# systemctl restart mongod
[root@root-01 ~]# ps aux |grep mongod
mongod    39020  7.3  4.8 1016828 48880 ?       Sl   17:18   0:00 /usr/bin/mongod -f /etc/mongod.conf
root      39050  0.0  0.0 112664   964 pts/0    S+   17:19   0:00 grep --color=auto mongod


Secondary1机器:
[root@root-02 ~]# vim /etc/mongod.conf

net:
  port: 27017
  bindIp: 127.0.0.1,192.168.2.116 # Listen to local interface only, comment to listen on all interfaces.

说明:做副本集bindIp 要监听本机IP和内网IP


#replication:    //把#去掉,并增两行

replication:
  oplogSizeMB: 20            
  replSetName: annalinux      //定义副本集的名字


重启MongoDB服务:
[root@root-02 ~]# systemctl restart mongod
[root@root-02 ~]# ps aux |grep mongod
mongod     2303  2.2  4.6 1016336 46404 ?       Sl   17:28   0:00 /usr/bin/mongod -f /etc/mongod.conf
root       2331  0.0  0.0 112664   968 pts/0    S+   17:28   0:00 grep --color=auto mongod


Secondary2机器:

[root@root-03 ~]# vim /etc/mongod.conf

net:
  port: 27017
  bindIp: 127.0.0.1,192.168.2.117 # Listen to local interface only, comment to listen on all interfaces.

说明:做副本集bindIp 要监听本机IP和内网IP


#replication:    //把#去掉,并增两行

replication:
  oplogSizeMB: 20            
  replSetName: annalinux      //定义副本集的名字

重启MongoDB服务:
[root@root-03 ~]# systemctl restart mongod
[root@root-03 ~]# ps aux |grep mongod
mongod     2735  3.5  4.3 1016340 43932 ?       Sl   17:46   0:00 /usr/bin/mongod -f /etc/mongod.conf
root       2761  0.0  0.0 112664   968 pts/0    R+   17:47   0:00 grep --color=auto mongod



连接MongoDB --Primary机器

[root@root-01 ~]# mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9
Server has startup warnings: 
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] 
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] 
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] 
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] 
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-10-20T17:18:53.740+0800 I CONTROL  [initandlisten] 

配置副本集

说明:在哪台机器上执行这一步,那么哪台机器就会成为primary

> config={_id:"annalinux",members:[{_id:0,host:"192.168.2.115:27017"},{_id:1,host:"192.168.2.116:27017"},{_id:2,host:"192.168.2.117:27017"}]}
{
	"_id" : "annalinux",
	"members" : [
		{
			"_id" : 0,
			"host" : "192.168.2.115:27017"
		},
		{
			"_id" : 1,
			"host" : "192.168.2.116:27017"
		},
		{
			"_id" : 2,
			"host" : "192.168.2.117:27017"
		}
	]
}

config={_id:"annalinux" --> annalinux(副本集的名字)
members --> 指定成员

rs.initiate(config) -->初始化 

> rs.initiate(config)
{ "ok" : 1 }

rs.status() -->查看副本集状态

说明:可以看到192.168.2.115 显示:"stateStr" : "PRIMARY"
          192.168.2.116和192.168.2.117 分别显示: "stateStr" : "SECONDARY"

annalinux:SECONDARY> rs.status()
{
	"set" : "annalinux",
	"date" : ISODate("2017-10-20T10:02:15.484Z"),
	"myState" : 1,
	"term" : NumberLong(1),
	"heartbeatIntervalMillis" : NumberLong(2000),
	"optimes" : {
		"lastCommittedOpTime" : {
			"ts" : Timestamp(1508493732, 1),
			"t" : NumberLong(1)
		},
		"appliedOpTime" : {
			"ts" : Timestamp(1508493732, 1),
			"t" : NumberLong(1)
		},
		"durableOpTime" : {
			"ts" : Timestamp(1508493732, 1),
			"t" : NumberLong(1)
		}
	},
	"members" : [
		{
			"_id" : 0,
			"name" : "192.168.2.115:27017",
			"health" : 1,
			"state" : 1,
			"stateStr" : "PRIMARY",
			"uptime" : 2602,
			"optime" : {
				"ts" : Timestamp(1508493732, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2017-10-20T10:02:12Z"),
			"infoMessage" : "could not find member to sync from",
			"electionTime" : Timestamp(1508493631, 1),
			"electionDate" : ISODate("2017-10-20T10:00:31Z"),
			"configVersion" : 1,
			"self" : true
		},
		{
			"_id" : 1,
			"name" : "192.168.2.116:27017",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 115,
			"optime" : {
				"ts" : Timestamp(1508493732, 1),
				"t" : NumberLong(1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(1508493732, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2017-10-20T10:02:12Z"),
			"optimeDurableDate" : ISODate("2017-10-20T10:02:12Z"),
			"lastHeartbeat" : ISODate("2017-10-20T10:02:13.519Z"),
			"lastHeartbeatRecv" : ISODate("2017-10-20T10:02:13.875Z"),
			"pingMs" : NumberLong(0),
			"syncingTo" : "192.168.2.117:27017",
			"configVersion" : 1
		},
		{
			"_id" : 2,
			"name" : "192.168.2.117:27017",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 115,
			"optime" : {
				"ts" : Timestamp(1508493732, 1),
				"t" : NumberLong(1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(1508493732, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2017-10-20T10:02:12Z"),
			"optimeDurableDate" : ISODate("2017-10-20T10:02:12Z"),
			"lastHeartbeat" : ISODate("2017-10-20T10:02:13.519Z"),
			"lastHeartbeatRecv" : ISODate("2017-10-20T10:02:13.881Z"),
			"pingMs" : NumberLong(0),
			"syncingTo" : "192.168.2.115:27017",
			"configVersion" : 1
		}
	],
	"ok" : 1
}
annalinux:PRIMARY> 

 

mongodb副本集测试

创建库 和 创建集合-->在primary机器

切换到admin库:
annalinux:PRIMARY> use admin
switched to db admin

创建mydb库:
annalinux:PRIMARY> use mydb
switched to db mydb

创建acc集合,并插入一些数据:
annalinux:PRIMARY> db.acc.insert({AccountID:1,USerName:"123",password:"123456"})
WriteResult({ "nInserted" : 1 })

查看所有库:
annalinux:PRIMARY> show dbs
admin  0.000GB
db1    0.000GB
local  0.000GB
mydb   0.000GB
test   0.000GB


切换到mydb库:
annalinux:PRIMARY> show dbs
admin  0.000GB
db1    0.000GB
local  0.000GB
mydb   0.000GB
test   0.000GB

进入mydb库:
annalinux:PRIMARY> use mydb
switched to db mydb

查看集合:
annalinux:PRIMARY> show tables
acc


登录Secondary1机器

说明: 和primary机器数据一致,说明搭建副本集成功了

登录:
[root@root-02 ~]# mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] 
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] 
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] 
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] 
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-10-20T17:28:02.614+0800 I CONTROL  [initandlisten] 

查看所有库:
annalinux:SECONDARY> show dbs;
2017-10-20T18:18:50.600+0800 E QUERY    [thread1] Error: listDatabases failed:{
	"ok" : 0,
	"errmsg" : "not master and slaveOk=false",       //提示不是master,slaveOK=false
	"code" : 13435, 
	"codeName" : "NotMasterNoSlaveOk"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:769:19
shellHelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1

需要执行:
annalinux:SECONDARY> rs.slaveOk()


再show dbs就没问题:
annalinux:SECONDARY> show dbs;
admin  0.000GB
db1    0.000GB
local  0.000GB
mydb   0.000GB
test   0.000GB

进入mydb库:
annalinux:SECONDARY> use mydb
switched to db mydb

查看集合:
annalinux:SECONDARY> show tables
acc




 登录Secondary2机器

说明: 和primary机器数据一致,说明搭建副本集成功了

[root@root-03 ~]# mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] 
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] 
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] 
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] 
2017-10-20T17:46:53.757+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-10-20T17:46:53.758+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-10-20T17:46:53.758+0800 I CONTROL  [initandlisten] 

查看所有库:
annalinux:SECONDARY> show dbs;
2017-10-20T18:18:50.600+0800 E QUERY    [thread1] Error: listDatabases failed:{
	"ok" : 0,
	"errmsg" : "not master and slaveOk=false",       //提示不是master,slaveOK=false
	"code" : 13435, 
	"codeName" : "NotMasterNoSlaveOk"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:769:19
shellHelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1

需要执行:
annalinux:SECONDARY> rs.slaveOk()


再show dbs就没问题:
annalinux:SECONDARY> show dbs;
admin  0.000GB
db1    0.000GB
local  0.000GB
mydb   0.000GB
test   0.000GB

进入mydb库:
annalinux:SECONDARY> use mydb
switched to db mydb

查看集合:
annalinux:SECONDARY> show tables
acc


副本集更改权重模拟primary宕机

说明:在primary机器添加防火墙规则,假装primary宕机,看看是如何变成一个新的primary。

rs.config() -->查看权重

说明:可以看到三个节点都是"priority" : 1, 也就是说三个节点权重都是一样

annalinux:PRIMARY> rs.config()
{
	"_id" : "annalinux",
	"version" : 1,
	"protocolVersion" : NumberLong(1),
	"members" : [
		{
			"_id" : 0,
			"host" : "192.168.2.115:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 1,
			"host" : "192.168.2.116:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 2,
			"host" : "192.168.2.117:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		}
	],
	"settings" : {
		"chainingAllowed" : true,
		"heartbeatIntervalMillis" : 2000,
		"heartbeatTimeoutSecs" : 10,
		"electionTimeoutMillis" : 10000,
		"catchUpTimeoutMillis" : 60000,
		"getLastErrorModes" : {
			
		},
		"getLastErrorDefaults" : {
			"w" : 1,
			"wtimeout" : 0
		},
		"replicaSetId" : ObjectId("59e9c9342025e71e7bcebc7b")
	}
}

在primary机器加一条iptables规则,把27017端口禁掉 

[root@root-01 ~]# iptables -I INPUT -p tcp --dport 27017 -j DROP


查看副本集状态--在Secondary1机器 

说明: 原本192.168.2.115是primary,现在192.168.2.117变成了primary

查看副本集状态:
annalinux:SECONDARY> rs.status()
{
	"set" : "annalinux",
	"date" : ISODate("2017-10-20T10:40:27.907Z"),
	"myState" : 2,
	"term" : NumberLong(2),
	"syncingTo" : "192.168.2.117:27017",
	"heartbeatIntervalMillis" : NumberLong(2000),
	"optimes" : {
		"lastCommittedOpTime" : {
			"ts" : Timestamp(1508496022, 1),
			"t" : NumberLong(2)
		},
		"appliedOpTime" : {
			"ts" : Timestamp(1508496022, 1),
			"t" : NumberLong(2)
		},
		"durableOpTime" : {
			"ts" : Timestamp(1508496022, 1),
			"t" : NumberLong(2)
		}
	},
	"members" : [
		{
			"_id" : 0,
			"name" : "192.168.2.115:27017",
			"health" : 0,
			"state" : 8,
			"stateStr" : "(not reachable/healthy)",          //显示不能获取状态值
			"uptime" : 0,
			"optime" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
			"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
			"lastHeartbeat" : ISODate("2017-10-20T10:40:26.805Z"),
			"lastHeartbeatRecv" : ISODate("2017-10-20T10:40:27.796Z"),
			"pingMs" : NumberLong(0),
			"lastHeartbeatMessage" : "Couldn't get a connection within the time limit",
			"configVersion" : -1
		},
		{
			"_id" : 1,
			"name" : "192.168.2.116:27017",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 4345,
			"optime" : {
				"ts" : Timestamp(1508496022, 1),
				"t" : NumberLong(2)
			},
			"optimeDate" : ISODate("2017-10-20T10:40:22Z"),
			"syncingTo" : "192.168.2.117:27017",
			"configVersion" : 1,
			"self" : true
		},
		{
			"_id" : 2,
			"name" : "192.168.2.117:27017",
			"health" : 1,
			"state" : 1,
			"stateStr" : "PRIMARY",
			"uptime" : 2405,
			"optime" : {
				"ts" : Timestamp(1508496022, 1),
				"t" : NumberLong(2)
			},
			"optimeDurable" : {
				"ts" : Timestamp(1508496022, 1),
				"t" : NumberLong(2)
			},
			"optimeDate" : ISODate("2017-10-20T10:40:22Z"),
			"optimeDurableDate" : ISODate("2017-10-20T10:40:22Z"),
			"lastHeartbeat" : ISODate("2017-10-20T10:40:26.709Z"),
			"lastHeartbeatRecv" : ISODate("2017-10-20T10:40:26.089Z"),
			"pingMs" : NumberLong(0),
			"electionTime" : Timestamp(1508495934, 1),
			"electionDate" : ISODate("2017-10-20T10:38:54Z"),
			"configVersion" : 1
		}
	],
	"ok" : 1
}

把原来的primary机器设置的iptables规则删除掉

说明:把在原来的primary机器设置的iptables规则删除掉,它也不能变会primary,除非设置了权重

[root@root-01 ~]# iptables -D INPUT -p tcp --dport 27017 -j DROP


在新的primary机器(192.168.2.117)设置权重

设置变量:
annalinux:PRIMARY> cfg=rs.config()
{
	"_id" : "annalinux",
	"version" : 1,
	"protocolVersion" : NumberLong(1),
	"members" : [
		{
			"_id" : 0,
			"host" : "192.168.2.115:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 1,
			"host" : "192.168.2.116:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 2,
			"host" : "192.168.2.117:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		}
	],
	"settings" : {
		"chainingAllowed" : true,
		"heartbeatIntervalMillis" : 2000,
		"heartbeatTimeoutSecs" : 10,
		"electionTimeoutMillis" : 10000,
		"catchUpTimeoutMillis" : 60000,
		"getLastErrorModes" : {
			
		},
		"getLastErrorDefaults" : {
			"w" : 1,
			"wtimeout" : 0
		},
		"replicaSetId" : ObjectId("59e9c9342025e71e7bcebc7b")
	}
}

设置权重:
annalinux:PRIMARY> cfg.members[0].priority=3
3
annalinux:PRIMARY> cfg.members[1].priority=2
2
annalinux:PRIMARY> cfg.members[2].priority=1
1


让设置的权重生效:
annalinux:PRIMARY> rs.reconfig(cfg)
{ "ok" : 1 }


查看权重:
annalinux:PRIMARY> rs.config()
2017-10-20T18:54:07.529+0800 E QUERY    [thread1] Error: error doing query: failed: network error while attempting to run command 'replSetGetConfig' on host '127.0.0.1:27017'  :
DB.prototype.runCommand@src/mongo/shell/db.js:132:1
DB.prototype.adminCommand@src/mongo/shell/db.js:150:16
rs.conf@src/mongo/shell/utils.js:1271:16
@(shell):1:1
2017-10-20T18:54:07.533+0800 I NETWORK  [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2017-10-20T18:54:07.534+0800 I NETWORK  [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) ok
annalinux:SECONDARY> 

说明: 提示这台机器不是primary,已经发生了改变,这台机器变成了Secondary了



重新执行rs.config():
annalinux:SECONDARY> rs.config()
{
	"_id" : "annalinux",
	"version" : 2,
	"protocolVersion" : NumberLong(1),
	"members" : [
		{
			"_id" : 0,
			"host" : "192.168.2.115:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 3,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 1,
			"host" : "192.168.2.116:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 2,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 2,
			"host" : "192.168.2.117:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		}
	],
	"settings" : {
		"chainingAllowed" : true,
		"heartbeatIntervalMillis" : 2000,
		"heartbeatTimeoutSecs" : 10,
		"electionTimeoutMillis" : 10000,
		"catchUpTimeoutMillis" : 60000,
		"getLastErrorModes" : {
			
		},
		"getLastErrorDefaults" : {
			"w" : 1,
			"wtimeout" : 0
		},
		"replicaSetId" : ObjectId("59e9c9342025e71e7bcebc7b")
	}
}

说明:可以看到192.168.2.115的权重显示: "priority" : 3
            192.168.2.116的权重显示: "priority" : 2
            192.168.2.117的权重显示: "priority" : 1

 

© 著作权归作者所有

共有 人打赏支持
Linux_Anna
粉丝 8
博文 171
码字总数 170486
作品 0
广州
运维
mongodb(一)mongodb 副本集配置

---layout: blogistop: truetitle: "mongodb 副本集配置"date: 2018-08-29category: mongodbtags: mongodb --- 环境 下载解压 基本配置: 假定已经解压安装完成,现在所处的目录是 /usr/loc...

开心的哈士奇
10/17
0
0
21.36 mongodb分片介绍

21.36 mongodb分片介绍 分片就是将数据库进行拆分,将大型集合分隔到不同服务器上。比如,本来100G的数据,可以分割成10份存储到10台服务器上,这样每台机器只有10G的数据。 通过一个mongos的...

脑洞老湿_
2017/10/20
0
0
mongodb 集群搭建 分片+副本集

mkdir -p /home/mongodb/conf mkdir -p /home/mongodb/mongos/log mkdir -p /home/mongodb/config/data mkdir -p /home/mongodb/config/log mkdir -p /home/mongodb/shard1/data mkdir -p /h......

674591788
06/26
0
0
MongoDB集群部署 - 带访问控制的分片副本集

1. 前言   Ceilometer将meter、event等数据保存在MongoDB中,之前将MongoDB部署在控制节点上,使用三副本模式,时间长了发现meter数据爆炸式增长,区区2T的磁盘捉襟见肘,而想删除旧数据,...

Sai18
08/16
0
0
Mongodb 副本集+分片集群搭建

环境需求: 在三台机器上搭建副本集,在副本集上做分片 服务器IP: 192.168.1.232/192.168.1.238/192.168.1.241 安装Mongodb all nodes: tar zxvf mongodb-linux-x86_64-rhel62-3.4.4.tgz c...

startuppp
06/26
0
0

没有更多内容

加载失败,请刷新页面

加载更多

《netty入门与实战》笔记-05:netty内置的channelHandler

Netty 内置了很多开箱即用的 ChannelHandler。下面,我们通过学习 Netty 内置的 ChannelHandler 来逐步构建我们的 pipeline。 ChannelInboundHandlerAdapter 与 ChannelOutboundHandlerAdap...

Funcy1122
37分钟前
3
0
帧动画(wifi信号动态动画)

准备六张wifi不同信号强度的素材图片,复制到drawable目录中 在drawable目录中新建frame文件,并编写代码 <animation-list xmlns:android="http://schemas.android.com/apk/res/android"> ...

lanyu96
57分钟前
3
0
快速get到学习Linux操作系统的点

Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。Linux能够运行主要的UNIX工具软件、网络协议和应用程序。它支持32位...

问题终结者
今天
3
0
Django2 model操作数据库

1.将应用(如learn)添加到安装应用配置中 将我们新建的应用(learn)添加到 settings.py 中的 INSTALLED_APPS中,告诉Django有这么一个应用。 INSTALLED_APPS = [ 'django.contrib.ad...

MichaelShu
今天
3
0
SpringBoot基础篇Bean之条件注入之注解使用

更多Spring文章,欢迎点击 一灰灰Blog-Spring专题 bean的条件注入,除了前面一篇博文中介绍的通过@Conditional注解配合Condition接口的实现之外,还提供了更多简化的注解使用方式,省略了自己...

小灰灰Blog
今天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部