Install MongoDB.

Source: Internet
Author: User
Tags gpg install mongodb

1. Install MongoDB. 1. Import the public key for the package management system.

Ubuntu software package management tool to ensure package consistency and reliability requires a GPG key to verify the package. Use the following command to import MongoDB GPG key (MongoDB public GPG key Http://docs.mongodb.org/10gen-gpg-key.asc) _:

sudoapt-keyadv--keyserverhkp://keyserver.ubuntu.com:80--recvEA312927

2. Create a list file for MongoDB

Use the following command to create a/etc/apt/sources.list.d/mongodb.list list file
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

3. Reload the package database.

Use the following command to reload the local package database:

sudo apt-get update

4. Install the MongoDB software package.

You can install the latest stable version of MongoDB or the specified version of MongoDB.
Install the latest stable version of MongoDB.
Use the following command:

sudo apt-get install-y mongodb-org


If you want to install the specified version of MongoDB, follow the methods below.
The following example installs the 3.2.0 version of MongoDB:
Different components of MongoDB can specify the corresponding version number

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

Running MongoDB
    • MongoDB default data files and log files are stored in the following location
      Data file:/var/lib/mongodb
      Log file:/var/log/mongodb
      You can modify the/etc/mongod.conf file to change the appropriate storage location.

    • If you want to change the user running MongoDB, you must pay the user access to the/VAR/LIB/MONGODB and/var/log/mongodb 2 directories.

1. Start MongoDB.

Use the following command to start the Mongod process.

sudo service Mongod start

2. Check if MongoDB started successfully

Determine whether the Mongod process has started successfully by examining the/var/log/mongodb/mongod.log file.
or view the process

Ps-ef | grep Mongod

3. Stop MongoDB

sudo service Mongod stop

4. Restart MongoDB

sudo service mongod restart

3. Uninstalling MongoDB
    • If you want to completely uninstall MongoDB in your system, you must uninstall the MongoDB program files, configuration files, and all the files and folders that contain the data and logs. Below I will demonstrate how to completely uninstall MongoDB
1. Stop MongoDB

Use the following name to stop the MongoDB daemon:

sudo service Mongod stop

2. Removal of MongoDB Program Files

Remove all of your previous MongoDB installation packages:

sudo apt-get purge mongodb-org*

3. Delete the directory of data and log files

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

This article refers to the official MongoDB installation documentation, if interested students can refer to the original official documents, the address is as follows:
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
Thank you ~ ~

4. Create user and Remote Access 4.1 create Administrator
db.createUser({user: "root",pwd: "root",roles: [ "readWrite", "dbAdmin" ]});
4.2 Modifying a bound IP

Vi/etc/mongod.conf
Comment out

#bindIp: 127.0.0.1 
4.3: restart
service mongod restart
4.4: Open port
-A-p-m--NEW-m--27017-j
5. Change the data storage and log path of MongoDB

Since MongoDB installation is complete, data files and log files are stored in the system disk (data file:/var/lib/mongodb log file:/var/log/mongodb), need to modify the next directory, need to change to the data disk, The error that prevents the system disk from being too large caused by the volume of data.

5.1 Create a separate folder in the data disk

The data disk for my system is/data

Cd/data
mkdir Mongodbfile
CD Mongodbfile

5.2 Creating a data file storage directory

mkdir data

5.3 Creating a log file storage directory

mkdir Log

5.4 Creating a Startup file

VI mongod.conf

Add the following file

# mongod.conf# for documentation of all options, see:#   http://docs.mongodb.org/manual/reference/configuration-options/# Where and how to store data.storage:  dbPath: /data/mongodbfile/data  journal:    truesystemLog:  destination: file  true  path: /data/mongodbfile/log/mongod.log# network interfacesnet:  27017  127.0.0.1

If you are an empty library, it is not involved in the data migration, directly to keep the database directory and log directory is empty, if the original data, please copy all the files of the original and log directory.

5.5 Starting the Service

Start the MongoDB service as a background process based on the configuration file

Mongod-f/data/mongodbfile/mongod.conf &

Exit terminal

Exit

MongoDB service is working properly.

Install MongoDB.

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.