尝试创建副本集时出现问题

Issue trying to create a replica set

我目前在 Mac (Sierra) 上设置副本集时遇到问题(根据 mongoDB 创建副本集教程中的说明)。我已经下载了相关的 .sh 文件,当我 运行 此代码时:

bash < create_replica_set__m101p_52b35df6e2d423678d3b9d48.19830756d7a7.sh

这是脚本:

#!/usr/bin/env bash

mkdir -p /data/rs1 /data/rs2 /data/rs3
mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --oplogSize 64 --fork --smallfiles
mongod --replSet m101 --logpath "2.log" --dbpath /data/rs2 --port 27018 --oplogSize 64 --smallfiles --fork
mongod --replSet m101 --logpath "3.log" --dbpath /data/rs3 --port 27019 --oplogSize 64 --smallfiles --fork

我的终端出现这个错误:

mkdir: /data/rs1: Permission denied mkdir: /data/rs2: Permission denied mkdir: /data/rs3: Permission denied about to fork child process, waiting until server is ready for connections. forked process: 27998 ERROR: child process failed, exited with error number 100 about to fork child process, waiting until server is ready for connections. forked process: 28001 ERROR: child process failed, exited with error number 100 about to fork child process, waiting until server is ready for connections. forked process: 28004 ERROR: child process failed, exited with error number 100

我尝试使用 sudo 执行此操作,但得到了相同的结果。

我已尝试 运行 在我的下载文件夹和桌面上进行此操作。我已将它移动到我的主目录中,但我没有从控制台注销任何内容,它只是 returns 一个新行。

我需要在这里做什么?

谢谢

尝试:

sudo mkdir /data
sudo chmod -R 755 /data && sudo chown -R `whoami` /data
# now run the script

可能不需要 运行 第一个命令,如果 /data 已经存在,只需 运行 第二个命令。

错误代码是因为MongoDB无法创建必要的数据库文件,因为目录不存在。