NoSQL Mongodb--ubuntu Installation

Source: Internet
Author: User
Tags gpg install mongodb



MongoDB only offers a 64-bit lts (long-term support) version of Ubuntu packages. For example, 12.04 lts,14.04 lts,16.04 LTS and so on.


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


Ubuntu Package management Tools (for example: dpkg and apt) require resellers to use GPG keys to sign packages to ensure the consistency and authenticity of the scenario. Use the following command to import the MongoDB public GPG key.



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


MongoDB Public gpg key content:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.11 (GNU/Linux)

mQINBFYYLZUBEADTvHI/DDlJY4JCLh7chtQiKkj8kFpqOtY4x6luOQWvYNXfvso1
yoKqKnU33Fh3JY4dWClXzv40PcVH4pIi95enzCLGvU30GNDsfmueV9vkq5HrCMMZ
rQ1M9/4HgrnbRvLhvcb4VY+RELEdcHWhUkYTpG00YuEHdgJ3PoPL5pDu1L1z/MwE
TVwCr63kl2HhgzqtpaXC00hbLSN/+GD3guCrIJy8Gfz6yfgpmCxr5KyOG2fdRoZL
mRKNzMdSua+bLeTM8BXqJpSB8BBsBSbnNuCLZdZhhSm4P7SUSrPoSRRzEMDwzv6e
1JqJqVaiApBoSX+elUzoYrglSkaPqWiT6kzlWw7ZOTTqKkojQftYGOvDYdvSKq0z
e8QzA/22FmDKzurBpv7Tus9VV+yMlxTCVGtb74u8j6pRO2jxs9w6Ur2CfQJgddtN
wbiIKWI1F7//YDSJncJRfW19cnOyrOqiNoPQqsF+YFexEy4wSs94eQ3EfBzbYjSt
EtJVSV5HCjJtIZjOxRJnyN8ZZZCPwhizvU+zGcCiAi0bwcur9kti+bnIbYCTURFy
WCLHM09HNCYg5ZBCa+6+ZDiOs+Y3sjs+Dzrrt3eAh+ny53BSBS+MlZ2CtvJZdjMu
JBAN2haiMYtaVIgmnfzfPZDJ1mZag/lGy++lufSQNJDPfVqVRlj17SG6kwARAQAB
tDdNb25nb0RCIDMuMiBSZWxlYXNlIFNpZ25pbmcgS2V5IDxwYWNrYWdpbmdAbW9u
Z29kYi5jb20+iQI+BBMBAgAoBQJWGC2VAhsDBQkDwmcABgsJCAcDAgYVCAIJCgsE
FgIDAQIeAQIXgAAKCRDWj6UP6jEpJ8KPD/9ZMK86x0ZNPK6PrJ4mmc7TVYzl9/Fb
PThLIvX/f1pUcUiLha0+TC7pYw8vWtl2iiOfAWI2bzPcQ6qrxo2wEvEE27ApL9PU
hbaUA0C/3BQzVwCojKka8If1GIf8dJVpxeai7Mcsx2vf+0svvoMvFOrTK5G2AnyH
MAY0Ko4Mw/1D/gFO1DjO90S8H6yvA0hapjwYQ8Tul0/u4wBjTRd3SNaoNnx9zcqD
evAmrDjNHDAr3WXhDlYCnciHQoqI+XUgnFMA+3zY0YczSGAU1aeUUj9F6Wr5fOlN
4pvzIaI+dQL/K9lY/2GgXEATRTuHYFZxT7gl7V6Su9wNVEBqTRkpnoGpxh1OQuRv
SHIRD9GAcP9eTD4AknvfEDbe/Hvqf9gDErGNEjy31hxSjZ5gl7WOJZw0rftlw0GN
pPmKiuT54kwUrluxtAXey9JaQ2ifomZByrxczWpIXSAi8G4ljiyJVkohmotbEiXh
PAYNtxWf0y57EQ6DO1d8yGv4BiB08YtrqaH/cFpNtRTgvajJm5iW55yb4v1Inf4d
9f7j9cQmFufJMtOMiF8/yDiFeOBkSfJXjx3+of4pXLIAuMbX95RWuAa7FOvL7xrs
RDhdohAjLyyBRcJBv8yQ9BYXOekWGIiTbhUW9L1ySkpdQ8+2QOKxOgK4Yl0psMPn
YXy2T09NgATr0A==
=8Qhy
-----END PGP PUBLIC KEY BLOCK-----




2. Create a MongoDB list file


Select the following command for different versions to create the/etc/apt/sources.list.d/mongodb-org-3.2.list listfile:



Ubuntu 12.04:



" Deb Http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 Multiverse " | sudo tee/etc/apt/sources.list.d/mongodb-org-3.2. List


Ubuntu 14.04:



" Deb Http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 Multiverse " | sudo tee/etc/apt/sources.list.d/mongodb-org-3.2. List


Ubuntu 16.04:



" Deb Http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Multiverse " | sudo tee/etc/apt/sources.list.d/mongodb-org-3.2. List
3. Reload the package database


Issue the following command to reload the local package database:



sudo apt-get update
4. Install MongoDB Package Packages


You can install the latest stable version of MongoDB or a specific version of MongoDB.


4.1 Installing MongoDB Latest stable version

sudo apt-get install-y mongodb-org
4.2 Installing MongoDB Specific Version


To install a specific version, you must specify each component package separately with the version number, as an example:



sudo apt-get install-y mongodb-org=3.2. 9 mongodb-org-server=3.2. 9 mongodb-org-shell=3.2. 9 mongodb-org-mongos=3.2. 9 mongodb-org-tools=3.2. 9


If you only install mongodb-org = 3.2.9, do not include component packages, regardless of the version you specify will install the latest version of each MongoDB package.



Although you can specify any version that is available for MongoDB, Apt-get will upgrade the package when a new version of the package is available. To prevent accidental escalation of packages, a fixed (Pin) package is required. The following commands are implemented:



echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
5. Create a system service file (for Ubuntu 16.04)


Under/lib/systemd/system/mongod.service, create a Mongod.service file with the following content:



 
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual  [Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target


To use root permissions here, you can first create a mongod.service file with the above content on the desktop and then use the console's MV command to move to the specified folder:



mv/home/wangchao/Desktop/mongod.service/lib/systemd/system
6. Running MongoDB


The MongoDB instance is stored by default in its data file/var/lib/mongodb and log file/var/log/mongodb, using MongoDB user account to run MongoDB. You can specify the replacement log and data file directory through the/etc/mongod.conf file. If you want to switch users to run MongoDB processes, you must enable these users to gain access to the/var/lib/mongodband/var/log/mongodb directories.


6.1Start MongoDB

sudo service Mongod start
6.2Stop MongoDB

sudo service Mongod stop
6.3Restart MongoDB

sudo service mongod restart
7. Uninstall Mongodb7.1stop MongoDB

sudo service Mongod stop
7.2Remove Packages

sudo apt-get purge mongodb-org*
7.3Remove Data Directories

sudo rm-r/var/log/-R/var/lib/mongodb





Original link: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/



Reference link: https://docs.mongodb.com/manual/#getting-started



This article link: http://www.cnblogs.com/homewch/p/5781769.html



NoSQL Mongodb--ubuntu Installation


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.