mac下MongoDB安装
在mac上安装mongoDB一般两种方式: + 下载源码,解压,编译,配置,启动…(或者直接下载编译好的压缩包) + 使用brew install mongoDB (ps:可以指定版本)
lvdalin:~ lvdalin$ brew search mongodb-community
==> Formulae
mongodb/brew/mongodb-community mongodb/brew/mongodb-community@3.4
mongodb/brew/mongodb-community-shell mongodb/brew/mongodb-community@3.6
mongodb/brew/mongodb-community@3.2 mongodb/brew/mongodb-community@4.0
mongodb/brew/mongodb-community@4.2
lvdalin:~ lvdalin$ brew install mongodb-community@4.2
==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.8.tgz
######################################################################## 100.0%
==> 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.2.8: 21 files, 306.3MB, built in 7 seconds
看到上面的日志说明,已经安装成功 上面显示:Caveats 提示/警告信息 : 可以使用brew services start/restart mongodb ,也可以指定配置启动mongodb Summary 总结: 安装的路径为:/usr/local/Cellar/mongodb-community/4.2.8: 21,文件总大小:306.3MB, 安装时间:7秒. 第一次启动可能用到的步骤:
修改默认的数据文件存放路径 /data/db, 没有的话需要创建,同时修改目录所属用户
lvdalin:bin lvdalin$ sudo mkdir -p /data/db lvdalin:bin lvdalin$ sudo chowm -R lvdalin /data/db
修改mongoDB配置文件mongod.conf(默认在usr/local/etc/下),修改数据文件存储位置
lvdalin:etc lvdalin$ vim mongod.conf systemLog: destination: file path: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: #dbPath: /usr/local/var/mongodb dpPath: /data/db net: bindIp: 127.0.0.1 #只允许本地的链接访问,如果允许远程访问 bindIp : 0.0.0.0
- mongodb加入环境变量
lvdalin:~ lvdalin$ vim .bash_profile
//加入到文件末尾 保存
export PATH="/usr/local/Cellar/mongodb-community/4.2.8/bin:$PATH"
//让环境变量生效
lvdalin:~ lvdalin$ source .bash_profile
启动mongodb
lvdalin:etc lvdalin$ brew services start mongodb/brew/mongodb-community
lvdalin:etc lvdalin$ mongod
启动客户端
lvdalin:etc lvdalin$ mongo
MongoDB shell version v4.2.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
MongoDB server version: 4.2.8
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()
---
>