MongoDB replica set storage recycling
description:
At present, the Mongodb replica set is a three-node+1 arbitration node.It has been running stably for two years.Due to the continuous update and deletion of data, a large part of the storage space has not been released.The temporary storage of the database in the database is not large, and the storage is not recovered (1.8 T data deleted 1.2T), in order to save costs for maintenance.
Solution:
The official disk defragmentation is not used here.
We use the new node to replace the old node.Pay attention to the size of the oplog setting of the database and whether it can store all the information.
1.Add a new node to resynchronize and
start a new node.The new node configuration file is consistent with the replication set member configuration file, and the database version must be consistent.
The new node has 1T storage.We have a node hidden specifically for program statistics.Online business programs cannot access this node.
When the new node is added to the replication set, set it as a hidden
node.Operation on the primary node of the replication set:
delay 0 seconds, The weight is 0, hide is turned on, and sync index is turned on
mongo> rs.add({_id:1,host:'10.0.6.44:27010',"slaveDelay":0,"priority":0,"hidden":true,"buildIndexes":true});
mongo> rs.status() #查看节点成员状态
By checking the node status, I found that the new node synchronization source is our master node.We need to ensure online business and we need to modify the synchronization source.
2.Modify the synchronization source of the newly added node
Operate on the primary node of the replication set
Run replSetSyncFrom in the admin database.You need to switch to the admin database to use this command.
mongo> db.adminCommand( { replSetSyncFrom: "10.0.6.55:27010" })
#设置同步源为隐藏节点
Check whether the modification is successful:
3.We use the command to check whether the newly added node is synchronized to
check the node status
PRIMARY> rs.status()
"members" : [
{
"_id" : 1,
"name" : "10.0.6.44:27010",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY", #由开始的STARTUP2变为了SECONDARY
"uptime" : 2991253,
"optime" : {
"ts" : Timestamp(1584078756, 24),
"t" : NumberLong(1687)
},
"optimeDurable" : {
"ts" : Timestamp(1584078756, 24),
"t" : NumberLong(1687)
},
"optimeDate" : ISODate("2020-03-13T05:52:36Z"),
"optimeDurableDate" : ISODate("2020-03-13T05:52:36Z"),
"lastHeartbeat" : ISODate("2020-03-13T05:52:36.903Z"),
"lastHeartbeatRecv" : ISODate("2020-03-13T05:52:37.019Z"),
"pingMs" : NumberLong(1),
"lastHeartbeatMessage" : "",
"syncingTo" : "10.10.20.31:27010",
"syncSourceHost" : "10.10.20.31:27010",
"syncSourceId" : 5,
"infoMessage" : "",
"configVersion" : 171
},
Check whether there is a delay in node replication
PRIMARY> db.printSlaveReplicationInfo()
source: 10.0.6.44:27010
syncedTo: Fri Mar 13 2020 13:49:54 GMT+0800 (CST)
1 secs (0 hrs) behind the primary
PRIMARY>
4.After the hidden node data synchronization is completed, modify it to be visible to the program and
connect to the PRIMARY node
PRIMARY> conf = rs.conf(); #查看10.0.6.44:27010排序第几,不是_id
PRIMARY> conf.members[3].priority=10 #从第一个节点开始为0 、1、 2、 3 //10.0.6.44:27010排序3,修改权重为10
10
rs02:PRIMARY> conf.members[3].hidden=false #隐藏设为false
false
PRIMARY> rs.reconfig(conf); #重新加载配置
{
"ok" : 1,
"operationTime" : Timestamp(1584080742, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1584080742, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
PRIMARY> rs.config()
5.Check whether the log of the new node is normal.
6.The old node can be shut down and removed from the cluster
PRIMARY> rs.remove("10.1.1.77:27030")
{
"ok" : 1,
"operationTime" : Timestamp(1584081322, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1584081322, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
PRIMARY>
The multi-nodes of the replica set adopt the way of rotation training and replacement to complete the disk arranging.
brand atorvastatin & lt;a href="https://lipiws.top/"& gt;order atorvastatin 10mg generic& lt;/a& gt; lipitor 10mg over the counter
Atoomd
2024-03-07