mac mongodb

Mac OSX 平台安装 MongoDB

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

MAC 设置环境变量path的几种方法

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

Unable to connect to mongodb Error: couldn’t connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

百世修行

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值