Mac OSX 平台安装 MongoDB
install mongodb
brew install mongodb
启动 MongoDB
cc$ mongod
2018-08-15T22:56:23.632+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] MongoDB starting : pid=21891 port=27017 dbpath=/data/db 64-bit host=zhangwei.local
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] db version v4.0.1
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] git version: 54f1582fc6eb01de4d4c42f26fc133e623f065fb
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] allocator: system
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] modules: none
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] build environment:
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] distarch: x86_64
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] options: {}
2018-08-15T22:56:23.646+0800 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] now exiting
2018-08-15T22:56:23.646+0800 I CONTROL [initandlisten] shutting down with code:100
cc$ mongo
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
2018-08-15T23:02:40.875+0800 E QUERY [js] 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:257:13
@(connect):1:6
exception: connect failed
error
cc$ mongod -repair
2018-08-15T23:06:56.181+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-15T23:06:56.194+0800 I CONTROL [initandlisten] MongoDB starting : pid=21921 port=27017 dbpath=/data/db 64-bit host=zhangwei.local
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] db version v4.0.1
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] git version: 54f1582fc6eb01de4d4c42f26fc133e623f065fb
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] allocator: system
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] modules: none
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] build environment:
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] distarch: x86_64
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] options: { repair: true }
2018-08-15T23:06:56.195+0800 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] now exiting
2018-08-15T23:06:56.195+0800 I CONTROL [initandlisten] shutting down with code:100
root 修复 mongodb
sh-3.2# mongod --repair
2018-08-15T23:14:19.953+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] MongoDB starting : pid=21947 port=27017 dbpath=/data/db 64-bit host=zhangwei.local
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] db version v4.0.1
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] git version: 54f1582fc6eb01de4d4c42f26fc133e623f065fb
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] allocator: system
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] modules: none
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] build environment:
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] distarch: x86_64
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-08-15T23:14:19.968+0800 I CONTROL [initandlisten] options: { repair: true }
2018-08-15T23:14:19.969+0800 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-08-15T23:14:20.531+0800 I STORAGE [initandlisten] WiredTiger message [1534346060:531103][21947:0x7fff8e8b2380], txn-recover: Set global recovery timestamp: 0
2018-08-15T23:14:20.558+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten]
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten]
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten]
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten]
2018-08-15T23:14:20.595+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2018-08-15T23:14:20.600+0800 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: f9d7223b-8f03-4572-86ad-377bd1f73506
2018-08-15T23:14:20.642+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 4.0
2018-08-15T23:14:20.644+0800 I STORAGE [initandlisten] repairDatabase admin
2018-08-15T23:14:20.644+0800 I STORAGE [initandlisten] Repairing collection admin.system.version
2018-08-15T23:14:20.658+0800 I STORAGE [initandlisten] Verify succeeded on uri table:collection-0--9169905283016474424. Not salvaging.
2018-08-15T23:14:20.678+0800 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { _id: 1 }, name: "_id_", ns: "admin.system.version" }
2018-08-15T23:14:20.678+0800 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2018-08-15T23:14:20.700+0800 I STORAGE [initandlisten] finished checking dbs
2018-08-15T23:14:20.700+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2018-08-15T23:14:20.700+0800 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2018-08-15T23:14:20.700+0800 I STORAGE [initandlisten] WiredTigerKVEngine shutting down
2018-08-15T23:14:20.840+0800 I STORAGE [initandlisten] shutdown: removing fs lock...
2018-08-15T23:14:20.843+0800 I CONTROL [initandlisten] now exiting
2018-08-15T23:14:20.843+0800 I CONTROL [initandlisten] shutting down with code:0
Same error here, this worked for me:
sudo mongod --repair
followed by
sudo mongod
(forget about service and start)
Then on a different tab/terminal:
mongo