Mongodb 不适用于 Ubuntu 16.04

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37565758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:45:49  来源:igfitidea点击:

Mongodb not working on Ubuntu 16.04

mongodbubuntu

提问by Yya09

I installed mongodb following this tutorial here, no errors during the installation but when I try to start the mongod server using this command sudo systemctl start mongodbas the tutorial mentions, i getting this error when i try to check whether it is running using this command sudo systemctl status mongodb.

在这里按照本教程安装了 mongodb ,在安装过程中没有错误,但是当我尝试使用sudo systemctl start mongodb教程中提到的此命令启动 mongod 服务器时,当我尝试使用此命令检查它是否正在运行时出现此错误sudo systemctl status mongodb

● mongodb.service - High-performance, schema-free document-oriented 

database
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: 
   Active: failed (Result: exit-code) since Rab 2016-06-01 18:04:20 MYT; 4s ago
  Process: 8241 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
 Main PID: 8241 (code=exited, status=14)

Jun 01 18:04:20 yasinya systemd[1]: Started High-performance, schema-free docume
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Main process exited, code=e
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Unit entered failed state.
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Failed with result 'exit-co
lines 1-10/10 (END)

so can anyone tell what is wrong and how I can fix it.

所以任何人都可以告诉我出了什么问题以及我如何解决它。

回答by Ranjeet Singh

Recently i have solved the same issue. I was unable to find the solution on googled, but i get come clues to, how get figure it out. In my case this issue was related to mongodb-27017.sock file.

最近我解决了同样的问题。我无法在谷歌上找到解决方案,但我得到了一些线索,如何弄清楚。就我而言,此问题与 mongodb-27017.sock 文件有关。

Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted

So i have changed the permission of /tmp/mongodb-27017.sock file to default mongodbuser.

所以我已将 /tmp/mongodb-27017.sock 文件的权限更改为默认mongodb用户。

sudo chown mongodb /tmp/mongodb-27017.sock
sudo chgrp mongodb /tmp/mongodb-27017.sock

After this sudo systemctl status mongodbworking fine and mongodbis started.

在此sudo systemctl status mongodb工作正常并mongodb启动之后。

回答by Eudie

Stumbed on the same issue, just reboot

遇到同样的问题,重启

sudo reboot

回答by Dara Vichit

This error returned by MongoDB applications which encounter an unrecoverable error, an uncaught exception or uncaught signal. The system exits without performing a clean shutdown.

此错误由遇到不可恢复错误、未捕获异常或未捕获信号的 MongoDB 应用程序返回。系统退出而不执行干净关闭。

I solved the problem by the command:

我通过命令解决了这个问题:

sudo chown -R mongodb:mongodb /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chmod -R 755 /var/lib/mongodb
sudo chmod -R 755 /var/log/mongodb

sudo chown mongodb /tmp/mongodb-27017.sock
sudo chgrp mongodb /tmp/mongodb-27017.sock

Then restart service

然后重启服务

sudo systemctl restart mongod

Then check your mongodb service

然后检查你的mongodb服务

sudo systemctl status mongod

回答by Sagar Jethi

I had same use ,

我有同样的用途,

get solve just

得到解决只是

sudo reboot

回答by Hoi Yuen

The first thing, you should examine the mongo log. It should tell you what went wrong.

首先,您应该检查 mongo 日志。它应该告诉你出了什么问题。

$ tail -n 100 /var/log/mongodb/mongod.log

$ tail -n 100 /var/log/mongodb/mongod.log

This command will show last 100 lines of the log file which will point you to the exact problem.

此命令将显示日志文件的最后 100 行,它将指向您确切的问题。

For example, mine wasn't working because i was running a mongoinstance using the same port 27017. when i ran another instance, the instance failed to load.

例如,我的无法工作,因为我正在mongo使用相同的端口运行一个实例27017。当我运行另一个实例时,该实例无法加载。

LOG

日志

2018-05-11T19:03:49.102-0400 I CONTROL  [initandlisten] MongoDB starting : pid=1247 port=27017 dbpath=/var/lib/mongodb 64-bit host=dev-hyuen
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] db version v3.2.20
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] git version: a7a144f40b70bfe290906eb33ff2714933544af8
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] modules: none
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] build environment:
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     distmod: ubuntu1604
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     distarch: x86_64
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2018-05-11T19:03:49.124-0400 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 127.0.0.1:27017
2018-05-11T19:03:49.124-0400 E NETWORK  [initandlisten]   addr already in use
2018-05-11T19:03:49.124-0400 E STORAGE  [initandlisten] Failed to set up sockets during startup.
2018-05-11T19:03:49.124-0400 I CONTROL  [initandlisten] dbexit:  rc: 48

回答by Etibar Hasanov

I was getting the similar error, in my case mongo couldn't use 27017. I needed to stop whatever was using 27017 port and restart mongo.

我遇到了类似的错误,在我的情况下 mongo 无法使用 27017。我需要停止使用 27017 端口的任何内容并重新启动 mongo。

回答by phenric

The problem may be related to the lack of space with your /dev/root/(it was mine).

问题可能与您的/dev/root/(是我的)空间不足有关。

Check with df -hand see if there enough free space. Otherwise, as explain there, try to free some space by moving the log files to another disk.

检查df -h并查看是否有足够的可用空间。否则,按照那里的解释,尝试通过将日志文件移动到另一个磁盘来释放一些空间。

sudo /etc/init.d/rsyslog stop
sudo mv /var/log /OTHERDISK/
sudo ln -s /OTHERDISK/log /var/log
sudo /etc/init.d/rsyslog start

Hope it could help as it helps me

希望它可以帮助我,因为它可以帮助我

回答by Abhijeet kumar

In my case the system was not able to to find mongod.service Running the following command will fixed it

在我的情况下,系统无法找到 mongod.service 运行以下命令将修复它

sudo systemct1 enable mongod

then restart the database by

然后通过以下方式重新启动数据库

sudo service mongod restart

回答by xingliang cai

After googling around for a while. I found that that is because the permission setting on /var/lib/mongodb and /tmp/mongodb-27017.lock are wrong. You will have to change the owner to monogdb user

在谷歌搜索了一段时间后。我发现这是因为 /var/lib/mongodb 和 /tmp/mongodb-27017.lock 上的权限设置错误。您必须将所有者更改为 monogdb 用户

chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock

回答by vasudev.p

Step1. sudo systemctl stop mongodb

第1步。 sudo systemctl stop mongodb

Step2. sudo systemctl start mongod

第2步。 sudo systemctl start mongod

Step3. sudo systemctl status mongod

第三步。 sudo systemctl status mongod

I hope it helps you

我希望它能帮助你