mongodb version upgrade

Posted by johncollins on Tue, 30 Jul 2019 10:08:20 +0200

mongodb version upgrade

Background
At present, the company's version of mongodb is the old version of 3.0.6. The company hopes to upgrade the version of mongodb to more than 3.6, so it's a pain. No database upgrade has been done before. The first reaction in my mind is not to redeploy a set of mongodb replica sets + fragmentation mode, or can upgrade directly from version 3.0.6 to version 3.6. After consulting the data above, it is found that the actual mongodb version upgrade is a step-by-step process, which needs to be upgraded to version 3.4 and then to version 3.6.
3.0 ======> 3.4 ======> 3.6

II. Environment
Currently, there are three machines in mongodb cluster. The environment is replica set + fragmentation mode.
The first stage: division master 1, division master 2, division master 3, config, mongos
Second stage: fragmented copy 1, fragmented copy 2, fragmented copy 3, config, mongos
The third stage: fragmented copy 1, fragmented copy 2, fragmented copy 3, config, mongos

3. Download the mongodb packages of different versions

[yukw@mongodb1-211 mongodbwork3.4]$ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.4.tgz
[yukw@mongodb1-211 mongodbwork3.4]$ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.5.tgz

4. Here's how to upgrade from 3.0 to 3.4
## 1. Copy the package to the response directory

[yukw@mongodb1-211 mongodbwork3.4]$ mkdir /data/service/mongodbwork3.4
[yukw@mongodb1-211 mongodbwork3.4]$ cp mongodb-linux-x86_64-rhel62-3.4.4.tgz /data/service/mongodbwork3.4/

## 2. Decompression package

[yukw@mongodb1-211 mongodbwork3.4]$ tar xf mongodb-linux-x86_64-rhel62-3.4.4.tgz
[yukw@mongodb1-211 mongodbwork3.4]$ mv mongodb-linux-x86_64-rhel62-3.4.4 mongodb

## 3. Stop mongodb service

[yukw@mongodb1-211 mongodbwork3.4]$ ps -ef |grep mongo |grep -v grep | awk '{print $2}' | xargs kill -2      ##Every machine executes

## 3.4 version of mongodb binary file to start three fragmentation services in turn

[yukw@mongodb1-211 mongodbwork3.4] $/data/service/mongodbwork3.4/mongodb/bin/mongod -f /etc/mongodb1.conf     ##Every machine executes
[yukw@mongodb1-211 mongodbwork3.4] $/data/service/mongodbwork3.4/mongodb/bin/mongod -f /etc/mongodb2.conf	 ##Every machine executes
[yukw@mongodb1-211 mongodbwork3.4] $/data/service/mongodbwork3.4/mongodb/bin/mongod -f /etc/mongodb3.conf	 ##Every machine executes

## 4. Upgraded version in PRIMARY machine

[yukw@mongodb1-211 mongodbwork3.4]$ /data/service/mongodbwork3.4/mongodb/bin/mongo -port mongodb1_prot
configdb:PRIMARY> use admin
switched to db admin
configdb:PRIMARY> db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
{ "ok" : 1 }
[yukw@mongodb1-211 mongodbwork3.4]$ /data/service/mongodbwork3.4/mongodb/bin/mongo -port mongodb2_prot
configdb:PRIMARY> use admin
switched to db admin
configdb:PRIMARY> db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
{ "ok" : 1 }
[yukw@mongodb1-211 mongodbwork3.4]$ /data/service/mongodbwork3.4/mongodb/bin/mongo -port mongodb3_prot
configdb:PRIMARY> use admin
switched to db admin
configdb:PRIMARY> db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
{ "ok" : 1 }

## 5. Check whether the fragmentation service version is updated on each replica set machine

shard1:SECONDARY> use admin
switched to db admin
shard1:SECONDARY> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : "3.4", "ok" : 1 }

## 6. Start Configuration Services

[yukw@mongodb1-211 mongodbwork3.4]$ /data/service/mongodbwork3.4/mongodb/bin/mongod -f /etc/mongo_config.conf     ##All three machines are executed

## 7. Configuration Service Configuration Copy Set. Here we need to pay attention to backing up the config data file first (this step is for the reader to backup himself), because when configuring the replica set, we may prompt that there is data in the directory of the replica set, which can not be initialized.

[yukw@mongodb3-111 data]$ /data/service/mongodbwork3.4/mongodb/bin/mongo -port config_port

> use admin
switched to db admin
> configdb1={_id:'configdb',members:[
{_id:0,host:'10.0.1.211:20000',priority:9},
{_id:1,host:'10.0.1.209:20000',priority:5},
{_id:2,host:'10.0.1.111:20000',priority:7}]
}                             ## Configure replica sets and set weights
>  rs.initiate(configdb1)     ##Initialization configuration

Explain here that version 3.0 can start mongos routing service without config configuration service setup replica set, but in version 3.4, config configuration service configuration replica set is required, otherwise starting mongos service will make an error, as follows:

## 8. Start the mongos routing service

[yukw@mongodb3-111 data]$ /data/service/mongodbwork3.4/mongodb/bin/mongos -f /etc/mongo_mongos.conf   ##Every machine executes

## 9. Upgrade version 3.4 to 3.6, the same principle

Okay, that's the whole process of mongodb version upgrade. If you have any questions, you can contact the blogger for discussion.

Topics: MongoDB Linux Database