在192.168.100.102上关闭shard1复制集的primary节点,测试mongos访问数据依然没有问题,实现了复制集的高可用;
[root@shard1 bin]# mongod -f /usr/local/mongodb/bin/mongodb1.conf --shutdown
killing process with pid: 7140
[root@shard1 bin]# netstat -utpln |grep mon
tcp 0 0 192.168.100.102:27018 0.0.0.0:* LISTEN 7167/mongod
tcp 0 0 192.168.100.102:27019 0.0.0.0:* LISTEN 7194/mongod
tcp 0 0 192.168.100.102:27025 0.0.0.0:* LISTEN 7397/mongos
[root@shard1 bin]# mongo --port 27018 --host 192.168.100.102
MongoDB shell version v3.6.3
connecting to: mongodb://192.168.100.102:27018/
MongoDB server version: 3.6.3
Server has startup warnings:
2020-04-16T10:37:39.339+0800 I CONTROL [initandlisten]
2020-04-16T10:37:39.339+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-04-16T10:37:39.339+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-04-16T10:37:39.339+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-04-16T10:37:39.339+0800 I CONTROL [initandlisten]
shard1:PRIMARY>
Bye
[root@shard1 bin]# mongo --port 27025 --host 192.168.100.102
mongos> show dbs
admin 0.000GB
config 0.001GB
test 0.000GB
zzq 0.003GB
zzq2 0.000GB
zzq7 0.000GB
mongos> use zzq7
switched to db zzq7
mongos> db.hehe.stats()
{
"sharded" : true,
"capped" : false,
"ns" : "zzq7.hehe",
"count" : 1000,
"size" : 49000,
"storageSize" : 40960,
"totalIndexSize" : 73728,
"indexSizes" : {
"_id_" : 32768,
"id_hashed" : 40960
},
"avgObjSize" : 49,
"nindexes" : 2,
"nchunks" : 4,
"shards" : {
"shard1" : {
"ns" : "zzq7.hehe",
"size" : 23520,
"count" : 480,
"avgObjSize" : 49,
"storageSize" : 20480,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
....
"shard2" : {
"ns" : "zzq7.hehe",
"size" : 25480,
"count" : 520,
"avgObjSize" : 49,
"storageSize" : 20480,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
[root@config ~]# mongo --port 27025 --host 192.168.100.101
mongos> show dbs
admin 0.000GB
config 0.001GB
test 0.000GB
zzq 0.003GB
zzq2 0.000GB
zzq7 0.000GB
mongos> use zzq7
switched to db zzq7
mongos> db.hehe.stats()
{
"sharded" : true,
"capped" : false,
"ns" : "zzq7.hehe",
"count" : 1000,
"size" : 49000,
"storageSize" : 40960,
"totalIndexSize" : 73728,
"indexSizes" : {
"_id_" : 32768,
"id_hashed" : 40960
},
"avgObjSize" : 49,
"nindexes" : 2,
"nchunks" : 4,
"shards" : {
"shard1" : {
"ns" : "zzq7.hehe",
"size" : 23520,
"count" : 480,
"avgObjSize" : 49,
"storageSize" : 20480,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
......
"shard2" : {
"ns" : "zzq7.hehe",
"size" : 25480,
"count" : 520,
"avgObjSize" : 49,
"storageSize" : 20480,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
版权声明:本文为weixin_45154567原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。