将分片副本集升级至 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集群使用情况