MongoDB(2)- 安装 MongoDB

MacOS 安装 MongoDB

博主目前都用 mac 电脑练习,所以这里重点讲 MacOS 安装方式

系统要求

MongoDB 4.4 社区版支持 macOS 10.13 或更高版本

 

安装 Homebrew

Homebrew 是一个软件包管理器。它的作用就是将软件包安装到自己的目录中,然后将其文件符号链接到 /usr/local。更多信息,请自行进入官网查看

https://brew.sh/

 

在将下面代码复制进终端

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

 

安装社区版的 MongoDB

下载 MongoDB 和数据库工具

brew tap mongodb/brew

 

安装 MongoDB

brew install mongodb-community@4.4                                   ==> Installing mongodb-community@4.4 from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.5.tgz
Already downloaded: /Users/polo/Library/Caches/Homebrew/downloads/f86017008241ff604c5586f09b0ac27416ca9006d72f3c7087a9c8d02d26df8e--mongodb-macos-x86_64-4.4.5.tgz
==> Caveats
mongodb-community@4.4 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have mongodb-community@4.4 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/mongodb-community@4.4/bin:$PATH"' >> ~/.zshrc


To have launchd start mongodb/brew/mongodb-community@4.4 now and restart at login:
  brew services start mongodb/brew/mongodb-community@4.4
Or, if you don't want/need a background service you can just run:
  mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺  /usr/local/Cellar/mongodb-community@4.4/4.4.5: 11 files, 157.3MB, built in 4 seconds

最新5.0,先不做小白鼠

 

添加 MongoDB 到 PATH 中

echo 'export PATH="/usr/local/opt/mongodb-community@4.4/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

 

验证 MongoDB 安装成功

mongo --version
mongod --version 

# 均显示
db version v4.4.5
Build Info: {
    "version": "4.4.5",
    "gitVersion": "ff5cb77101b052fa02da43b8538093486cf9b3f7",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

 

系统文件所在位置

 
Intel 处理器
Apple M1 处理器

configuration file

 /usr/local/etc/mongod.conf
/opt/homebrew/etc/mongod.conf

log directory

 /usr/local/var/log/mongodb/opt/homebrew/var/log/mongodb 
data directory/usr/local/var/mongodb /opt/homebrew/var/mongodb 

 

运行 MongoDB

MongoDB(即 mongod 进程)作为 macOS 服务运行(推荐,不需要手动运行)

brew services start mongodb-community@4.4

 

停止作为服务运行

brew services stop mongodb-community@4.4

 

手动运行 MongoDB(即 mongod 进程)作为后台进程

intel 处理器

mongod --config /usr/local/etc/mongod.conf --fork

 

M1 处理器

mongod --config /opt/homebrew/etc/mongod.conf --fork

 

如何关闭后台进程?

从 mongo shell 连接到 mongod,并发出关闭命令 

 

验证 MongoDB 正在运行

brew services list                                                

 

ps 验证

ps aux | grep mongdb
ps aux | grep -v grep | grep mongod

 

开始使用 mongodb

mongo

 

指定端口运行

mongo --port 57017

 

碰到的问题

brew services list 查看 MongoDB 服务 status 显示 error 的问题

https://www.cnblogs.com/poloyy/p/14828075.html

 

执行 mongo、mongod 显示无命令

https://www.cnblogs.com/poloyy/p/14828089.html

 

Window 下安装 MongoDB

https://docs.mongodb.com/v4.4/tutorial/install-mongodb-on-windows/

 

Linux 下安装 MongoDB

https://docs.mongodb.com/v4.4/administration/install-on-linux/

 
posted @ 2021-05-30 15:29  小菠萝测试笔记  阅读(1006)  评论(0编辑  收藏  举报