MongoDB - Permission denied for socket: /tmp/mongodb-27017.sock
Asked Answered
P

6

21

I had an unclean shutdown of MongoDB on Ubuntu 10.04 LTS. Now when I login as root and run Mongodb via service mongodb start, I get below error-

Mon Dec 12 13:53:15 [initandlisten] ERROR: listen(): bind() failed errno:13 Permission denied for socket: /tmp/mongodb-27017.sock

When I run MongoDB manually via root, it works just fine.

I can confirm that there is no /tmp/mongodb-27017.sock file

root@devbox:~# ll /tmp/
total 16
drwxr-xr-x  4 root root 4096 2011-12-12 13:53 ./
drwxr-xr-x 25 root root 4096 2011-12-11 13:06 ../
drwxrwxrwt  2 root root 4096 2011-12-12 13:01 .ICE-unix/
drwxrwxrwt  2 root root 4096 2011-12-12 13:01 .X11-unix/

Where do I begin troubleshooting?

Privity answered 12/12, 2011 at 18:58 Comment(0)
C
18

What's are the file permissions on /tmp? Is it possible that they've been changed?

A

# ls -ld /tmp

will tell you.

If you're unsure try:

# chown root:root /tmp
# chmod 1777 /tmp

That might fix it.

Coelacanth answered 12/12, 2011 at 19:22 Comment(4)
You are right, after unclean shutdown, thins got messed up and /tmp was not write-able anymore by MongoDb user.Privity
Great. Glad we found you an answer.Coelacanth
You save my day. Thank you!Hyperthyroidism
Excellent. Glad to help.Coelacanth
P
20

Try changing owner like this,

sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
Photobathic answered 9/8, 2016 at 6:25 Comment(4)
This fixed my issue ! ThanksUtas
Thank god it finally worked!! Thanks! It's weird because /tmp had rwx permission for all three yet the operation was not permitted until I tried your example.Briefcase
It seems when using Debian based systems the user is mongodb, but when using Centos systems the user id mongod (notice no 'b' in the user name). Be careful out there!Saluki
this fixed my issue | ThanksElegit
C
18

What's are the file permissions on /tmp? Is it possible that they've been changed?

A

# ls -ld /tmp

will tell you.

If you're unsure try:

# chown root:root /tmp
# chmod 1777 /tmp

That might fix it.

Coelacanth answered 12/12, 2011 at 19:22 Comment(4)
You are right, after unclean shutdown, thins got messed up and /tmp was not write-able anymore by MongoDb user.Privity
Great. Glad we found you an answer.Coelacanth
You save my day. Thank you!Hyperthyroidism
Excellent. Glad to help.Coelacanth
P
5

we use mac and install mongodb, usually do not need mongodb.conf, so, try this:

sudo chown -R your-username /tmp/

ps:your-username is your username in mac os, not root.if you don't know what is your username,there's a command:

whoami
Phosphor answered 8/4, 2019 at 12:2 Comment(0)
S
1

In the Versions before 3.0 the socket was created with 777 permissions by default. Most the most correct way set permissions to mongod socket is set value in mongodb.conf. For example:

sudo vim /usr/local/etc/mongodb.conf

and insert line:

filePermissions = 0777 

to it.

In case if you will try directly change permissions to /tmp/mongodb-27017.sock with chown and chmod you can have a chance set it temporary. And have a old permissions after mongod service restart or server reboot.

Spalding answered 1/11, 2018 at 23:9 Comment(0)
G
0

Make sure the Ubuntu mongo user has access to the file. The Mongo Ubuntu service uses the Ubuntu Mongo user. To find out the mongo username is go to /var/lib/mongodb directory and show the permissions: ls -l

Gersham answered 12/12, 2011 at 19:19 Comment(1)
root@devbox:~# ls -l /var/lib/mongodb total 4 drwxr-xr-x 2 mongodb mongodb 4096 2011-12-12 13:53 journal -rwxr-xr-x 1 mongodb mongodb 0 2011-12-12 13:53 mongod.lockPrivity
S
0

I have same issue, because I have use run mongodb by root, it will start fail with systemctl on CentOS 7.3.

Please use the correct permission for mongodb. $ sudo chown -R mongod:mongod \ /var/run/mongodb/mongod.pid \ /tmp/mongodb-27017.sock \ /var/lib/mongo/

If we have other fail like Error reading file /path/file: Permission denied, maybe we can fix it by SELinux. $ sudo chcon -v -t mongod_var_lib_t /path/file

By the way, I don't recomment use the 777 permission, it's so danger. :P

Sin answered 13/4, 2017 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.