mongodb下载安装
方法一: 官网链接下载安装
方法二:
a. cd /usr/local 进入目录
- sudo curl -O fastdl.mongodb.org/osx/mongodb…
- 开始下载,后面的地址替换为最新版本的地址
- sudo tar -zxvf mongodb-osx-ssl-x86_64-4.0.9.tgz
- 解压,这里的文件名也需要替换为按版本的文件名,具体可以下载之后ls看一下文件即可
- sudo mv mongodb-osx-x86_64-4.0.9/ mongodb
- 解压后改名,不要忘了改文件名
b. 配置镜像
方案一:
- 启动终端Terminal
- 进入当前用户的home目录
- 输入cd ~
- 创建.bash_profile --> touch .bash_profile
- 编辑.bash_profile文件 输入open -e .bash_profile
- 写入 export PATH=${PATH}:/usr/local/mongodb/bin
- 保存文件,关闭.bash_profile
- 更新刚配置的环境变量 输入source .bash_profile
如果安装了 iTerm zsh 就在~/.zshrc 文件里面 加入bash_profile 指向
source ~/.bash_profile
方案二:安装了 iTerm zsh 的前提下 直接在 文件 ~/.zshrc 文件里面直接设置镜像
export PATH=${PATH}:/usr/local/mongodb/bin
客官记得刷新哦
source ~/.zshrc
c.创建log和data目录
sudo mkdir -p /usr/local/mongodb/data
sudo mkdir -p /usr/local/mongodb/log
d. 启动mongodb服务
先进入 mongodb 目录
cd /usr/local/mongodb
然后输入
mongod --dbpath data --logpath log/mongod.log --logappend
启动mongodb服务(当前终端不要关闭)
e. 链接数据库
在新的终端 输入 mongo
如下,表示已生效
MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2022-04-08T11:11:47.988+0800 I CONTROL [js] machdep.cpu.extfeatures unavailable
Implicit session: session { "id" : UUID("00930149-2c13-44cf-9695-9fc51ad1f28d") }
MongoDB server version: 4.0.9
Server has startup warnings:
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten]
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten]
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten]
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten]
2022-04-07T16:16:04.200+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
---
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()
---
>
f. mongo 无效看是否是镜像的问题
输入mongo 报以下错误,
zsh: command not found: mongo
处理如下:
open ~/.zshrc
在文件里面输入 source ~/.bash_profile 保存后记得更新 .zshrc 文件
source ~/.zshrc