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

后端 未结 6 453
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 07:41

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          


        
相关标签:
6条回答
  • 2020-12-03 07:53

    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
    
    0 讨论(0)
  • 2020-12-03 07:55

    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

    0 讨论(0)
  • 2020-12-03 07:55

    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.

    0 讨论(0)
  • 2020-12-03 08:03

    Try changing owner like this,

    sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
    
    0 讨论(0)
  • 2020-12-03 08:06

    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.

    0 讨论(0)
  • 2020-12-03 08:13

    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

    0 讨论(0)
提交回复
热议问题