mongodb3.6分片副本集升级为4.0版本

将分片副本集升级至 4.0 版本,并验证集群 featureCompatibilityVersion 版本。

官方文档


https://docs.mongodb.com/manual/release-notes/4.0-upgrade-replica-set/
https://docs.mongodb.com/manual/release-notes/4.0-upgrade-sharded-cluster/

1、换源

换个清华源

cat >/etc/yum.repos.d/mongodb-org-3.4.repo<<EOF
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-4.0/
gpgcheck=0
enabled=1
EOF

2、副本集protocol version 从pv0升到pv1

指令

cfg.protocolVersion=1;
rs.reconfig(cfg);

结果

lugotestrepl:PRIMARY> cfg.protocolVersion=1;
1
lugotestrepl:PRIMARY> rs.reconfig(cfg);
{
    "ok" : 1,
    "operationTime" : Timestamp(1589596536, 1),
    "$gleStats" : {
        "lastOpTime" : {
            "ts" : Timestamp(1589596536, 1),
            "t" : NumberLong(4)
        },
        "electionId" : ObjectId("7fffffff0000000000000004")
    },
    "$configServerState" : {
        "opTime" : {
            "ts" : Timestamp(1589596521, 2),
            "t" : NumberLong(2)
        }
    },
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589596536, 1),
        "signature" : {
            "hash" : BinData(0,"SnX3/1qI6Dq346a1nC28bhRjX10="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}

3、setFeatureCompatibilityVersion

进入mongos执行

[root@test02 log]# mongo 127.0.0.1:22222/admin
MongoDB shell version v3.6.18
connecting to: mongodb://127.0.0.1:22222/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8c776166-3c5d-49d5-a5c5-8a26b941e7ec") }
MongoDB server version: 3.6.18
mongos> db.auth('admin','test123')
1
mongos> db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )
{
    "ok" : 1,
    "operationTime" : Timestamp(1589596839, 3),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589596839, 3),
        "signature" : {
            "hash" : BinData(0,"iarFAdUhLe6HQNq2urzttW8oBQc="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}

4、升级mongodb本地文件

yum -y upgrade mongodb-org

5、准备升级

mongos停止balancer

Disable the Balancer

指令和结果

[root@test02 log]# mongo 127.0.0.1:22222/admin
MongoDB shell version v4.0.18
connecting to: mongodb://127.0.0.1:22222/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("71524af7-8009-4216-814f-9c2a18f3bd34") }
MongoDB server version: 3.6.18
WARNING: shell and server versions do not match
mongos> db.auth('admin','test123')
1
mongos> sh.stopBalancer()
{
    "ok" : 1,
    "operationTime" : Timestamp(1589597041, 3),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589597041, 3),
        "signature" : {
            "hash" : BinData(0,"isEVCTP0sIRgHbda1FcZbJiKmGc="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}
mongos> sh.getBalancerState()
false

6、升级config servers

重启升级secondary节点

[root@test02 log]# systemctl restart mongodconfig21002
[root@test02 log]# systemctl restart mongodconfig21001

进入主节点
查看状态
rs.status()

lugotestreplconfig:PRIMARY> rs.status()
{
    "set" : "lugotestreplconfig",
    "date" : ISODate("2020-05-16T02:50:40.800Z"),
    "myState" : 1,
    "term" : NumberLong(2),
    "syncingTo" : "",
    "syncSourceHost" : "",
    "syncSourceId" : -1,
    "configsvr" : true,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1589597439, 3),
            "t" : NumberLong(2)
        },
        "readConcernMajorityOpTime" : {
            "ts" : Timestamp(1589597439, 3),
            "t" : NumberLong(2)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1589597439, 3),
            "t" : NumberLong(2)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1589597439, 3),
            "t" : NumberLong(2)
        }
    },
    "members" : [
        {
            "_id" : 0,
            "name" : "127.0.0.1:21000",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 69959,
            "optime" : {
                "ts" : Timestamp(1589597439, 3),
                "t" : NumberLong(2)
            },
            "optimeDate" : ISODate("2020-05-16T02:50:39Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1589596266, 1),
            "electionDate" : ISODate("2020-05-16T02:31:06Z"),
            "configVersion" : 1,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "127.0.0.1:21001",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 79,
            "optime" : {
                "ts" : Timestamp(1589597438, 1),
                "t" : NumberLong(2)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597438, 1),
                "t" : NumberLong(2)
            },
            "optimeDate" : ISODate("2020-05-16T02:50:38Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:50:38Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:50:38.960Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:50:40.099Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "127.0.0.1:21000",
            "syncSourceHost" : "127.0.0.1:21000",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 1
        },
        {
            "_id" : 2,
            "name" : "127.0.0.1:21002",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 85,
            "optime" : {
                "ts" : Timestamp(1589597438, 1),
                "t" : NumberLong(2)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597438, 1),
                "t" : NumberLong(2)
            },
            "optimeDate" : ISODate("2020-05-16T02:50:38Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:50:38Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:50:38.960Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:50:39.230Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "127.0.0.1:21000",
            "syncSourceHost" : "127.0.0.1:21000",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 1
        }
    ],
    "ok" : 1,
    "operationTime" : Timestamp(1589597439, 3),
    "$gleStats" : {
        "lastOpTime" : Timestamp(0, 0),
        "electionId" : ObjectId("7fffffff0000000000000002")
    },
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589597439, 3),
        "signature" : {
            "hash" : BinData(0,"dr/VLVF1efELOHWKwTTyeyL89TQ="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}

进入主,升级主节点
rs.stepDown()

lugotestreplconfig:PRIMARY> rs.stepDown()
2020-05-16T10:53:02.938+0800 I NETWORK  [js] DBClientConnection failed to receive message from 127.0.0.1:21000 - HostUnreachable: Connection closed by peer
2020-05-16T10:53:02.939+0800 E QUERY    [js] Error: error doing query: failed: network error while attempting to run command 'replSetStepDown' on host '127.0.0.1:21000'  :
DB.prototype.runCommand@src/mongo/shell/db.js:168:1
DB.prototype.adminCommand@src/mongo/shell/db.js:185:1
rs.stepDown@src/mongo/shell/utils.js:1489:12
@(shell):1:1
2020-05-16T10:53:02.941+0800 I NETWORK  [js] trying reconnect to 127.0.0.1:21000 failed
2020-05-16T10:53:02.942+0800 I NETWORK  [js] reconnect 127.0.0.1:21000 ok
lugotestreplconfig:SECONDARY> rs.status() 
{
    "set" : "lugotestreplconfig",
    "date" : ISODate("2020-05-16T02:53:24.038Z"),
    "myState" : 2,
    "term" : NumberLong(3),
    "syncingTo" : "127.0.0.1:21001",
    "syncSourceHost" : "127.0.0.1:21001",
    "syncSourceId" : 1,
    "configsvr" : true,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1589597602, 1),
            "t" : NumberLong(3)
        },
        "readConcernMajorityOpTime" : {
            "ts" : Timestamp(1589597602, 1),
            "t" : NumberLong(3)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1589597602, 1),
            "t" : NumberLong(3)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1589597602, 1),
            "t" : NumberLong(3)
        }
    },
    "members" : [
        {
            "_id" : 0,
            "name" : "127.0.0.1:21000",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 70123,
            "optime" : {
                "ts" : Timestamp(1589597602, 1),
                "t" : NumberLong(3)
            },
            "optimeDate" : ISODate("2020-05-16T02:53:22Z"),
            "syncingTo" : "127.0.0.1:21001",
            "syncSourceHost" : "127.0.0.1:21001",
            "syncSourceId" : 1,
            "infoMessage" : "",
            "configVersion" : 1,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "127.0.0.1:21001",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 243,
            "optime" : {
                "ts" : Timestamp(1589597598, 1),
                "t" : NumberLong(3)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597598, 1),
                "t" : NumberLong(3)
            },
            "optimeDate" : ISODate("2020-05-16T02:53:18Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:53:18Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:53:22.077Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:53:22.961Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1589597582, 1),
            "electionDate" : ISODate("2020-05-16T02:53:02Z"),
            "configVersion" : 1
        },
        {
            "_id" : 2,
            "name" : "127.0.0.1:21002",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 249,
            "optime" : {
                "ts" : Timestamp(1589597598, 1),
                "t" : NumberLong(3)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597598, 1),
                "t" : NumberLong(3)
            },
            "optimeDate" : ISODate("2020-05-16T02:53:18Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:53:18Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:53:22.077Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:53:23.305Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "127.0.0.1:21000",
            "syncSourceHost" : "127.0.0.1:21000",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 1
        }
    ],
    "ok" : 1,
    "operationTime" : Timestamp(1589597602, 1),
    "$gleStats" : {
        "lastOpTime" : Timestamp(0, 0),
        "electionId" : ObjectId("7fffffff0000000000000002")
    },
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589597602, 1),
        "signature" : {
            "hash" : BinData(0,"OgyIoG89xO0ylTbBK6ybCmwvLUw="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}

切换成功
重启主
systemctl restart mongodconfig21000

[root@test02 log]# mongo 127.0.0.1:21000/admin
MongoDB shell version v4.0.18
connecting to: mongodb://127.0.0.1:21000/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("218cc8d2-6d95-4b33-bda4-9794e5f1e7be") }
MongoDB server version: 4.0.18

7、Upgrade the shards

升级分片
跟升级configserver同样的步骤

lugotestrepl:PRIMARY> rs.status();
{
    "set" : "lugotestrepl",
    "date" : ISODate("2020-05-16T02:55:57.386Z"),
    "myState" : 1,
    "term" : NumberLong(4),
    "syncingTo" : "",
    "syncSourceHost" : "",
    "syncSourceId" : -1,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1589597750, 1),
            "t" : NumberLong(4)
        },
        "readConcernMajorityOpTime" : {
            "ts" : Timestamp(1589597750, 1),
            "t" : NumberLong(4)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1589597750, 1),
            "t" : NumberLong(4)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1589597750, 1),
            "t" : NumberLong(4)
        }
    },
    "members" : [
        {
            "_id" : 0,
            "name" : "127.0.0.1:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 1556,
            "optime" : {
                "ts" : Timestamp(1589597750, 1),
                "t" : NumberLong(4)
            },
            "optimeDate" : ISODate("2020-05-16T02:55:50Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1589596218, 1),
            "electionDate" : ISODate("2020-05-16T02:30:18Z"),
            "configVersion" : 2,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "127.0.0.1:27018",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 1552,
            "optime" : {
                "ts" : Timestamp(1589597750, 1),
                "t" : NumberLong(4)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597750, 1),
                "t" : NumberLong(4)
            },
            "optimeDate" : ISODate("2020-05-16T02:55:50Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:55:50Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:55:57.107Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:55:56.203Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "127.0.0.1:27017",
            "syncSourceHost" : "127.0.0.1:27017",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 2
        },
        {
            "_id" : 2,
            "name" : "127.0.0.1:27019",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 1555,
            "optime" : {
                "ts" : Timestamp(1589597750, 1),
                "t" : NumberLong(4)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597750, 1),
                "t" : NumberLong(4)
            },
            "optimeDate" : ISODate("2020-05-16T02:55:50Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:55:50Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:55:57.107Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:55:56.202Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "127.0.0.1:27017",
            "syncSourceHost" : "127.0.0.1:27017",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 2
        }
    ],
    "ok" : 1,
    "operationTime" : Timestamp(1589597750, 1),
    "$gleStats" : {
        "lastOpTime" : Timestamp(0, 0),
        "electionId" : ObjectId("7fffffff0000000000000004")
    },
    "$configServerState" : {
        "opTime" : {
            "ts" : Timestamp(1589597752, 1),
            "t" : NumberLong(3)
        }
    },
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589597752, 1),
        "signature" : {
            "hash" : BinData(0,"OsxZE1d2xgi4IuUbw8MLZ88PAX8="),
            "keyId" : NumberLong("6826969049499435034")
        }
    

重启secondary

[root@test02 log]# mongo 127.0.0.1:27017/admin
MongoDB shell version v4.0.18
connecting to: mongodb://127.0.0.1:27017/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("86a4332f-952e-4c9f-8c81-3c632f068b75") }
MongoDB server version: 3.6.18
WARNING: shell and server versions do not match
lugotestrepl:PRIMARY> db.auth('admin','test123')
1
lugotestrepl:PRIMARY> rs.stepDown()
2020-05-16T10:57:44.802+0800 I NETWORK  [js] DBClientConnection failed to receive message from 127.0.0.1:27017 - HostUnreachable: Connection closed by peer
2020-05-16T10:57:44.803+0800 E QUERY    [js] Error: error doing query: failed: network error while attempting to run command 'replSetStepDown' on host '127.0.0.1:27017'  :
DB.prototype.runCommand@src/mongo/shell/db.js:168:1
DB.prototype.adminCommand@src/mongo/shell/db.js:185:1
rs.stepDown@src/mongo/shell/utils.js:1489:12
@(shell):1:1
2020-05-16T10:57:44.809+0800 I NETWORK  [js] trying reconnect to 127.0.0.1:27017 failed
2020-05-16T10:57:44.810+0800 I NETWORK  [js] reconnect 127.0.0.1:27017 ok
lugotestrepl:SECONDARY> exit
bye
[root@test02 log]# systemctl restart mongod27017

重启完主后检查

lugotestrepl:PRIMARY> rs.status()
{
    "set" : "lugotestrepl",
    "date" : ISODate("2020-05-16T02:58:34.484Z"),
    "myState" : 1,
    "term" : NumberLong(6),
    "syncingTo" : "",
    "syncSourceHost" : "",
    "syncSourceId" : -1,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1589597906, 1),
            "t" : NumberLong(6)
        },
        "readConcernMajorityOpTime" : {
            "ts" : Timestamp(1589597906, 1),
            "t" : NumberLong(6)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1589597906, 1),
            "t" : NumberLong(6)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1589597906, 1),
            "t" : NumberLong(6)
        }
    },
    "lastStableCheckpointTimestamp" : Timestamp(1589597864, 3),
    "electionCandidateMetrics" : {
        "lastElectionReason" : "priorityTakeover",
        "lastElectionDate" : ISODate("2020-05-16T02:58:06.736Z"),
        "electionTerm" : NumberLong(6),
        "lastCommittedOpTimeAtElection" : {
            "ts" : Timestamp(1589597884, 1),
            "t" : NumberLong(5)
        },
        "lastSeenOpTimeAtElection" : {
            "ts" : Timestamp(1589597884, 1),
            "t" : NumberLong(5)
        },
        "numVotesNeeded" : 2,
        "priorityAtElection" : 33,
        "electionTimeoutMillis" : NumberLong(10000),
        "priorPrimaryMemberId" : 1,
        "numCatchUpOps" : NumberLong(0),
        "newTermStartDate" : ISODate("2020-05-16T02:58:06.749Z"),
        "wMajorityWriteAvailabilityDate" : ISODate("2020-05-16T02:58:07.760Z")
    },
    "members" : [
        {
            "_id" : 0,
            "name" : "127.0.0.1:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 43,
            "optime" : {
                "ts" : Timestamp(1589597906, 1),
                "t" : NumberLong(6)
            },
            "optimeDate" : ISODate("2020-05-16T02:58:26Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1589597886, 1),
            "electionDate" : ISODate("2020-05-16T02:58:06Z"),
            "configVersion" : 2,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "127.0.0.1:27018",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 39,
            "optime" : {
                "ts" : Timestamp(1589597906, 1),
                "t" : NumberLong(6)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597906, 1),
                "t" : NumberLong(6)
            },
            "optimeDate" : ISODate("2020-05-16T02:58:26Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:58:26Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:58:32.761Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:58:33.873Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "127.0.0.1:27017",
            "syncSourceHost" : "127.0.0.1:27017",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 2
        },
        {
            "_id" : 2,
            "name" : "127.0.0.1:27019",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 39,
            "optime" : {
                "ts" : Timestamp(1589597906, 1),
                "t" : NumberLong(6)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589597906, 1),
                "t" : NumberLong(6)
            },
            "optimeDate" : ISODate("2020-05-16T02:58:26Z"),
            "optimeDurableDate" : ISODate("2020-05-16T02:58:26Z"),
            "lastHeartbeat" : ISODate("2020-05-16T02:58:32.761Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-16T02:58:33.713Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "127.0.0.1:27018",
            "syncSourceHost" : "127.0.0.1:27018",
            "syncSourceId" : 1,
            "infoMessage" : "",
            "configVersion" : 2
        }
    ],
    "ok" : 1,
    "operationTime" : Timestamp(1589597906, 1),
    "$gleStats" : {
        "lastOpTime" : Timestamp(0, 0),
        "electionId" : ObjectId("7fffffff0000000000000006")
    },
    "lastCommittedOpTime" : Timestamp(1589597906, 1),
    "$configServerState" : {
        "opTime" : {
            "ts" : Timestamp(1589597907, 1),
            "t" : NumberLong(3)
        }
    },
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589597907, 1),
        "signature" : {
            "hash" : BinData(0,"KJG7029cMU/qy3e/Ka3bNfwcLv0="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}

另一个分片步骤同上

2020-05-16T10:59:56.324+0800 I NETWORK  [js] DBClientConnection failed to receive message from 127.0.0.1:37017 - HostUnreachable: Connection closed by peer
2020-05-16T10:59:56.325+0800 E QUERY    [js] Error: error doing query: failed: network error while attempting to run command 'replSetStepDown' on host '127.0.0.1:37017'  :
DB.prototype.runCommand@src/mongo/shell/db.js:168:1
DB.prototype.adminCommand@src/mongo/shell/db.js:185:1
rs.stepDown@src/mongo/shell/utils.js:1489:12
@(shell):1:1
2020-05-16T10:59:56.328+0800 I NETWORK  [js] trying reconnect to 127.0.0.1:37017 failed
2020-05-16T10:59:56.329+0800 I NETWORK  [js] reconnect 127.0.0.1:37017 ok

systemctl restart mongod37017

分片升级完毕。

8、升级mongos

重启mongos

systemctl restart mongos22222

检查升级情况
并恢复setBalancerState

[root@test02 log]# mongo 127.0.0.1:22222/admin
MongoDB shell version v4.0.18
connecting to: mongodb://127.0.0.1:22222/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("beb238dd-8acd-4638-b10b-85e2049563c3") }
MongoDB server version: 4.0.18
mongos> sh.setBalancerState(true)
2020-05-16T11:01:41.301+0800 E QUERY    [js] Error: command failed: {
    "ok" : 0,
    "errmsg" : "command balancerStart requires authentication",
    "code" : 13,
    "codeName" : "Unauthorized",
    "operationTime" : Timestamp(1589598086, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589598086, 1),
        "signature" : {
            "hash" : BinData(0,"6JW1VeHiZIYsBpZtCvFjMaQWUWs="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:580:17
assert.commandWorked@src/mongo/shell/assert.js:673:16
sh.startBalancer@src/mongo/shell/utils_sh.js:179:12
sh.setBalancerState@src/mongo/shell/utils_sh.js:145:16
@(shell):1:1
mongos> db.auth('admin','test123')
1
mongos> sh.setBalancerState(true)
{
    "ok" : 1,
    "operationTime" : Timestamp(1589598112, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589598112, 1),
        "signature" : {
            "hash" : BinData(0,"IK8n887IagrIeQcpPvvVOkvcses="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}

9、setFeatureCompatibilityVersion

mongos里面执行

mongos> db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )
{
    "ok" : 1,
    "operationTime" : Timestamp(1589598142, 5),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1589598142, 5),
        "signature" : {
            "hash" : BinData(0,"9ST+MV6BM1kzFVUtgDo5/8HFnhw="),
            "keyId" : NumberLong("6826969049499435034")
        }
    }
}

升级完毕
检查mongo集群使用情况

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,293评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,604评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,958评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,729评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,719评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,630评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,000评论 3 397
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,665评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,909评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,646评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,726评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,400评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,986评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,959评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,996评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,481评论 2 342