提示第一次连接 mongodb 失败
报错输出大概是说无法连接到xxxx:27017
,这里的 xxxx 指的是一个域名,更确切说是主机名,需要将其添加到配置文件的bindIp
上面才能通过该域名进行连接,其实就是给mongod
指定监听特定主机的作用,而外部只能通过这些指定的主机名进行连接(包括IP地址)。
net:
bindIp: localhost,127.0.0.1,livejq
因不正常关闭而无法启动 mongod 服务
报错信息
root@livejq:/usr/local/var/mongodb/conf# mongod -f node1.conf
about to fork child process, waiting until server is ready for connections.
forked process: 12558
ERROR: child process failed, exited with 14
To see additional information in this output, start without the "--fork" option.
日志关键信息
{"msg":"An incomplete repair has been detected! This is likely because a repair operation unexpectedly failed before completing. MongoDB will not start up again without --repair."}
解决办法
删除/var/lib/mongo
下的mongod.lock
文件后,以修复方式启动 mongod 服务。
root@livejq:/usr/local/var/mongodb/conf# mongod -f node1.conf --repair
上述办法仍无法解决,修复失败
{"error":"NotWritablePrimary: Not primary while creating collection admin.system.version"}
这是因为我将三个节点设置了Replica Set
副本集模式,所以要想启动primary
节点,必须先将其他节点启动起来才行。(当然,启动之前依然先将mongod.lock
和_repair_incomplete
修复失败之类的文件删除)
root@livejq:/usr/local/var/mongodb/conf# mongod -f node2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 16280
child process started successfully, parent exiting
root@livejq:/usr/local/var/mongodb/conf# mongod -f node3.conf
about to fork child process, waiting until server is ready for connections.
forked process: 16333
child process started successfully, parent exiting
root@livejq:/usr/local/var/mongodb/conf# mongod -f node1.conf
about to fork child process, waiting until server is ready for connections.
forked process: 16382
child process started successfully, parent exiting
缺少 dbPath 目录而无法启动 mongod 服务
报错信息
root@livejq:/usr/local/var/mongodb# mongod -f conf/node1.conf
about to fork child process, waiting until server is ready for connections.
forked process: 11104
ERROR: child process failed, exited with 100
To see additional information in this output, start without the "--fork" option.
日志关键信息
{"error":"NonExistentPath: Data directory /usr/local/var/mongodb/node1 not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}
解决办法
缺少数据存储目录,按要求创建一个即可
mkdir -p /usr/local/var/mongodb/node1
评论区