mac终端上无法启动mongo(3.6.2)

【问题】
第一次使用MongoDB,安装了但是无法通过终端进入
搜索了相关资料也不知道问题所在何处

希望有人能稍微指点一下,感激不尽

【环境】
终端: mac os
MongoDB:3.6.2

【相关代码】

登入MongoDB

himiMacBookPro:bin himi$ sudo mongod --port 27017 --dbpath /data/db

或者

himiMacBookPro:bin himi$ sudo mongod
mac的$path是设定好的了

↓得到下面

2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] MongoDB starting : pid=24899 port=27017 dbpath=/data/db 64-bit host=himiMacBookPro.local
2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] db version v3.6.2
2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 0.9.8zc 15 Oct 2014
2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] allocator: system
2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] modules: none
2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] build environment:
2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten]     distarch: x86_64
2018-02-12T21:01:38.229+0900 I CONTROL  [initandlisten]     target_arch: x86_64
2018-02-12T21:01:38.229+0900 I CONTROL  [initandlisten] options: { net: { port: 27017 }, storage: { dbPath: "/data/db" } }
2018-02-12T21:01:38.229+0900 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-02-12T21:01:38.229+0900 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,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),statistics_log=(wait=0),verbose=(recovery_progress),
2018-02-12T21:01:38.701+0900 I STORAGE  [initandlisten] WiredTiger message [1518436898:701666][24899:0x7fff75831300], txn-recover: Main recovery loop: starting at 6/4864
2018-02-12T21:01:38.826+0900 I STORAGE  [initandlisten] WiredTiger message [1518436898:826287][24899:0x7fff75831300], txn-recover: Recovering log 6 through 7
2018-02-12T21:01:38.921+0900 I STORAGE  [initandlisten] WiredTiger message [1518436898:921309][24899:0x7fff75831300], txn-recover: Recovering log 7 through 7
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten]
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten]
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten]
2018-02-12T21:01:39.131+0900 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-02-12T21:01:39.131+0900 I NETWORK  [initandlisten] waiting for connections on port 27017

这里会停留很长时间
照理说这个出来之后就应该进入mongo

↓但是过了很久会出现以下内容

2018-02-12T21:06:39.153+0900 I STORAGE  [thread1] createCollection: config.system.sessions with generated UUID: c16f1163-15d8-4132-8a66-5a2e61d855b1
2018-02-12T21:06:39.238+0900 I INDEX    [thread1] build index on: config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 }
2018-02-12T21:06:39.238+0900 I INDEX    [thread1]      building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2018-02-12T21:06:39.260+0900 I INDEX    [thread1] build index done.  scanned 0 total records. 0 secs
2018-02-12T21:06:39.262+0900 I COMMAND  [thread1] command config.$cmd command: createIndexes { createIndexes: "system.sessions", indexes: [ { key: { lastUse: 1 }, name: "lsidTTLIndex", expireAfterSeconds: 1800 } ], $db: "config" } numYields:0 reslen:98 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { W: 1 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_msg 115ms

然后就没有其他内容了.
等了半个小时也没有变化

↓如果在上面的等待的时候control+c,会出现以下内容

^C2018-02-12T22:04:41.601+0900 I CONTROL  [signalProcessingThread] got signal 2 (Interrupt: 2), will terminate after current cmd ends
2018-02-12T22:04:41.601+0900 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
2018-02-12T22:04:41.601+0900 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2018-02-12T22:04:41.603+0900 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
2018-02-12T22:04:41.605+0900 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
2018-02-12T22:04:41.803+0900 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
2018-02-12T22:04:41.805+0900 I CONTROL  [signalProcessingThread] now exiting
2018-02-12T22:04:41.805+0900 I CONTROL  [signalProcessingThread] shutting down with code:0

用了其他的看似是相关的命令,也不是很清楚这代表了什么

himiMacBookPro:~ himi$ sudo /usr/local/mongodb/bin/mongod
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] MongoDB starting : pid=24718 port=27017 dbpath=/data/db 64-bit host=himiMacBookPro.local
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] db version v3.6.2
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 0.9.8zc 15 Oct 2014
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] allocator: system
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] modules: none
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] build environment:
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten]     distarch: x86_64
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten]     target_arch: x86_64
2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] options: {}
2018-02-12T20:31:44.078+0900 I STORAGE  [initandlisten] exception in initAndListen: DBPathInUse: Unable to lock the lock file: /data/db/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /data/db directory, terminating
2018-02-12T20:31:44.078+0900 I CONTROL  [initandlisten] now exiting
2018-02-12T20:31:44.078+0900 I CONTROL  [initandlisten] shutting down with code:100

【自己查找相关资料】

http://www.runoob.com/mongodb...
http://blog.csdn.net/xht555/a...
https://stackoverflow.com/que...
https://www.jianshu.com/p/116...

阅读 5.4k
2 个回答

mongod 是开启数据库进程 并不是 mongo, 实际已经启动了数据库, 你只需要再打开一个 terminal(终端) 然后输入 mongo 就可以了.

mongo 是 mongodb 管理工具, mongod 是 mongodb 数据库进程.

你第一张图 用mongod开机后得到下面这个信息并且一直停留在这个信息是正确的 然后你需要保持这个终端不动,重新开启一个终端 输入mongo

2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] MongoDB starting : pid=24899 port=27017 dbpath=/data/db 64-bit host=himiMacBookPro.local
2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] db version v3.6.2
2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] OpenSSL version: OpenSSL 0.9.8zc 15 Oct 2014
2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] allocator: system
2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] modules: none
2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] build environment:
2018-02-12T21:01:38.228+0900 I CONTROL [initandlisten] distarch: x86_64
2018-02-12T21:01:38.229+0900 I CONTROL [initandlisten] target_arch: x86_64
2018-02-12T21:01:38.229+0900 I CONTROL [initandlisten] options: { net: { port: 27017 }, storage: { dbPath: "/data/db" } }
2018-02-12T21:01:38.229+0900 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-02-12T21:01:38.229+0900 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,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),statistics_log=(wait=0),verbose=(recovery_progress),
2018-02-12T21:01:38.701+0900 I STORAGE [initandlisten] WiredTiger message 1518436898:701666, txn-recover: Main recovery loop: starting at 6/4864
2018-02-12T21:01:38.826+0900 I STORAGE [initandlisten] WiredTiger message 1518436898:826287, txn-recover: Recovering log 6 through 7
2018-02-12T21:01:38.921+0900 I STORAGE [initandlisten] WiredTiger message 1518436898:921309, txn-recover: Recovering log 7 through 7
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten]
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten]
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-02-12T21:01:39.125+0900 I CONTROL [initandlisten]
2018-02-12T21:01:39.131+0900 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-02-12T21:01:39.131+0900 I NETWORK [initandlisten] waiting for connections on port 27017
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进