In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
MongoDB3.2 how to upgrade to 3.4.6, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
MongoDB upgrade test steps:
1. MongoDB version upgrade sequence 3.2-> 3.4-> 3.6-> 4.0 cannot be upgraded across versions.
2. After upgrading to 3.4, you cannot downgrade to 3.2.7 or earlier. You can only be downgraded to 3.2.8 or later
3. Upgrade the Secondary in all replica sets first
4. Downgrade Primary node to Secondary node
5. Upgrade Primary
6. MongoDB3.2 is upgraded to 3.4.If the version information is still 3.2after login, execute db.adminCommand ({setFeatureCompatibilityVersion: "3.4"}).
7. MongoDB3.4 is upgraded to 3.6.If the version information is still 3.4after login, execute db.adminCommand ({setFeatureCompatibilityVersion: "3.6"})
8. MongoDB3.6 is upgraded to 4.0. if the version information is still 3.6after logging in, execute db.adminCommand ({setFeatureCompatibilityVersion: "4.0"})
# only perform # when upgrading to 4.0
Cfg = rs.conf ()
Cfg.protocolVersion=1
Rs.reconfig (cfg)
View the MongoDB process:
[root@127.0.0.1 bin] # ps-ef | grep mongo
Root 17908 9428 0 20:43 pts/1 00:00:00 grep mongo
Root 47265 1 0 Oct09? 00:09:38 / u02/mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/2777/conf/mongodb_2777.conf
Root 179052 1 0 Oct09? 00:05:27 / u02/mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/5777/conf/mongodb_5777.conf
Root 180521 1 2 Oct08? 00:59:01 / u02/mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/3777/conf/mongodb_3777.conf
Root 185602 1 0 Oct08? 00:08:30 / u02/mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/4777/conf/mongodb_4777.conf
Port 5777 is Primary,2777,3777,4777 and Secondary
Log in to the replica set to view the replica set information:
[root@127.0.0.1 bin] # / u02/mongodb/mongodb/bin/mongo-- port 5777
MongoDB shell version: 3.2.6
Connecting to: 127.0.0.1:5777/test
Server has startup warnings:
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
Shard1:PRIMARY > rs.status ()
{
"set": "shard1"
Date: ISODate ("2019-10-10T12:42:36.196Z")
"myState": 1
Term: NumberLong (4)
"heartbeatIntervalMillis": NumberLong (2000)
"members": [
{
"_ id": 1
"name": "127.0.0.1 purl 3777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 106410
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
LastHeartbeat: ISODate ("2019-10-10T12:42:34.326Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:42:35.321Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 21
}
{
"_ id": 2
"name": "127.0.0.1 purl 4777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 106410
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
LastHeartbeat: ISODate ("2019-10-10T12:42:34.324Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:42:35.321Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 21
}
{
"_ id": 3
"name": "127.0.0.1 purl 5777"
"health": 1
"state": 1
"stateStr": "PRIMARY"
"uptime": 106450
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
ElectionTime: Timestamp (1570711316, 1)
ElectionDate: ISODate ("2019-10-10T12:41:56Z")
"configVersion": 21
"self": true
}
{
"_ id": 4
"name": "127.0.0.1 purl 2777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 100601
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
LastHeartbeat: ISODate ("2019-10-10T12:42:34.324Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:42:35.319Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 21
}
]
"ok": 1
}
Rename mongodb-linux-x86_64-rhel62-3.4.6.tgz after decompressing it under / opt
[root@127.0.0.1 bin] # ls
Bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongooplog mongoperf mongoreplay mongorestore mongos mongostat mongotop
[root@127.0.0.1 bin] # pwd
/ opt/mongodb_3_4/bin
Delete the copy:
Shard1:PRIMARY > rs.remove ("127.0.0.1 purl 2777")
Shut down port 2777 mongo
[root@127.0.0.1 bin] # / mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/2777/conf/mongodb_2777.conf-- shutdown
Start port 2777mongo via mongodb3.4 and upgrade to 3.4
/ opt/mongodb_3_4/bin/mongod-f / u02/mongodb/mongodb/2777/conf/mongodb_2777.conf
Log in to mongo to view version information
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 2777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:2777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten]
Add port 2777mongo to the replica set
Shard1:PRIMARY > rs.add ("127.0.0.1 purl 2777")
View port 2777 copy set information
Shard1:PRIMARY > rs.status ()
{
"set": "shard1"
Date: ISODate ("2019-10-10T12:49:24.623Z")
"myState": 1
Term: NumberLong (4)
"heartbeatIntervalMillis": NumberLong (2000)
"members": [
{
"_ id": 1
"name": "127.0.0.1 purl 3777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 106819
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
LastHeartbeat: ISODate ("2019-10-10T12:49:24.438Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:49:23.376Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 21
}
{
"_ id": 2
"name": "127.0.0.1 purl 4777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 106819
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
LastHeartbeat: ISODate ("2019-10-10T12:49:24.438Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:49:23.374Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 21
}
{
"_ id": 3
"name": "127.0.0.1 purl 5777"
"health": 1
"state": 1
"stateStr": "PRIMARY"
"uptime": 106858
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
ElectionTime: Timestamp (1570711316, 1)
ElectionDate: ISODate ("2019-10-10T12:41:56Z")
"configVersion": 21
"self": true
}
{
"_ id": 4
"name": "127.0.0.1 purl 2777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 101009
"optime": {
Ts: Timestamp (1570711316, 2)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:41:56Z")
LastHeartbeat: ISODate ("2019-10-10T12:49:24.405Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:49:23.375Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 21
}
]
"ok": 1
}
Log in to port 2777 of mongo3.4 version to query data test
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 2777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:2777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten]
Shard1:SECONDARY > rs.slaveOk ()
Shard1:SECONDARY > show dbs
Local 0.001GB
Test 0.000GB
Yoon 0.000GB
Shard1:SECONDARY > use yoon
Switched to db yoon
Shard1:SECONDARY > show collections
Movie
Shard1:SECONDARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
Start port 3777mongo via mongodb3.4 and upgrade to 3.4
[root@127.0.0.1 bin] # / u02/mongodb/mongodb/bin/mongo-- port 5777
MongoDB shell version: 3.2.6
Connecting to: 127.0.0.1:5777/test
Server has startup warnings:
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
Shard1:PRIMARY > rs.remove ("127.0.0.1 3777")
{"ok": 1}
Shard1:PRIMARY > rs.status ()
{
"set": "shard1"
Date: ISODate ("2019-10-10T12:52:37.517Z")
"myState": 1
Term: NumberLong (4)
"heartbeatIntervalMillis": NumberLong (2000)
"members": [
{
"_ id": 2
"name": "127.0.0.1 purl 4777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 107011
"optime": {
Ts: Timestamp (1570711953, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:52:33Z")
LastHeartbeat: ISODate ("2019-10-10T12:52:37.379Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:52:37.379Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 22
}
{
"_ id": 3
"name": "127.0.0.1 purl 5777"
"health": 1
"state": 1
"stateStr": "PRIMARY"
"uptime": 107051
"optime": {
Ts: Timestamp (1570711953, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:52:33Z")
ElectionTime: Timestamp (1570711316, 1)
ElectionDate: ISODate ("2019-10-10T12:41:56Z")
"configVersion": 22
"self": true
}
{
"_ id": 4
"name": "127.0.0.1 purl 2777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 101202
"optime": {
Ts: Timestamp (1570711953, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:52:33Z")
LastHeartbeat: ISODate ("2019-10-10T12:52:37.379Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:52:37.379Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 22
}
]
"ok": 1
}
[root@127.0.0.1 bin] # / u02/mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/3777/conf/mongodb_3777.conf-- shutdown
Killing process with pid: 180521
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongod-f / u02/mongodb/mongodb/3777/conf/mongodb_3777.conf
About to fork child process, waiting until server is ready for connections.
Forked process: 25117
Child process started successfully, parent exiting
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 3777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:3777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
Shard1:OTHER >
Upgrade port 3777 to version 3.4.6 and add port 3777 to the replica set
[root@127.0.0.1 bin] # / u02/mongodb/mongodb/bin/mongo-- port 5777
MongoDB shell version: 3.2.6
Connecting to: 127.0.0.1:5777/test
Server has startup warnings:
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
Shard1:PRIMARY > rs.add ("127.0.0.1 3777")
{"ok": 1}
Shard1:PRIMARY > rs.status ()
{
"set": "shard1"
Date: ISODate ("2019-10-10T12:55:20.927Z")
"myState": 1
Term: NumberLong (4)
"heartbeatIntervalMillis": NumberLong (2000)
"members": [
{
"_ id": 2
"name": "127.0.0.1 purl 4777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 107175
"optime": {
Ts: Timestamp (1570712117, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:55:17Z")
LastHeartbeat: ISODate ("2019-10-10T12:55:19.964Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:55:19.964Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 23
}
{
"_ id": 3
"name": "127.0.0.1 purl 5777"
"health": 1
"state": 1
"stateStr": "PRIMARY"
"uptime": 107214
"optime": {
Ts: Timestamp (1570712117, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:55:17Z")
ElectionTime: Timestamp (1570711316, 1)
ElectionDate: ISODate ("2019-10-10T12:41:56Z")
"configVersion": 23
"self": true
}
{
"_ id": 4
"name": "127.0.0.1 purl 2777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 101365
"optime": {
Ts: Timestamp (1570712117, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:55:17Z")
LastHeartbeat: ISODate ("2019-10-10T12:55:19.964Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:55:19.965Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 23
}
{
"_ id": 5
"name": "127.0.0.1 purl 3777"
"health": 1
"state": 5
"stateStr": "STARTUP2"
"uptime": 0
"optime": {
Ts: Timestamp (1570711953, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T12:52:33Z")
LastHeartbeat: ISODate ("2019-10-10T12:55:19.964Z")
LastHeartbeatRecv: ISODate ("2019-10-10T12:55:17.966Z")
"pingMs": NumberLong (0)
"configVersion": 23
}
]
"ok": 1
}
Insert a new piece of data into Primary to query the test on port 3777
View DB
Shard1:PRIMARY > show dbs
Local 0.001GB
Test 0.000GB
Yoon 0.000GB
Connect DB
Shard1:PRIMARY > use yoon
Switched to db yoon
View the following table of DB
Shard1:PRIMARY > show collections
Movie
Query data
Shard1:PRIMARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
Currently connect to DB
Shard1:PRIMARY > db
Yoon
Insert a new piece of data
Shard1:PRIMARY > db.movie.insert ({"kname": "shouqi"})
WriteResult ({"nInserted": 1})
Query data
Shard1:PRIMARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
{"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
Log in to ports 2777 and 3777 to view {"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 2777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:2777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-09T16:41:23.659+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-09T16:41:23.660+0800 I CONTROL [initandlisten]
Shard1:SECONDARY > rs.slaveOk ()
Shard1:SECONDARY > use yoon
Switched to db yoon
Shard1:SECONDARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
{"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
Shard1:SECONDARY >
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 3777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:3777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
Shard1:SECONDARY > rs.slaveOk ()
Shard1:SECONDARY > use yoon
Switched to db yoon
Shard1:SECONDARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
{"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
And so on, upgrade port 4777 to 3.4.6
Shard1:PRIMARY > rs.remove ("127.0.0.1 purl 4777")
{"ok": 1}
[root@127.0.0.1 bin] # / u02/mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/4777/conf/mongodb_4777.conf-- shutdown
Killing process with pid: 185602
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongod-f / u02/mongodb/mongodb/4777/conf/mongodb_4777.conf
About to fork child process, waiting until server is ready for connections.
Forked process: 34453
Child process started successfully, parent exiting
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 4777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:4777/
MongoDB server version: 3.4.6
Add port 4777 to the replica set
[root@127.0.0.1 bin] # / u02/mongodb/mongodb/bin/mongo-- port 5777
MongoDB shell version: 3.2.6
Connecting to: 127.0.0.1:5777/test
Server has startup warnings:
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-09T15:08:26.464+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-09T15:08:26.465+0800 I CONTROL [initandlisten]
Shard1:PRIMARY > rs.add ("127.0.0.1 purl 4777")
{"ok": 1}
Shard1:PRIMARY > rs.status ()
{
"set": "shard1"
Date: ISODate ("2019-10-10T13:07:58.679Z")
"myState": 1
Term: NumberLong (4)
"heartbeatIntervalMillis": NumberLong (2000)
"members": [
{
"_ id": 3
"name": "127.0.0.1 purl 5777"
"health": 1
"state": 1
"stateStr": "PRIMARY"
"uptime": 107972
"optime": {
Ts: Timestamp (1570712875, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T13:07:55Z")
ElectionTime: Timestamp (1570711316, 1)
ElectionDate: ISODate ("2019-10-10T12:41:56Z")
"configVersion": 25
"self": true
}
{
"_ id": 4
"name": "127.0.0.1 purl 2777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 102123
"optime": {
Ts: Timestamp (1570712875, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T13:07:55Z")
LastHeartbeat: ISODate ("2019-10-10T13:07:57.987Z")
LastHeartbeatRecv: ISODate ("2019-10-10T13:07:55.990Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 25
}
{
"_ id": 5
"name": "127.0.0.1 purl 3777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 758
"optime": {
Ts: Timestamp (1570712875, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T13:07:55Z")
LastHeartbeat: ISODate ("2019-10-10T13:07:57.987Z")
LastHeartbeatRecv: ISODate ("2019-10-10T13:07:55.990Z")
"pingMs": NumberLong (0)
"syncingTo": "127.0.0.1 purl 5777"
"configVersion": 25
}
{
"_ id": 6
"name": "127.0.0.1 purl 4777"
"health": 1
"state": 5
"stateStr": "STARTUP2"
"uptime": 0
"optime": {
Ts: Timestamp (1570712743, 1)
"t": NumberLong (4)
}
OptimeDate: ISODate ("2019-10-10T13:05:43Z")
LastHeartbeat: ISODate ("2019-10-10T13:07:57.987Z")
LastHeartbeatRecv: ISODate ("2019-10-10T13:07:55.990Z")
"pingMs": NumberLong (0)
"configVersion": 25
}
]
"ok": 1
}
Upgrade Primary to 3.4.6
There are two ways to demote a Primary node to a Secondary node, one is rs.stepDown (), and the other is to modify the Primary by changing the priority
Shard1:PRIMARY > rs.stepDown ()
Or
Modify PRIMARY by priority
Shard1:PRIMARY > config=rs.conf () / / View the current configuration and store it in the config variable
Shard1:PRIMARY > config.members [0] .priority = 50 / / modify the config variable. The priority of the first group member is 50.
Shard1:PRIMARY > rs.reconfig (config) / / configuration takes effect
Shard1:PRIMARY > rs.config () / / View current configuration
{
"_ id": "shard1"
"version": 18
"protocolVersion": NumberLong (1)
"members": [
{
"_ id": 1
"host": "127.0.0.1 purl 3777"
"arbiterOnly": false
"buildIndexes": true
"hidden": false
"priority": 50
"tags": {
}
"slaveDelay": NumberLong (0)
"votes": 1
}
{
"_ id": 2
"host": "127.0.0.1 purl 4777"
"arbiterOnly": false
"buildIndexes": true
"hidden": false
"priority": 1
"tags": {
}
"slaveDelay": NumberLong (0)
"votes": 1
}
{
"_ id": 3
"host": "127.0.0.1 purl 5777"
"arbiterOnly": false
"buildIndexes": true
"hidden": false
"priority": 1
"tags": {
}
"slaveDelay": NumberLong (0)
"votes": 1
}
{
"_ id": 4
"host": "127.0.0.1 purl 2777"
"arbiterOnly": false
"buildIndexes": true
"hidden": false
"priority": 1
"tags": {
}
"slaveDelay": NumberLong (0)
"votes": 1
}
]
"settings": {
"chainingAllowed": true
"heartbeatIntervalMillis": 2000
"heartbeatTimeoutSecs": 10
"electionTimeoutMillis": 10000
"getLastErrorModes": {
}
"getLastErrorDefaults": {
"w": 1
"wtimeout": 0
}
"replicaSetId": ObjectId ("5d9c7a7e76695600e03e231f")
}
}
Log in to port 3777 and change to Primary
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 3777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:3777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
Shard1:PRIMARY >
Upgrade port 5777
Shard1:PRIMARY > rs.remove ("127.0.0.1 virtual 5777")
{"ok": 1}
[root@127.0.0.1 bin] # / u02/mongodb/mongodb/bin/mongod-f / u02/mongodb/mongodb/5777/conf/mongodb_5777.conf-- shutdown
Killing process with pid: 179052
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongod-f / u02/mongodb/mongodb/5777/conf/mongodb_5777.conf
About to fork child process, waiting until server is ready for connections.
Forked process: 40446
Child process started successfully, parent exiting
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 5777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:5777/
MongoDB server version: 3.4.6
Add port 5777 to the replica set
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 3777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:3777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-10T20:53:40.536+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-10T20:53:40.537+0800 I CONTROL [initandlisten]
Shard1:PRIMARY > rs.add ("127.0.0.1 virtual 5777")
{"ok": 1}
Shard1:PRIMARY > rs.status ()
{
"set": "shard1"
Date: ISODate ("2019-10-10T13:16:30.878Z")
"myState": 1
"term": NumberLong (5)
"heartbeatIntervalMillis": NumberLong (2000)
"optimes": {
"lastCommittedOpTime": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
"appliedOpTime": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
"durableOpTime": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
}
"members": [
{
"_ id": 4
"name": "127.0.0.1 purl 2777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 1272
"optime": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
"optimeDurable": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
OptimeDate: ISODate ("2019-10-10T13:16:16Z")
OptimeDurableDate: ISODate ("2019-10-10T13:16:16Z")
LastHeartbeat: ISODate ("2019-10-10T13:16:28.911Z")
LastHeartbeatRecv: ISODate ("2019-10-10T13:16:26.912Z")
"pingMs": NumberLong (0)
"configVersion": 28
}
{
"_ id": 5
"name": "127.0.0.1 purl 3777"
"health": 1
"state": 1
"stateStr": "PRIMARY"
"uptime": 1370
"optime": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
OptimeDate: ISODate ("2019-10-10T13:16:16Z")
ElectionTime: Timestamp (1570713059, 1)
ElectionDate: ISODate ("2019-10-10T13:10:59Z")
"configVersion": 28
"self": true
}
{
"_ id": 6
"name": "127.0.0.1 purl 4777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
Uptime: 514
"optime": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
"optimeDurable": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
OptimeDate: ISODate ("2019-10-10T13:16:16Z")
OptimeDurableDate: ISODate ("2019-10-10T13:16:16Z")
LastHeartbeat: ISODate ("2019-10-10T13:16:28.911Z")
LastHeartbeatRecv: ISODate ("2019-10-10T13:16:26.912Z")
"pingMs": NumberLong (0)
"configVersion": 28
}
{
"_ id": 7
"name": "127.0.0.1 purl 5777"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 11
"optime": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
"optimeDurable": {
Ts: Timestamp (1570713376, 1)
"t": NumberLong (5)
}
OptimeDate: ISODate ("2019-10-10T13:16:16Z")
OptimeDurableDate: ISODate ("2019-10-10T13:16:16Z")
LastHeartbeat: ISODate ("2019-10-10T13:16:28.911Z")
LastHeartbeatRecv: ISODate ("2019-10-10T13:16:27.075Z")
"pingMs": NumberLong (0)
"configVersion": 28
}
]
"ok": 1
}
Insert data in Primary and Secondary on all ports to test whether the data is normal
Shard1:PRIMARY > db.movie.insert ({"shouyue": "yunweibu"})
WriteResult ({"nInserted": 1})
Shard1:PRIMARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
{"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
{"_ id": ObjectId ("5d9f2fa0b384f3ba8df3a0ce"), "shouyue": "yunweibu"} # check whether each port has this data
Port 2777:
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 2777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:2777/
MongoDB server version: 3.4.6
Shard1:SECONDARY > show dbs
2019-10-10T21:19:51.176+0800 E QUERY [thread1] Error: listDatabases failed: {
"ok": 0
"errmsg": "not master and slaveOk=false"
"code": 13435
"codeName": "NotMasterNoSlaveOk"
}:
_ getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
ShellHelper.show@src/mongo/shell/utils.js:769:19
ShellHelper@src/mongo/shell/utils.js:659:15
@ (shellhelp2): 1:1
Shard1:SECONDARY > rs.slaveOk ()
Shard1:SECONDARY > use yoon
Switched to db yoon
Shard1:SECONDARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
{"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
{"_ id": ObjectId ("5d9f2fa0b384f3ba8df3a0ce"), "shouyue": "yunweibu"}
Port 4777:
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 4777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:4777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten]
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten]
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten]
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-10T21:07:05.390+0800 I CONTROL [initandlisten]
Shard1:SECONDARY > rs.slaveOk ()
Shard1:SECONDARY > use yoon
Switched to db yoon
Shard1:SECONDARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
{"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
{"_ id": ObjectId ("5d9f2fa0b384f3ba8df3a0ce"), "shouyue": "yunweibu"}
Port 5777:
[root@127.0.0.1 bin] # / opt/mongodb_3_4/bin/mongo-- port 5777
MongoDB shell version v3.4.6
Connecting to: mongodb://127.0.0.1:5777/
MongoDB server version: 3.4.6
Server has startup warnings:
2019-10-10T21:15:35.059+0800 I CONTROL [initandlisten]
2019-10-10T21:15:35.059+0800 I CONTROL [initandlisten] * * WARNING: Access control is not enabled for the database.
2019-10-10T21:15:35.059+0800 I CONTROL [initandlisten] * * Read and write access to data and configuration is unrestricted.
2019-10-10T21:15:35.059+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
2019-10-10T21:15:35.059+0800 I CONTROL [initandlisten]
2019-10-10T21:15:35.060+0800 I CONTROL [initandlisten]
2019-10-10T21:15:35.060+0800 I CONTROL [initandlisten] * * WARNING: You are running on a NUMA machine.
2019-10-10T21:15:35.060+0800 I CONTROL [initandlisten] * * We suggest launching mongod like this to avoid performance problems:
2019-10-10T21:15:35.060+0800 I CONTROL [initandlisten] * * numactl-- interleave=all mongod [other options]
2019-10-10T21:15:35.060+0800 I CONTROL [initandlisten]
Shard1:SECONDARY > rs.slaveOk ()
Shard1:SECONDARY > use yoon
Switched to db yoon
Shard1:SECONDARY > db.movie.find ()
{"_ id": ObjectId ("5d9c7ee9d7a8df8fd023d6ed"), "name": "hank"}
{"_ id": ObjectId ("5d9d9d5d159fa59c5d01985a"), "hname": "yoon"}
{"_ id": ObjectId ("5d9d9e33159fa59c5d01985b"), "yname": "hankyoon"}
{"_ id": ObjectId ("5d9f2aacdaabe0e11aebef86"), "kname": "shouqi"}
{"_ id": ObjectId ("5d9f2fa0b384f3ba8df3a0ce"), "shouyue": "yunweibu"}
Upgrade from MongoDB3.2 to 3.4.6 is complete.
But the real upgrade online needs to be developed and tested to ensure the availability of the upgrade.
After reading the above, have you mastered how to upgrade MongoDB3.2 to 3.4.6? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.