Add by Zhj: directly from the fourth step can be, and after the installation of MongoDB will automatically start, do not have to execute the start command
Original: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
I. Overview
With this tutorial, we can install the MongoDB Community Edition on Lts Ubuntu with the. Deb package. Although Ubuntu has its own MongoDB package, the official MongoDB Community Edition usually needs to be updated.
Note: Platform support
MongoDB only provides installation packages for 64-bit lts ubuntu, such as 12.04 lts (precise), 14.04 lts (trusty), 16.04 Lts (xenial), etc. These packages may be installed in other Ubuntu
Version also works well, but MongoDB does not support these versions of Ubuntu.
Two. installation package
MongoDB offers an officially supported installation package in its own library that contains the following packages
mongodb-org |
Wenbao (Metapackage), the following four package packages are installed automatically |
Mongodb-org-server |
Contains the mongod daemon and associated configuration and init scripts. |
Mongodb-org-mongos |
Contains the mongos daemon. |
Mongodb-org-shell |
Contains the MONGO shell. |
mongodb-org-tools |
Contains the following MongoDB tools: mongoimport bsondump , mongodump , mongoexport ,  mongofiles , mongooplog , mongoperf , mongorestore , mongostat , and mongotop . |
These packages are conflicting with Ubuntu's own MongoDB, Mongodb-server, and mongodb-clients packages.
In profile/etc/mongod.conf, the default value for Bind_ip is 127.0.0.1, and you need to modify it to suit your environment before initializing the replica set
Three. Init script
Slightly
Four. Install MongoDB Community Edition
Note: If you want to install a version prior to 3.2, see the installation tutorial for a specific version, such as version 3.0 of the installation tutorial is 3.0.
1. The public key required to import the package management system
The command is as follows
sudo apt-key adv--keyserver HKP://keyserver.ubuntu.com:80--recv EA312927
2. Create a list file for MongoDB
To create a/etc/apt/sources.list.d/mongodb-org-3.2.list file, use the following command
Ubuntu 12.04
Echo " 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
Echo " 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
Echo " 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. Update the local package database
sudo apt-get update
4. Installing the MongoDB Package
You can install the latest stable version, or you can install a specific version of MongoDB
Install the latest stable version
Execute the following command, after the installation is complete, will automatically start the MongoDB
sudo Install -y mongodb-org
Install a specific version
To install the specified version, you must specify the version number for each component package, as follows
sudo Install -y mongodb-org=3.2. Ten mongodb-org-server=3.2. Ten mongodb-org-shell=3.2. Ten mongodb-org-mongos=3.2. Ten mongodb-org-tools=3.2. Ten
If you only specify mongodb-org=3.2.10 when you install, and you do not specify the version of those package packages, those packages are installed with the latest version of
5. (Ubuntu 16.04-only) Create systemd service file
Slightly
Five. Running MongoDB
The default, MongoDB data files and log file directories are as follows, and you can modify both directories in the configuration file/etc/mongod.conf.
MongoDB is running as the user MongoDB, if you want to use other users to start the MongoDB process, it should also modify the data file directory and log file directory permissions, so that the user can access the two directories
Additional information parameters Systemlog.path and Storage.dbpath
Default data file directory
/var/lib/mongodb
Default log file directory
/var/log/mongodb
1. Start MongoDB
sudo service mongod start
2. Confirm that MongoDB has started successfully
The flag for MongoDB boot success is the following print in log file/var/log/mongodb/mongod.log, where <port> is the port configured in profile/etc/mongod.conf, default is 27017
for connections on port <port>
3. Stop MongoDB
sudo service mongod stop
4. Restart MongoDB
sudo service mongod restart
5. Start using MongoDB
To the start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See Getting Started for the available editions.
Before deploying MongoDB in a production environment, consider the production Notes document.
Later, to-stop MongoDB, press control+c in the terminal where the Mongod instance is running.
Six. Uninstalling MongoDB
Slightly
Install MongoDB on Ubuntu (translate)