Mongodb latest version 4.2.7 three piece cluster modification IP practice

Time:2021-1-11

background

To re network, it is necessary to change the IP of the existing mongodb partitioned cluster server. Therefore, it is also necessary to update the IP of mongodb partitioned cluster. The IP modification of mongodb partitioned cluster can’t be carried out simply through configuration. It needs some twists and turns before it can be updated normally. Here, I record the IP modification process of the whole mongodb cluster, hoping to provide reference for those with the same requirements Little friends help.

Author: Yi lezhu
Original address:https://www.cnblogs.com/yilezhu/p/13536628.html

The original cluster configuration is as follows

192.168.147.11 192.168.147.16 192.168.147.21
mongos mongos mongos
config server config server config server
Master node of shard Server1 Shard Server1 secondary node Shard Server1 arbitration
Shard server2 arbitration Shard server2 master node Shard server2 secondary node
Shard Server3 secondary node Shard Server3 arbitration Master node of shard Server3

The port allocation here is as follows:

mongos 20000
config server 21000
shard server1 27001
shard server2 27002
shard server3 27003

The corresponding relationship of IP modification is as follows:

172.168.7.11 172.168.7.11
172.168.7.16 172.168.7.16
172.168.7.21 172.168.7.21

Change IP step

The upgrade process is to upgrade firstConfigService, and then upgrade threeShardConfigure and modify the last onemongosThe routing of. Of course, before you start, you need to make sure that the mongdb fragmentation cluster has stopped.
The process of stopping is also very simple.ps -ef | grep mongoFind the corresponding thread ID, and thenkillJust drop it.

Modify the IP address of the config node

  • Use the following command tostandloneMode to start aConfigServices
/usr/mongod/bin/mongod --port 21000 --dbpath=/usr/mongod/data
  • Open a new shell and connect to the config service
/usr/mongod/bin/mongo --port 21000
  • Enter intolocalDatabase viewreplsetSet, and modify the correspondinghost
use local
db.system.replset.find()
cfg = db.system.replset.findOne({_id: 'configs'})
cfg.members[0].host = "172.168.7.11:21000"
cfg.members[1].host = "172.168.7.16:21000"
cfg.members[2].host = "172.168.7.21:21000"
db.system.replset.update({_id: 'configs'}, cfg)
db.system.replset.find()
  • The last line above is to find out the modified content, so as to check whether the modification is successful.
  • Follow the same steps tostandloneMode starts the other two config nodes and modifies the information of the other two config service nodes.
  • Stop these three so thatstandloneConfig service node started by mode
  • Start the three config nodes according to the normal cluster mode
/usr/mongod/bin/mongod -f /usr/mongod/conf/config.conf
  • Seeing the following shows that the election was successful.

  • Log in toprimaryNode, modify the partition information

use config

cfg=db.shards.findOne({_id:'shard1'})
cfg.host="shard1/172.168.7.11:27001,172.168.7.16:27001"
db.shards.update({_id:'shard1'},cfg)
cfg = db.shards.findOne({_id: 'shard2'})

cfg.host = "shard2/172.168.7.16:27002,172.168.7.21:27002"
db.shards.update({_id: 'shard2'}, cfg)

cfg = db.shards.findOne({_id: 'shard3'})
cfg.host = "shard3/172.168.7.11:27003,172.168.7.21:27003"
db.shards.update({_id: 'shard3'}, cfg)
  • So far, the modification of the config service node is completed, and then the shard node is modified

Modify the IP information of shard partition

  • withstandloneMode start fragment 1, and then log in
/usr/mongod/bin/mongod --port 27001 --dbpath=/usr/mongod/shard1/
/usr/mongod/bin/mongo --port 27001
  • Switch toadminDatabaseversionLet’s seeconfigConfiguration information, if any_id:shardIdentityIf you have any data, you can update it_id:minOpTimeRecoveryOur data also needs to be updated
use admin
db.system.version.find()
db.system.version.update({"_id" : "shardIdentity"},{"$set":{"configsvrConnectionString" : "configs/172.168.7.11:21000,172.168.7.16:21000,172.168.7.21:21000"}})
db.system.version.update({"_id" : "minOpTimeRecovery"},{"$set":{"configsvrConnectionString" : "configs/172.168.7.11:21000,172.168.7.16:21000,172.168.7.21:21000"}})
  • Modify the configuration information of the replica set, and save the configuration information of the replica setlocalLibrarysystem.replsetIn the collection
use local
cfg = db.system.replset.findOne({_id: 'shard1'})
cfg.members[0].host="172.168.7.11:27003"
cfg.members[1].host="172.168.7.16:27003"
cfg.members[2].host="172.168.7.21:27003"
db.system.replset.update({_id:'shard1'},cfg)
db.system.replset.findOne({_id: 'shard1'})
  • Repeat the above steps to change the IP of shaed2 and shard3 respectively
  • Finally, start your three partitions in cluster mode.
/usr/mongod/bin/mongod -f /usr/mongod/conf/shard1.conf

Modify the routing information of mongos service

  • Open the mongos configuration file with vim and modify the correspondingconfigserverThe configuration item is the latest configderver address
vim /usr/mongod/conf/mongos.conf

  • Start mongos service in cluster mode
/usr/mongod/bin/mongos -f /usr/mongod/conf/mongos.conf
  • Login and verify
/usr/mongod/bin/mongo --port 20000

So far, the modification of mongodb partitioned cluster IP is over.

Recommended Today

JS function

1. Ordinary function Grammar: Function function name (){ Statement block } 2. Functions with parameters Grammar: Function function name (parameter list){ Statement block } 3. Function with return value Grammar: Function function name (parameter list){ Statement block; Return value; } Allow a variable to accept the return value after calling the function Var variable name […]