Install MongoDB on Linux

Source: Internet
Author: User
Tags install mongodb

Install MongoDB on Linux

Install MongoDB on Linux.

1. Download the installation package and decompress tgz (the installation on 64-bit Linux is demonstrated below ).

Curl-O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # download tar-zxvf mongodb-linux-x86_64-3.0.6.tgz # unzip mv mongodb-linux-x86_64-3.0.6 // usr/local/mongodb # copy the package to the specified directory

 

2. the executable file of MongoDB is located in the bin directory, so you can add it to the PATH:

  export PATH=<mongodb-install-directory>/bin:$PATH

<Mongodb-install-directory> is the MongoDB installation path. For example,/usr/local/mongodb in this article.

 

3. Create a database directory

MongoDB data is stored in the db directory of the data directory, but this directory is not automatically created during the installation process. Therefore, you need to manually create the data DIRECTORY and create a db directory in the data directory. In the following example, we create the data directory under the root directory (/).

Note:/data/db is the default database path (-- dbpath) started by MongoDB ).

    mkdir -p /data/db

4. Run the MongoDB service in the command line

① You can run the following command in the/usr/local/mongodb/bin/directory:

    ./mongod

② Add the conf directory under/usr/local/mongodb/and add the mongodb. conf configuration file.

./Mongod-f/usr/local/mongodb/conf/mongodb. conf or
./Mongod -- config/usr/local/mongodb/conf/mongodb. conf

Mongodb. conf
The configuration file is as follows:
Dbpath =/data/db
Bind_ip = 127.0.0.1
Port = 27017
Fork = true
Master = true
Verbose = true
Vvvv = true
MaxConns = 100
Objcheck = true
Logappend = true
Shardsvr = true
Directoryperdb = true
Logpath =/usr/local/mongodb/log/mongodb. log

5. Set mongo to start upon startup

Method 1. ① Add the mongod script in the/etc/init. d/directory,

② Add the script execution permission chmod + x/etc/init. d/mongod

③ Set chkconfig startup on

      MongoThe script content is as follows:

#! /Bin/bash

# Chkconfig: 2345 80 90

# Description: mongodb
Start (){
/Usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/mongodb. conf
}

Stop (){
/Usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/mongodb. conf -- shutdown
}

Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Stop
Start
;;
*)
Echo $ "Usage: $0 {start | stop | restart }"
Exit 1
Esac

Method 2:/Usr/local/mongodb/bin/mongod

-- Dbpath/data/db

-- Fork

-- Port 27017

-- Logpath =/usr/local/mongodb/log/mongodb. log

-- Logappend 

        Add/Etc/rc. localMedium.

For more MongoDB tutorials, see the following:

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

MongoDB beginners must read (both concepts and practices)

MongoDB Installation Guide for Ubunu 14.04

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

Nagios monitoring MongoDB sharded cluster service practice

Build MongoDB Service Based on CentOS 6.5 Operating System

MongoDB details: click here
MongoDB: click here

This article permanently updates the link address:

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.