【mongodb 基础2】Install MongoDB Community Edition on macOS

本文参考官网通过Homebrew安装MongoDB
 
Use this tutorial to install MongoDB 6.0 Community Edition on macOS using the third-party Homebrew package manager.

 

一. 安装准备

Install Xcode Command-Line Tools

Install the Xcode command-line tools by running the following command in your macOS Terminal:

xcode-select --install

 

Install Homebrew

macOS does not include the Homebrew brew package by default.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

brew官网:https://brew.sh/#install

 

二. Installing MongoDB 6.0 Community Edition

1. 下载MongoDB Homebrew 组件包

Tap the MongoDB Homebrew Tap to download the official Homebrew formula for MongoDB and the Database Tools,

brew tap mongodb/brew

 

2. 更新组件包

To update Homebrew and all existing formulae:

brew update

 

3. 安装MongoDBTo install MongoDB

brew install mongodb-community@6.0

 

可能出现的问题

Error: Command failed with exit 128: git

执行:brew -v

lianggao@LiangdeMacBook-Pro ~ % brew -v
Homebrew 4.0.6
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

        git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:

        git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

根据提示添加:

lianggao@LiangdeMacBook-Pro ~ % git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core  
lianggao@LiangdeMacBook-Pro ~ % git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

 

三. 安装后包含的组件

The installation includes the following binaries:

  • The mongod server
  • The mongos sharded cluster query router
  • The MongoDB Shell, mongosh

 
创建的目录和文件

安装位置:
check where brew has installed these files and directories:

 % brew --prefix                     
/usr/local

In addition, the installation creates the following files and directories at the location specified below, depending on your Apple hardware:

在这里插入图片描述
 
 

四. Run&stop MongoDB

两种方式运行mongodb

You can run MongoDB as a macOS service using brew, or you can run MongoDB manually as a background process.

1. 作为macOS服务的方式运行mongodb

It is recommended to run MongoDB as a macOS service, as doing so sets the correct system ulimit values automatically (see ulimit settings for more information).
 
To run MongoDB (i.e. the mongod process) as a macOS service, run:

brew services start mongodb-community@6.0

。。。
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-commu

 

2. stop mongod

To stop a mongod running as a macOS service, use the following command as needed:

brew services stop mongodb-community@6.0

 

3. verify that MongoDB is running

To verify that MongoDB is running, perform one of the following: If
you started MongoDB as a macOS service:

brew services list

4. the log file

You can also view the log file to see the current status of your mongod process:

/usr/local/var/log/mongodb/mongo.log.

 
 

五. Connect and Use MongoDB

1. Connect MongoDB

To begin using MongoDB, connect mongosh to the running instance.

lianggao@LiangdeMacBook-Pro ~ % mongosh

lianggao@LiangdeMacBook-Pro ~ % mongosh
Current Mongosh Log ID:        641168ac9149fea4d2578ae1
Connecting to:                mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.8.0
Using MongoDB:                6.0.5
Using Mongosh:                1.8.0

。。。

test> 

 

2. other tools

including data backup and import/export tools like mongoimport and mongodump as well as monitoring tools like mongotop.

% mongotop

It should start up, connect to your running mongod, and start reporting usage statistics.

3. default setting

mongoDB默认绑定的ip是127.0.0.1,也就是说所有的请求只能来自本地一个节点。

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

通过设置ip来允许与外界的通讯

This value can be configured either:

  • in the MongoDB configuration file with bindIp,
  • via the command-line argument --bind_ip
     

For more information on configuring bindIp, see IP Binding.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

roman_日积跬步-终至千里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值