Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied
my mongodb server had stoped working on my mac:
check the log file and found the error:
Check the /tmp/mongodb-27017.sock
permission, owner is root?
output
"0 srwx------ 1 mongodb mongodb 0 Aug 24 04:01 /tmp/mongodb-27017.sock"
solution:
then
start mongo, it appears:
MongoDB shell version v4.2.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-04-08T20:05:01.381+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:341:17
@(connect):2:6
2020-04-08T20:05:01.384+0800 F - [main] exception: connect failed
2020-04-08T20:05:01.384+0800 E - [main] exiting with code 1
try to repair, but failed!
Error parsing command line: unrecognised option '-–repair'
try 'mongod --help' for more information
check th mongod.conf file (/usr/local/etc/mongod.conf), but it's not in the path.
ok, reinstall ?
$ brew uninstall [email protected]
$ brew install [email protected]
$ brew services start [email protected]
In addition to the binaries, the install creates:
- the configuration file (
/usr/local/etc/mongod.conf
) - the
log directory path
(/usr/local/var/log/mongodb
) - the
data directory path
(/usr/local/var/mongodb
)
run mongodb community :
$ mongod --config /usr/local/etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 37247
ERROR: child process failed, exited with error number 1
To see additional information in this output, start without the "--fork" option.
192:etc jessea$ mongod --config /usr/local/etc/mongod.conf
2020-04-08T21:51:29.689+0800 F CONTROL [main] Failed global initialization: FileNotOpen: logpath "/usr/local/var/log/mongodb/mongo.log" should name a file, not a directory.
$ cd /usr/local/var/log/mongodb/
// if you want to remove file, use rm filename
$ rm -r mongo.log
$ touch mongo.log
// To run MongoDB manually as a background process
$ mongod --config /usr/local/etc/mongod.conf --fork
about to fork child process, waiting until server is ready for connections.
forked process: 37320
child process started successfully, parent exiting
$ brew services start [email protected]
Service `mongodb-community` already started, use `brew services restart mongodb-community` to restart.
$ brew services list
Name Status User Plist
mongodb-community started /Users/jessea/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
// connect a mongo
shell to the running instance. ( or "mongo --port 27017")
$ mongo
MongoDB shell version v4.2.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("751dee53-9e1f-4c41-a361-95e2918f4426") }
MongoDB server version: 4.2.5
Server has startup warnings:
2020-04-08T22:05:15.048+0800 I CONTROL [initandlisten]
2020-04-08T22:05:15.049+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-04-08T22:05:15.050+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-04-08T22:05:15.051+0800 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> exit