upgrade mongodb

蹲街弑〆低调 提交于 2019-12-02 17:11:24

shutdown mongodb with:

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

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

To Upgrade MongoDB on Ubuntu

First, Backup your data using 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:

$ mongod --version

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

Confirm if mongo is currently running:

$ ps -deaf | grep mongod

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

To Shutdown MongoDB

$ ./mongo

> use admin

> db.shutdownServer()

server should be down...

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

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

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

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

Update your packages:

$ sudo apt-get update

install 10gen's MongoDB Debian/Ubuntu package:

$ sudo apt-get install mongodb-10gen

The following packages will be REMOVED: mongodb

The following NEW packages will be installed: mongodb-10gen

If you get an error, try:

$ apt-get autoremove

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

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

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

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

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

$ ./mongo

> use admin

> db.shutdownServer()

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:

  • 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

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 :)

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

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

2. Create a list file for MongoDB.

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

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

4. stop the existing service sudo service mongodb stop

5. first migrate to 2.4 to 2.6 Install a specific release of 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

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

7.restart mongo service sudo service mongodb restart

8. Now finally migrate from 2.6 to 3.0 sudo 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

kris

To upgrade from version 2 to version 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!