终端报错信息: ERROR: child process failed, exited with error number 1
我是在stackoverflow上读到一位老哥的回答解决的问题,下面这一段是原回答:
I had the same thing and it turned out to be a permissions issue. If the owner of the child process cannot access the log path or the log path does not exist, it will fail.
What I did was put the log directory in my home directory:
mkdir ~/log
mongod --fork --logpath ~/log/mongodb.log
什么意思呢?我们知道,在启动MongoDB服务的时候需要告诉他的数据库文件放在哪里以及运行过程中产生的日志文件放在哪里,那么我是使用的Ubuntu系统,其根目录下有专门设计来存放数据库数据和日志文件的文件夹,所以我就想着把数据和日志文件放在根目录里相应的文件夹中,但是这样就产生了一个问题,就是权限问题,所以说我们每次启动MongoDB服务的时候,需要赋予其一个能够访问根目录下文件夹的权限。所以我们可以在启动服务命令前加sudo,或者直接以管理员的身份去运行,都可以。上面的老哥呢,他直接把日志文件放在了用户主目录(home)下,这样你不去给予更高权限也没有问题。