当前位置: 首页 > 工具软件 > 升级树 > 使用案例 >

mongodb升级详细教程 - 3.2~4.4

许俊晤
2023-12-01

mongodb的稳定版本全部为偶数,例如:4.0、4.2

mongoDB的升级必须是相邻版本升级,不能跳版本升级。例如:3.2->3.4->3.6,不能3.2直接升级3.6,这是因为相邻版本会有兼容,如果跳版本升级很容易出问题。

下载mongodb程序

请到官网下载各个版本的程序包

解压

tar -xf mongodb-linux-x86_64-3.4.24.tgz 

配置文件

mongodb启动配置文件属性说明

# 数据文件位置
dbpath = /opt/module/mongoData

# 日志文件位置
logpath = /opt/module/mongoLog/mongodb.log

# 以追加方式写入日志,true为追加。false是覆盖
logappend = true

# 日志输出都发送到主机的syslog系统,而不是标准输出到logpath指定日志文件。syslog和logpath不能一起用,会报错:Cant use both a logpath and syslog
# syslog = true

#绑定地址。默认127.0.0.1,只能通过本地连接。进程绑定和监听来自这个地址上的应用连接。要是需要给其他服务器连接,则需要注释掉这个或则 把IP改成本机地址,
# 如192.168.200.201[其他服务器用 mongo --host=192.168.200.201 连接] ,可以用一个逗号分隔的列表绑定多个IP地址。
bind_ip = 192.168.1.10
# 默认端口27017
port = 27017

# 是否后台运行,设置为true 启动 进程在后台运行的守护进程模式。默认false。
fork = true

# 安静模式。这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
quiet = false

# 启用日志文件,默认启用
journal = true

停止正在运行的mongodb

[root@KELL ~]# kill 26181;

启动新版本的mongodb

[root@localhost bin]# ./mongod -f /home/mongodb/mongo.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 628
child process started successfully, parent exiting

命令行连接mongodb

[root@localhost bin]# ./mongo 192.168.1.10
MongoDB shell version v3.4.24
connecting to: mongodb://192.168.1.10:27017/test
MongoDB server version: 3.4.24
Server has startup warnings: 
2020-10-16T16:58:42.836+0800 I CONTROL  [initandlisten] 
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] 
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] 
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] 
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-10-16T16:58:42.838+0800 I CONTROL  [initandlisten] 
> 

更新新版本数据文件:

> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : "3.2", "ok" : 1 } #查看兼容性版本
> db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )  #修改兼容性版本
{ "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : "3.4", "ok" : 1 }

重复执行上面的步骤到最新版本

包括下载、解压、运行新版本的程序。

下面是每个包运行后最后一步的输出:

> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "3.4" }, "ok" : 1 }
> db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } ) 
{ "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "3.6" }, "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "3.6" }, "ok" : 1 }
> db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )
{ "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "4.0" }, "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "4.0" }, "ok" : 1 }
> db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )
{ "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "4.2" }, "ok" : 1 }

> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "4.2" }, "ok" : 1 }
> db.adminCommand( { setFeatureCompatibilityVersion: "4.4" } )
{ "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "4.4" }, "ok" : 1 }

完成

 类似资料: