首页 > 解决方案 > MongoDB 没有启动

问题描述

几天前,我决定将 mongodb 用于一个项目。但我仍然没有让它工作。

如果我尝试使用以下命令启动 mongodb:

  sudo mongod --config=/etc/mongod.conf

这是结果:

  about to fork child process, waiting until server is ready for connections.
  forked process: 4539
  child process started successfully, parent exiting

这是我的 mongod.conf:

  # mongod.conf
  systemLog:
     path: "/var/log/mongodb/mongod.log"
     destination: file
     timeStampFormat: iso8601-utc
     logAppend: true
     logRotate: reopen

  net:
     bindIp: 127.0.0.1
     port: 27017
     wireObjectCheck: true
     serviceExecutor: adaptive

  storage:
     dbPath: "/home/juny/nodeBox/data/db"

  processManagement:
     fork: true
     pidFilePath: "/run/mongod.pid"

  security:
     authorization: enabled

  operationProfiling:
     mode: slowOp

如果我尝试将 mongod 作为服务启动,终端会显示:

   ● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-05-27 14:22:31 AST; 8s ago
      Docs: https://docs.mongodb.org/manual
   Process: 4861 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
   Main PID: 4861 (code=exited, status=1/FAILURE)

   May 27 14:22:31 LAPTOP-CJFC94N systemd[1]: Started MongoDB Database Server.
   May 27 14:22:31  mongod[4861]: about to fork child process, waiting until server is ready for connections.
   May 27 14:22:31  mongod[4861]: forked process: 4863
   May 27 14:22:31  systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
   May 27 14:22:31  systemd[1]: mongod.service: Unit entered failed state.
   May 27 14:22:31  systemd[1]: mongod.service: Failed with result 'exit-code'.

最后,这是我的日志文件中的几行:

   2019-05-27T18:14:16.257Z I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
   2019-05-27T18:14:16.437Z I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
   2019-05-27T18:14:16.437Z I CONTROL  [initandlisten] 
   2019-05-27T18:14:16.437Z I CONTROL  [initandlisten] 
   2019-05-27T18:14:16.437Z I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
   2019-05-27T18:14:16.437Z I CONTROL  [initandlisten] **        We suggest setting it to 'never'
   2019-05-27T18:14:16.437Z I CONTROL  [initandlisten] 
   2019-05-27T18:14:16.530Z I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/home/juny/nodeBox/data/db/diagnostic.data'
   2019-05-27T18:14:16.531Z I EXECUTOR [initandlisten] No thread count configured for executor. Using number of cores / 2: 2
   2019-05-27T18:14:16.531Z I EXECUTOR [worker-1] Started new database worker thread 1
   2019-05-27T18:14:16.531Z I EXECUTOR [worker-2] Started new database worker thread 2
   2019-05-27T18:14:16.531Z I NETWORK  [initandlisten] waiting for connections on port 27017
   2019-05-27T18:28:02.535Z I NETWORK  [listener] connection accepted from 127.0.0.1:48610 #1 (1 connection now open)
   2019-05-27T18:28:02.535Z I NETWORK  [conn1] Error receiving request from client: ProtocolError: Client sent an HTTP request over a native MongoDB connection. Ending connection from 127.0.0.1:48610 (connection id: 1)
   2019-05-27T18:28:02.535Z I NETWORK  [worker-2] end connection 127.0.0.1:48610 (0 connections now open)
   2019-05-27T18:28:02.585Z I NETWORK  [listener] connection accepted from 127.0.0.1:48612 #2 (1 connection now open)
   2019-05-27T18:28:02.585Z I NETWORK  [conn2] Error receiving request from client: ProtocolError: Client sent an HTTP request over a native MongoDB connection. Ending connection from 127.0.0.1:48612 (connection id: 2)
   2019-05-27T18:28:02.585Z I NETWORK  [worker-1] end connection 127.0.0.1:48612 (0 connections now open)

标签: mongodb

解决方案


好的好的,如果我输入以下命令,它就可以工作:mongo


推荐阅读