【MongoDB】MacOS安装MongoDB完整收录

举报
小雨青年 发表于 2022/03/28 23:55:26 2022/03/28
【摘要】 系统版本 最低版本要求 10.13 1 MongoDB版本 MongoDB Community Edition 4.4 12 安装 安装Xcode命令行 xcode-select --...

系统版本

在这里插入图片描述

最低版本要求

10.13

  
 
  • 1

MongoDB版本

MongoDB Community Edition 
4.4

  
 
  • 1
  • 2

安装

安装Xcode命令行

xcode-select --install

  
 
  • 1

安装Homebrew

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

  
 
  • 1

安装MongoDB

brew tap mongodb/brew

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (elastic/tap and homebrew/services).
==> Updated Formulae
Updated 17 formulae.
==> Deleted Formulae
elastic/tap/elasticsearch-oss            elastic/tap/kibana-oss

==> Tapping mongodb/brew
Cloning into '/usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew'...
remote: Enumerating objects: 619, done.
remote: Counting objects: 100% (116/116), done.
remote: Compressing objects: 100% (112/112), done.
remote: Total 619 (delta 45), reused 13 (delta 4), pack-reused 503
Receiving objects: 100% (619/619), 133.57 KiB | 124.00 KiB/s, done.
Resolving deltas: 100% (283/283), done.
Tapped 11 formulae (39 files, 208.7KB).

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
brew install mongodb-community@4.4

Updating Homebrew...
==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/tools/db/mongodb-database-tools-macos
######################################################################## 100.0%
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.4.tgz
######################################################################## 100.0%
==> Installing dependencies for mongodb/brew/mongodb-community: mongodb-database-tools
==> Installing mongodb/brew/mongodb-community dependency: mongodb-database-
🍺  /usr/local/Cellar/mongodb-database-tools/100.3.1: 13 files, 150.9MB, built in 6 seconds
==> Installing mongodb/brew/mongodb-community
==> Caveats
To have launchd start mongodb/brew/mongodb-community now and restart at login:
  brew services start mongodb/brew/mongodb-community
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: 11 files, 156.9MB, built in 4 seconds
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/gdbm--1.18.1_1.big_sur.bottle.tar.gz... (207.3KB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/mycli--1.22.2_1.big_sur.bottle.tar.gz... (4.0MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/mysql-client--8.0.22.big_sur.bottle.tar.gz... (42.3MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/nginx--1.19.5.big_sur.bottle.tar.gz... (1.2MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/openssl@1.1--1.1.1i.big_sur.bottle.tar.gz... (5.4MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.8--pip--20.2.4.tar.gz... (1.4MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.8--wheel--0.35.1.tar.gz... (58.3KB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.8--setuptools--50.3.2.zip... (2.0MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.8--3.8.6.tar.xz... (17.4MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.9--setuptools--51.0.0.zip... (2.0MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.9--pip--20.3.1.tar.gz... (1.5MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.9--wheel--0.36.1.tar.gz... (62.7KB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/python@3.9--3.9.1.tar.xz... (18MB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/readline--8.1.big_sur.bottle.tar.gz... (536KB)
Removing: /Users/lixiaoyu/Library/Caches/Homebrew/sqlite--3.34.0.big_sur.bottle.tar.gz... (2.0MB)
Removing: /Users/lixiaoyu/Library/Logs/Homebrew/mkcert... (64B)
Removing: /Users/lixiaoyu/Library/Logs/Homebrew/nss... (64B)
Removing: /Users/lixiaoyu/Library/Logs/Homebrew/nspr... (64B)
==> Caveats
==> mongodb-community
To have launchd start mongodb/brew/mongodb-community now and restart at login:
  brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
  mongod --config /usr/local/etc/mongod.conf

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

我好久没更新了,所以上面有一段自动更新。

运行

作为服务运行(推荐)

开启服务

brew services start mongodb-community@4.4

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

  
 
  • 1
  • 2
  • 3

验证运行

brew services list | grep mongodb

mongodb-community  started lixiaoyu /Users/coderfix.blog.csdn.net/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

  
 
  • 1
  • 2
  • 3

结束服务

brew services stop mongodb-community@4.4

Stopping `mongodb-community`... (might take a while)
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community)

  
 
  • 1
  • 2
  • 3
  • 4

作为后台进程

开启进程

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

about to fork child process, waiting until server is ready for connections.
forked process: 39626
child process started successfully, parent exiting

  
 
  • 1
  • 2
  • 3
  • 4
  • 5

验证运行

ps aux | grep -v grep | grep mongod

coderfix.blog.csdn.net         39626   0.2  0.2  5529296  20416   ??  S     3:50下午   0:01.04 mongod --config /usr/local/etc/mongod.conf --fork

  
 
  • 1
  • 2
  • 3

结束进程

kill 39626

39626是上面的进程号

  
 
  • 1
  • 2
  • 3

命令行进入mongo

mongo

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("657fd4ef-6986-4b55-b694-625710e2cbe9") }
MongoDB server version: 4.4.4
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
	https://community.mongodb.com
---
The server generated these startup warnings when booting: 
        2021-04-23T15:59:42.655+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

总结

  • 推荐服务形式运行

后续我会继续更新相关学习笔记,敬请期待!!!

参考资料

  • https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
  • https://brew.sh/#install
  • https://docs.mongodb.com/manual/reference/program/mongod/#mongodb-binary-bin.mongod

文章来源: coderfix.blog.csdn.net,作者:小雨青年,版权归原作者所有,如需转载,请联系作者。

原文链接:coderfix.blog.csdn.net/article/details/116055192

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。