我目前在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做到这一点,我得到了相同的结果。
我试图在我的下载文件夹和桌面上运行它。我已将其移至我的主目录中,并且我没有注销到控制台,它只返回一个新行。
我需要在这做什么?
谢谢
答案 0 :(得分:3)
尝试:
sudo mkdir /data
sudo chmod -R 755 /data && sudo chown -R `whoami` /data
# now run the script
如果/ data exists刚刚运行第二个命令,则可能没有必要运行第一个命令。
错误代码是因为MongoDB无法创建必要的数据库文件,因为目录不存在。