MongoDB Download + install + Run

Source: Internet
Author: User
Tags auth brew install mongodb chmod curl install mongodb mkdir mongodb commands mongodb download

One. Download and install the website

MongoDB offers a 64-bit installation package on the OSX platform, which you can download on the website.
: MongoDB website-community Server

Select the appropriate version for your platform and download the corresponding installation file
The version I downloaded is:mongodb-osx-ssl-x86_64-3.6.5.tgz

// 从 MongoDB 3.0 版本开始只支持 OS X 10.7 (Lion) 版本及更新版本的系统。

MongoDB Installation: (The following installation operations are done in the terminal)

1. Select Fit and Table of contents

Since this is a native installation, I chose/usr/local

/usr/local
2. Create a directory for MongoDB
mkdir mongodb
3. Move or copy the downloaded installation package to the MongoDB directory

(The path is for reference only, this is the author's development path, does not represent the reader development machine Path)

cp /User/Apple/Download/mongodb-osx-ssl-x86_64-3.4.2.tgz /usr/local/mongodb
4. Unzip the package (will get an extract directory in the MongoDB directory)
tar zxf mongodb-osx-ssl-x86_64-3.4.2.tgz
5. Add environment variables for MONGODB commands
vim ~/.bash_profile //打开用户的配置进行编辑

Copy and paste the following code into the. bash_profile file (the function is to add an environment variable for the command under Mongodb/bin so that you do not need to enter the path again each time you use the MONGO command)

#mongoexport MONGO_PATH=/usr/local/mongodb/mongodb-osx-x86_64-3.4.2export PATH=$PATH:$MONGO_PATH/bin

Exit Save

:wq

Reload the resource file

source ~/.bash_profile

Use the source command to make the command you just configured take effect

1. Each time you open a terminal, you need to reload the. bash_profile file with the source command in order for the configuration to take effect (if you want to fix it, paste the configuration into the root user profile, please Baidu)

2. If the reader is not found. Bash_profile Please use the command touch ~/.bash_profile to create a profile file, paste it in

6. Create a database directory for MongoDB (necessary, because MongoDB services cannot start if the directory does not exist)
mkdir -p /User/Apple/mongodb/data/db

Here's why to create it here:

As the author often uses the ordinary user identity, unless necessary, otherwise rarely switch to root identity, so, create in the/user/apple directory will be exempt every start mongodb use the sudo command to enter the password trouble (mac switch to root command: sudo su, Enter your password)
Because the real development, are directly using the domain name and port to connect to the server, so there is no need to create/data/db directory in the root directory, installed on this machine only for their own learning, so, in the future when you can safely delete/user/apple/mongodb directory

Otherwise, you need to change permissions:

chmod -R 777 /opt/soft/mongo/

Chmod can change the permissions,-R is the directory of all files, 777 is the high privilege (read, write, execute)
Chmod-r 777 * Means to give 777 permissions to all files in the current directory

7. Add the MONGO configuration file
mkdir /User/Apple/mongodb/etccd&&touch mongod.conf
#mongodb config filedbpath=/opt/soft/mongo/mongodb-osx-x86_64-3.6.2/data/dblogpath=/opt/soft/mongo/mongodb-osx-x86_64-3.6.2/logs/mongodb/mongod.loglogappend = truebind_ip = 127.0.0.1journal=trueport = 27017# fork允许后端子进程启动,终端可以随便关fork = true# 安全权限,可以先以非授权模式启动Mongod,添加完用户db.addUser(‘root‘,‘pwd‘) ,再开启auth = true 后,db.auth(‘root‘,‘pwd‘),带密码登陆auth = true
8. Add a log file
mkdir /User/Apple/mongodb/logsmkdir /User/Apple/mongodb/logs/mongodb/touch mongod.log
9. Start the MONGO service
mongod --dbpath /User/Apple/mongodb/data/db/

This starts the service directly (foreground boot)

Keep this window from shutting down and use another window (terminal) to open the client

mongo

Or

mongod --config /User/Apple/mongodb/etc/mongod.conf
Background boot

At this point, MONGO in the local environment is set up, but when we close the service, the client can not be used, then how to start the background???

mongod --dbpath /User/Apple/mongodb/data/db/ &

Copy and paste, completed the background of MongoDB start, even if the shell is closed, the service is still running. If you want to terminate the
Querying the PID of Mongod

ps -ef | grep mongo

Kill the process

kill -9 [pid]
Two. Brew Installation MongoDB

You can use OSX's brew to install MongoDB:

sudo brew install mongodb

If you want to install the support TLS/SSL command as follows:

sudo brew install mongodb --with-openssl

To install the latest development version:

sudo brew install mongodb --devel
Three. Curl command to download the installation
# 进入 /usr/localcd /usr/local# 下载sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.2.tgz# 解压sudo tar -zxvf mongodb-osx-x86_64-3.4.2.tgz# 重命名为 mongodb 目录sudo mv mongodb-osx-x86_64-3.4.2 mongodb

After the installation is complete, we can add the MongoDB binary command file directory (installation directory/bin) to the path path:

export PATH=/usr/local/mongodb/bin:$PATH

MongoDB Download + install + Run

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.