In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
How to switch cluster node failures in mongodb? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Treatment method
Method 1. Generally, it will switch automatically. If the shard is a replica set composed of 3 nodes and the primary node cannot be connected to the other two secondary nodes, the default value related to the electionTimeoutMilis value in rs.conf () is 10 seconds, and the two secondary nodes will automatically choose one node to become the primary node; if the shard is a replica set composed of 2 nodes, the primary node will automatically become the secondary node after the primary node is started, and the original secondary node will automatically become the new primary node
Method 2. If the machine of the primary node is completely unavailable, you need to switch to the replica node of a shard and switch to the primay state. The mongo command enters the secondary node of the shard, view the rs.conf () configuration information, and check the rs.status () status. See that the primary node cannot be connected and reconfigure using rs.reconfig (). The contents in rs.reconfig parentheses refer to the information of rs.conf () and remove the information of the primay node. And add {"force": true}. After that, I quit and re-logged in to the shard. I found that the copy was switched to the primay state, and the login mongos found that it was normal.
Use mongo to log in to the mongod instance to execute rs.status () or db.isMaster () to see who is the primary node and who is the secondary node
If the mongos instance executes rs.status (), it will report an error replSetGetStatus is not supported through mongos
Mongos instance executes db.isMaster () normally, and connects to the master node by default
Experimental case
1. Switch to TDB6 to execute show tables error, saying that the primay node of the shard corresponding to this database cannot be found.
Mongo-- host 172.22.138.157-- port 27001
Mongos > use TDB6
Mongos > show tables
2019-06-20T00:16:17.935-0700 E QUERY [thread1] Error: listCollections failed: {
"ok": 0
"errmsg": "Could not find host matching read preference {mode:\" primary\ ", tags: [{}]} for set shard28003"
2. You can only enter the secondary node of this shard, view the configuration information of rs.conf (), and check the status of rs.status (). You can see that the primary node cannot be connected, reconfigure it with rs.reconfig (), refer to the information of rs.conf () in rs.reconfig parentheses, remove the information of primay node, and add {"force": true}.
Mongo-- host 172.22.138.157-- port 28003
Shard28003:SECONDARY > rs.conf ()
{
"_ id": "shard28003"
"version": 1
"protocolVersion": NumberLong (1)
"members": [
{
"_ id": 0
"host": "172.22.138.157purl 28003"
"arbiterOnly": false
"buildIndexes": true
"hidden": false
"priority": 1
"tags": {
}
"slaveDelay": NumberLong (0)
"votes": 1
}
{
"_ id": 1
"host": "172.22.138.158purl 28003"
"arbiterOnly": false
"buildIndexes": true
"hidden": false
"priority": 1
"tags": {
}
"slaveDelay": NumberLong (0)
"votes": 1
}
]
"settings": {
"chainingAllowed": true
"heartbeatIntervalMillis": 2000
"heartbeatTimeoutSecs": 10
"electionTimeoutMillis": 10000
"catchUpTimeoutMillis":-1
"catchUpTakeoverDelayMillis": 30000
"getLastErrorModes": {
}
"getLastErrorDefaults": {
"w": 1
"wtimeout": 0
}
"replicaSetId": ObjectId ("5d09d2c89fb43c4506d995ac")
}
}
Shard28003:SECONDARY > rs.status ()
{
"set": "shard28003"
"date": ISODate ("2019-06-20T07:25:07.438Z")
"myState": 2
"term": NumberLong (2)
"syncingTo":
"syncSourceHost":
"syncSourceId":-1
"heartbeatIntervalMillis": NumberLong (2000)
"optimes": {
"lastCommittedOpTime": {
Ts: Timestamp (1561001587, 1)
"t": NumberLong (2)
}
"readConcernMajorityOpTime": {
Ts: Timestamp (1561001587, 1)
"t": NumberLong (2)
}
"appliedOpTime": {
Ts: Timestamp (1561001587, 1)
"t": NumberLong (2)
}
"durableOpTime": {
Ts: Timestamp (1561001587, 1)
"t": NumberLong (2)
}
}
"members": [
{
"_ id": 0
"name": "172.22.138.157purl 28003"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 15254
"optime": {
Ts: Timestamp (1561001587, 1)
"t": NumberLong (2)
}
"optimeDate": ISODate ("2019-06-20T03:33:07Z")
"syncingTo":
"syncSourceHost":
"syncSourceId":-1
"infoMessage": "could not find member to sync from"
"configVersion": 1
"self": true
"lastHeartbeatMessage":
}
{
"_ id": 1
"name": "172.22.138.158purl 28003"
"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 ("2019-06-20T07:25:07.121Z")
"lastHeartbeatRecv": ISODate ("2019-06-20T03:33:08.040Z")
"pingMs": NumberLong (0)
"lastHeartbeatMessage": "Connection refused"
"syncingTo":
"syncSourceHost":
"syncSourceId":-1
"infoMessage":
"configVersion":-1
}
]
"ok": 1
OperationTime: Timestamp (1561001587, 1)
"$gleStats": {
"lastOpTime": Timestamp (0,0)
"electionId": ObjectId ("000000000000000000000000")
}
"$configServerState": {
"opTime": {
Ts: Timestamp (1561001589, 1)
"t": NumberLong (2)
}
}
"$clusterTime": {
ClusterTime: Timestamp (1561015481, 1)
"signature": {
"hash": BinData (0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA=")
"keyId": NumberLong (0)
}
}
}
Shard28003:SECONDARY > rs.reconfig ({
"_ id": "shard28003"
"version": 1
"protocolVersion": NumberLong (1)
"members": [
{
"_ id": 0
"host": "172.22.138.157purl 28003"
"arbiterOnly": false
"buildIndexes": true
"hidden": false
"priority": 1
"tags": {
}
"slaveDelay": NumberLong (0)
"votes": 1
}
]
"settings": {
"chainingAllowed": true
"heartbeatIntervalMillis": 2000
"heartbeatTimeoutSecs": 10
"electionTimeoutMillis": 10000
"catchUpTimeoutMillis":-1
"catchUpTakeoverDelayMillis": 30000
"getLastErrorModes": {
}
"getLastErrorDefaults": {
"w": 1
"wtimeout": 0
}
"replicaSetId": ObjectId ("5d09d2c89fb43c4506d995ac")
}
}
{"force": true}
)
3. After logging out, log in again and find that the copy has been switched to primay status.
Mongo-- host 172.22.138.157-- port 28003
Shard28003:PRIMARY >
4. Log in to mongos and find that you can operate show tables normally, but you cannot db.createCollection, because the primary node of Config Server's replica set is broken. It would be nice to switch the secondary node of Config Server's replica set according to the above methods 1, 2 and 3.
Mongo-- host 172.22.138.157-- port 27001
Mongos > show tables
Test06
Mongos > use testdb2
Switched to db testdb2
Mongos > db.createCollection ("table1")
{
"ok": 0
"errmsg": "Database testdb2 not found due to Could not confirm non-existence of database testdb2 due to Could not find host matching read preference {mode:\" primary\ "} for set config29001"
"code": 133
"codeName": "FailedToSatisfyReadPreference"
OperationTime: Timestamp (1561034171, 1)
"$clusterTime": {
ClusterTime: Timestamp (1561034171, 1)
"signature": {
"hash": BinData (0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA=")
"keyId": NumberLong (0)
}
}
}
This is the answer to the question about how to switch cluster nodes in mongodb. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.