我无法运行 mongodb,即使我已经关注了这里的大多数帖子

Posted

技术标签:

【中文标题】我无法运行 mongodb,即使我已经关注了这里的大多数帖子【英文标题】:I can't run mongodb, even though I have followed most posts here 【发布时间】:2021-02-16 16:06:48 【问题描述】:

当我尝试sudo mongod --port 27017sudo mongod 时,出现错误:

NonExistentPath, Data directory /data/db not found

所以,我在/Users/thiago/ 下使用chmod 777 创建了/data/db 并运行:

sudo mongod --dbpath /Users/thiago/data/db

但仍然出现同样的错误。

错误信息

$sudo mongod

"t":"$date":"2020-11-03T19:58:39.824-03:00","s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"
"t":"$date":"2020-11-03T19:58:39.829-03:00","s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"
"t":"$date":"2020-11-03T19:58:39.829-03:00","s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."
"t":"$date":"2020-11-03T19:58:39.829-03:00","s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":"pid":12590,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"C02T507NGTFJs-MacBook-Pro.local"
"t":"$date":"2020-11-03T19:58:39.829-03:00","s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":"buildInfo":"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","modules":[],"allocator":"system","environment":"distarch":"x86_64","target_arch":"x86_64"
"t":"$date":"2020-11-03T19:58:39.829-03:00","s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":"os":"name":"Mac OS X","version":"19.6.0"
"t":"$date":"2020-11-03T19:58:39.829-03:00","s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":"options":
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"E",  "c":"STORAGE",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":"error":"NonExistentPath: Data directory /data/db 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."
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"REPL",     "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":"waitTimeMillis":10000
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"COMMAND",  "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"STORAGE",  "id":4784906, "ctx":"initandlisten","msg":"Shutting down the FlowControlTicketholder"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"CONTROL",  "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"FTDC",     "id":4784926, "ctx":"initandlisten","msg":"Shutting down full-time data capture"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"STORAGE",  "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"STORAGE",  "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"-",        "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"
"t":"$date":"2020-11-03T19:58:39.831-03:00","s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":"exitCode":100

$sudo mongod --dbpath /Users/thiago/data/db

"t":"$date":"2020-11-03T20:00:53.205-03:00","s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"
"t":"$date":"2020-11-03T20:00:53.207-03:00","s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"
"t":"$date":"2020-11-03T20:00:53.208-03:00","s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."
"t":"$date":"2020-11-03T20:00:53.208-03:00","s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":"pid":12614,"port":27017,"dbPath":"/Users/thiago/data/db","architecture":"64-bit","host":"C02T507NGTFJs-MacBook-Pro.local"
"t":"$date":"2020-11-03T20:00:53.208-03:00","s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":"buildInfo":"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","modules":[],"allocator":"system","environment":"distarch":"x86_64","target_arch":"x86_64"
"t":"$date":"2020-11-03T20:00:53.208-03:00","s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":"os":"name":"Mac OS X","version":"19.6.0"
"t":"$date":"2020-11-03T20:00:53.208-03:00","s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":"options":"storage":"dbPath":"/Users/thiago/data/db"
"t":"$date":"2020-11-03T20:00:53.211-03:00","s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":"dbpath":"/Users/thiago/data/db","storageEngine":"wiredTiger"
"t":"$date":"2020-11-03T20:00:53.211-03:00","s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":"config":"create,cache_size=3584M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"
"t":"$date":"2020-11-03T20:00:53.816-03:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1604444453:816494][12614:0x11da86dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 6 through 7"
"t":"$date":"2020-11-03T20:00:53.896-03:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1604444453:896463][12614:0x11da86dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 7 through 7"
"t":"$date":"2020-11-03T20:00:54.008-03:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1604444454:8614][12614:0x11da86dc0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Main recovery loop: starting at 6/4608 to 7/256"
"t":"$date":"2020-11-03T20:00:54.113-03:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1604444454:113155][12614:0x11da86dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 6 through 7"
"t":"$date":"2020-11-03T20:00:54.177-03:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1604444454:177740][12614:0x11da86dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 7 through 7"
"t":"$date":"2020-11-03T20:00:54.235-03:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1604444454:235869][12614:0x11da86dc0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"
"t":"$date":"2020-11-03T20:00:54.235-03:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1604444454:235985][12614:0x11da86dc0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global oldest timestamp: (0, 0)"
"t":"$date":"2020-11-03T20:00:54.283-03:00","s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":"durationMillis":1072
"t":"$date":"2020-11-03T20:00:54.284-03:00","s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":"recoveryTimestamp":"$timestamp":"t":0,"i":0
"t":"$date":"2020-11-03T20:00:54.332-03:00","s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"
"t":"$date":"2020-11-03T20:00:54.333-03:00","s":"W",  "c":"CONTROL",  "id":22120,   "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]
"t":"$date":"2020-11-03T20:00:54.333-03:00","s":"W",  "c":"CONTROL",  "id":22138,   "ctx":"initandlisten","msg":"You are running this process as the root user, which is not recommended","tags":["startupWarnings"]
"t":"$date":"2020-11-03T20:00:54.333-03:00","s":"W",  "c":"CONTROL",  "id":22140,   "ctx":"initandlisten","msg":"This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning","tags":["startupWarnings"]
"t":"$date":"2020-11-03T20:00:54.338-03:00","s":"W",  "c":"CONTROL",  "id":22184,   "ctx":"initandlisten","msg":"Soft rlimits too low","attr":"currentValue":2560,"recommendedMinimum":64000,"tags":["startupWarnings"]
"t":"$date":"2020-11-03T20:00:54.398-03:00","s":"I",  "c":"STORAGE",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"
"t":"$date":"2020-11-03T20:00:54.423-03:00","s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":"dataDirectory":"/Users/thiago/data/db/diagnostic.data"
"t":"$date":"2020-11-03T20:00:54.444-03:00","s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":"address":"/tmp/mongodb-27017.sock"
"t":"$date":"2020-11-03T20:00:54.445-03:00","s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":"address":"127.0.0.1"
"t":"$date":"2020-11-03T20:00:54.445-03:00","s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":"port":27017,"ssl":"off"

为什么每当我运行 mongod 命令时,我都会得到日志返回?

即使它在第二个日志中工作,我在运行 mongod 时继续返回该错误:

DBException in initAndListen, terminating", "attr": "error": "NonExistentPath: Data directory / data / db 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

我的数据库配置:

development:
  clients:
    default:
      database: mydb_development
      hosts:
        - localhost:27017
      options:
        roles:
         - 'root'
        auth_source: admin
  options:
    raise_not_found_error: false
test:
  clients:
    default:
      database: mydb_test
      hosts:
        - localhost:27017
      options:
        read:
          mode: :primary
        max_pool_size: 1
  options:
    raise_not_found_error: false
production:
  clients:
    default:
      uri: <%= ENV["MONGODB_URI"] %>
  options:
    raise_not_found_error: false

当我尝试 $mongod -v 时,我得到了:

"t":"$date":"2020-11-04T09:20:46.678-03:00","s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"
"t":"$date":"2020-11-04T09:20:46.685-03:00","s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"
"t":"$date":"2020-11-04T09:20:46.685-03:00","s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."
"t":"$date":"2020-11-04T09:20:46.686-03:00","s":"D1", "c":"NETWORK",  "id":22940,   "ctx":"main","msg":"file descriptor and connection resource limits","attr":"hard":9223372036854775807,"soft":256,"conn":204
"t":"$date":"2020-11-04T09:20:46.686-03:00","s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":"pid":3251,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"C02T507NGTFJs-MacBook-Pro.local"
"t":"$date":"2020-11-04T09:20:46.686-03:00","s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":"buildInfo":"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","modules":[],"allocator":"system","environment":"distarch":"x86_64","target_arch":"x86_64"
"t":"$date":"2020-11-04T09:20:46.686-03:00","s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":"os":"name":"Mac OS X","version":"19.6.0"
"t":"$date":"2020-11-04T09:20:46.686-03:00","s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":"options":"systemLog":"verbosity":1
"t":"$date":"2020-11-04T09:20:46.686-03:00","s":"D1", "c":"NETWORK",  "id":22940,   "ctx":"initandlisten","msg":"file descriptor and connection resource limits","attr":"hard":9223372036854775807,"soft":256,"conn":204
"t":"$date":"2020-11-04T09:20:46.688-03:00","s":"D1", "c":"EXECUTOR", "id":23104,   "ctx":"OCSPManagerHTTP-0","msg":"Starting thread","attr":"threadName":"OCSPManagerHTTP-0","poolName":"OCSPManagerHTTP"
"t":"$date":"2020-11-04T09:20:46.688-03:00","s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":"path":"/tmp/mongodb-27017.sock","error":"Permission denied"
"t":"$date":"2020-11-04T09:20:46.688-03:00","s":"F",  "c":"-",        "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919
"t":"$date":"2020-11-04T09:20:46.688-03:00","s":"F",  "c":"-",        "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"

当我尝试 $mongo 时:

MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

【问题讨论】:

根据您的日志,--dbPath 的第二个命令似乎有效。它没有显示任何错误。您是否尝试过连接到数据库并运行一些查询?请提供更多信息,例如您如何连接到此数据库等 当我尝试启动控制台时,我收到消息:MongoDB shell 版本 v4.4.1 连接到:mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb 错误:无法连接到服务器 127.0.0.1:27017,连接尝试失败:SocketException: 连接到 127.0.0.1:27017 :: 时出错 :: Connection refused : connect@src/mongo/shell/mongo.js:374:17 @(connect) :2:6 异常:连接失败退出代码 1 【参考方案1】:

第二个命令的输出不是错误。日志的最后几行显示它正在侦听连接。

【讨论】:

是的,但我认为每次在终端上写 mongod 时都显示日志是错误的。 这不是错误。如果要减少日志记录,可以使用 quiet 标志运行 mongod。 @ThiagoXimenes

以上是关于我无法运行 mongodb,即使我已经关注了这里的大多数帖子的主要内容,如果未能解决你的问题,请参考以下文章

无法使用节点到数据库运行 MongoDB Atlas URL 的脚本

即使它存在,我也无法从 mongodb 中检索值

为啥即使在节点服务器和 mongodb 加载后 localhost 也没有加载?

即使已经安装了可再发行组件,也无法运行 VS 2013 项目?

即使已经安装了mongodb,我在安装解析时是不是需要安装mongodb-runner

HKObserverQuery 无法在 iPhone 上运行