sfsoul / personalBlog

思考与总结
MIT License
1 stars 0 forks source link

mongoDB #19

Open sfsoul opened 3 years ago

sfsoul commented 3 years ago

Mac 上下载 MongoDB

下载地址

下载地址

Copy the extracted archive to the target directory

Copy the extracted folder to the location from which MongoDB will run.

这里是将解压后的 MongoDB 文件放到将要运行的地方。推荐放在 /usr/local

Ensure the location of the binaries is in the PATH variable.

The MongoDB binaries are in the bin/ directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.

这里是要将 MongoDB 的二进制文件放入到环境变量中。由于我的终端是 Iterm + zsh,所以这边直接修改 .zshrc 文件

// 新增环境变量
export PATH="$PATH:/usr/local/mongodb/bin"

source ~/.zshrc

Run MongoDB

Create the data directory

Before you start MongoDB for the first time, create the directory to which the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a directory other than this one, you must specify that directory in the dbpath option when starting the mongod process later in this procedure.

The following example command creates the default /data/db directory:

// 创建 data/db 目录,存放 mongod 进程写入数据的目录
mkdir -p /data/db

Set permissions fro the data directory

Before running mongod for the first time, ensure that the user account running mongod has read and write permissions for the directory.

给 /data/db 设置读写权限

// 获取用户名
$ whoami
-> username

// 设置权限
$ sudo chown username /data/db

mkdir -p /data/db 报错

执行 mkdir -p /data/db 报错,报错信息为:mkdir: /data/db: Read-only file system

因为mac电脑默认是开启安全模式的,不能在根目录下面随便创建、删除文件夹。所以会出现这个错误。

sfsoul commented 3 years ago

参考文章