mongodb 升级mongodb

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9757925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:32:45  来源:igfitidea点击:

upgrade mongodb

mongodbupgrade

提问by Liatz

I'm looking for the easiest and the most recommended way to upgrade mongodb version (standalone server and mongodb shell).

我正在寻找升级 mongodb 版本(独立服务器和 mongodb shell)的最简单和最推荐的方法。

Are there any terminal (for mac) commands that i can follow in order to upgrade?

是否有任何我可以遵循的终端(对于 mac)命令来升级?

I tried to stop the server by $ mongo

我试图通过 $ mongo 停止服务器

use admin db.shutdownServer()
i get : Sat Mar 17 20:38:15 DBClientCursor::init call() failed Sat Mar 17 20:38:15 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:27017 server should be down... Sat Mar 17 20:38:15 trying reconnect to 127.0.0.1:27017 Sat Mar 17 20:38:15 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017

使用 admin db.shutdownServer()
我得到:Sat Mar 17 20:38:15 DBClientCursor::init call() failed Sat Mar 17 20:38:15 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0. 0.1:27017 服务器应该关闭... Sat Mar 17 20:38:15 尝试重新连接到 127.0.0.1:27017 Sat Mar 17 20:38:15 reconnect 127.0.0.1:27017 失败无法连接到服务器 127.0。 :27017

I understand that after stopping the server i need to change the bin folder of mongodb. (which i'm failing to do because mongo is in use)

我知道在停止服务器后我需要更改 mongodb 的 bin 文件夹。(我没能做到,因为 mongo 正在使用中)

If someone knows an easier way to only upgrade the mongodb version i would really thank him/her! thank you.

如果有人知道只升级 mongodb 版本的更简单方法,我真的会感谢他/她!谢谢你。

采纳答案by mrohnstock

shutdown mongodb with:

使用以下命令关闭 mongodb:

/usr/bin/mongodb --config $PATH-TO-CONFIG --shutdown

(replace /usr/bin with the right directory) copy new mongodb and restart mongodb afterwards.

(将 /usr/bin 替换为正确的目录)复制新的 mongodb,然后重新启动 mongodb。

回答by nelsonic

To Upgrade MongoDBon Ubuntu

升级的MongoDB的Ubuntu

First, Backup your datausing Mongoexport

首先,使用Mongoexport备份您的数据

e.g:

例如:

mongoexport --db sales --collection contacts --out contacts.json --journal

Then check which version of MongoDB you are running by issuing the command:

然后通过发出以下命令检查您正在运行的 MongoDB 版本:

$ mongod --version

db version v1.8.2, pdfile version 4.5 - Wed Oct 24 15:43:13 git version: nogitversion

$ mongod --version

db version v1.8.2, pdfile version 4.5 - Wed Oct 24 15:43:13 git version: nogitversion

Confirmif mongo is currently running:

确认mongo 当前是否正在运行:

$ ps -deaf | grep mongod

mongodb 154081 0 Jun06 ? 13:50:00 /usr/bin/mongod --config /etc/mongodb.conf

$ ps -聋| grep mongod

mongodb 154081 0 Jun06 ? 13:50:00 /usr/bin/mongod --config /etc/mongodb.conf

To Shutdown MongoDB

关机的MongoDB

$ ./mongo

> use admin

> db.shutdownServer()

server should be down...

$ ./mongo

> 使用管理员

> db.shutdownServer()

服务器应该挂了...

Then upgraded following these instructions: How to Install MongoDB on Ubuntu

然后按照以下说明进行升级:如何在 Ubuntu 上安装 MongoDB

Add the 10 Gen (creators of MongoDB) public key to apt-get so you trust their package:

将第 10 代(MongoDB 的创建者)公钥添加到 apt-get,以便您信任他们的包:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

$ echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstartdist 10gen" >> /etc/apt/sources.list.d/10gen.list

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

$ echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstartdist 10gen" >> /etc/apt/sources.list.d/10gen.list

Update your packages:

更新您的软件包:

$ sudo apt-get update

$ sudo apt-get 更新

install 10gen's MongoDB Debian/Ubuntu package:

安装 10gen 的 MongoDB Debian/Ubuntu 包:

$ sudo apt-get install mongodb-10gen

The following packages will be REMOVED: mongodb

The following NEWpackages will be installed: mongodb-10gen

$ sudo apt-get install mongodb-10gen

以下包将被删除mongodb

将安装以下软件包: mongodb-10gen

If you get an error, try:

如果出现错误,请尝试:

$ apt-get autoremove

$ apt-get autoremove

Confirm that the mongodbuser/group has permission to write to the data directory:

确认mongodb用户/组有写入数据目录的权限:

$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.

$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.

Start up MongoDB as a Daemon(background process) using the following command:

使用以下命令将 MongoDB作为守护程序(后台进程)启动:

$ mongod --fork --dbpath /var/lib/mongodb/ --smallfiles --logpath /var/log/mongodb.log --logappend

$ mongod --fork --dbpath /var/lib/mongodb/ --smallfiles --logpath /var/log/mongodb.log --logappend

To Shut Down MongoDBenter the Mongo CLI, access the admin and issue the shutdown command:

关闭 MongoDB,请进入 Mongo CLI,访问管理员并发出关闭命令:

$ ./mongo

> use admin

> db.shutdownServer()

$ ./mongo

> 使用管理员

> db.shutdownServer()

回答by golja

Depends on the version upgrade, but usually if it's a major upgrade (example from 1.8.xx to 2.0.XX) you should do at least the following steps:

取决于版本升级,但通常如果是重大升级(例如从 1.8.xx 到 2.0.XX),您至少应该执行以下步骤:

  • backup your data (mongoexport or check this MongoDB backup documentation)
  • stop the server (use admin db.shutdownServer() )
  • copy or symbolic link the new mongodb binaries
  • run mongod with the --upgrade flag (mongod - f --upgrade)
  • when upgrade done, restart the mongod server
  • 备份您的数据(mongoexport 或查看此MongoDB 备份文档
  • 停止服务器(使用 admin db.shutdownServer() )
  • 复制或符号链接新的 mongodb 二进制文件
  • 使用 --upgrade 标志运行 mongod (mongod - f --upgrade)
  • 升级完成后,重启 mongod 服务器

After that make sure that everything is working properly. If not switch back to the old version, import the data from the backup and check mongoDB jira:)

之后确保一切正常。如果没有切换回旧版本,请从备份中导入数据并检查mongoDB jira:)

回答by frostcs

1.Import the public key used by the package management system

1.导入包管理系统使用的公钥

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

2. Create a list file for MongoDB.

2. 为 MongoDB 创建一个列表文件。

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstartdist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstartdist 10gen' | 须藤三通/etc/apt/sources.list.d/mongodb.list

3. Reload local package database.sudo apt-get update

3. 重新加载本地包数据库。sudo apt-get 更新

4. stop the existing servicesudo service mongodb stop

4. 停止现有服务sudo service mongodb stop

5. first migrate to 2.4 to 2.6Install a specific release of MongoDB

5.先迁移到2.4到2.6安装特定版本的MongoDB

sudo apt-get install -y mongodb-org=2.6.12 mongodb-org-server=2.6.12 mongodb-org-shell=2.6.12 mongodb-org-mongos=2.6.12 mongodb-org-tools=2.6.12

sudo apt-get install -y mongodb-org=2.6.12 mongodb-org-server=2.6.12 mongodb-org-shell=2.6.12 mongodb-org-mongos=2.6.12 mongodb-org-tools=2.6.12

6.unlink the temp linksremove the lock file. rm /tmp/mongodb-27017.sock

6.unlink临时链接删除锁定文件。rm /tmp/mongodb-27017.sock

7.restart mongo servicesudo service mongodb restart

7.restart mongo servicesudo service mongodb restart

8. Now finally migrate from 2.6 to 3.0sudo apt-get install -y mongodb-org=3.0.12 mongodb-org-server=3.0.12 mongodb-org-shell=3.0.12 mongodb-org-mongos=3.0.12 mongodb-org-tools=3.0.12

8. 现在终于从 2.6 迁移到 3.0sudo apt-get install -y mongodb-org=3.0.12 mongodb-org-server=3.0.12 mongodb-org-shell=3.0.12 mongodb-org-mongos=3.0.12 mongodb-org-tools=3.0.12

restart again and voila !!!!

再次重新启动,瞧!!!!

For more details follow the official documentation: mongo doc

有关更多详细信息,请参阅官方文档: mongo doc

回答by kris

To upgrade from version 2 to version 3

从版本 2 升级到版本 3

I was unsuccessful using the methods in the other answers here, and was finally successful when following the offical document's "Upgrade Binaries" approach, like so:

我在这里使用其他答案中的方法没有成功,并且在遵循官方文档的“升级二进制文件”方法时终于成功了,如下所示:

  1. Stop mongo from running:

    $ sudo service mongod stop

  2. Download the correct binaries

    (from here, and for help getting the correct version see this answer)

  3. Copy the downloaded binaries over:

    $ sudo cp downloaded_binaries/bin/* /usr/bin

  4. Restart mongo:

    $ sudo service mongod start

  1. 停止 mongo 运行

    $ sudo service mongod stop

  2. 下载正确的二进制文件

    (从这里开始,有关获取正确版本的帮助,请参阅此答案

  3. 将下载的二进制文件复制到

    $ sudo cp downloaded_binaries/bin/* /usr/bin

  4. 重启蒙戈

    $ sudo service mongod start