启动即服务时,MongoDB无法连接

时间:2017-11-30 17:49:24

标签: mongodb ubuntu

我在我的名为automationTaskV3的ubuntu服务器(16.04)上安装了mongodb(3.2.18)。当我在我的服务器上工作时,它工作,但当我尝试从我的计算机连接时,它只有在mongodb作为服务启动时才会失败。

例如,如果我以这种方式启动mongod:

sudo mongod

它可以工作,我可以访问我的数据库 但如果我这样做:

sudo service mongod start

我无法从计算机连接。 否则mongod服务状态似乎没问题:

sudo service mongod status

● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-11-30 17:34:46 UTC; 8min ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 17712 (mongod)
   CGroup: /system.slice/mongod.service
           └─17712 /usr/bin/mongod --quiet --auth --config /etc/mongod.conf

November 30 17:34:46 automationTaskV3 systemd [1]:启动高性能,无架构的面向文档的数据库。 11月30日17:38:09 automationTaskV3 systemd [1]:启动高性能,无架构的面向文档的数据库。 11月30日17:39:29 automationTaskV3 systemd [1]:启动高性能,无架构的面向文档的数据库。

目前我正在尝试访问没有凭据。 这是我的mongod.service文件:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet  --config /etc/mongod.conf
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

这里是我的mongod.conf文件

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


#processManagement:

这可能是用户正确的问题吗?当我按照教程中的步骤进行操作时,这似乎很奇怪: https://www.linode.com/docs/databases/mongodb/install-mongodb-on-ubuntu-16-04 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

1 个答案:

答案 0 :(得分:1)

正如我在评论中所说,其IP绑定问题。所以你甚至可以尝试这个解决方案。

您可以使用ssh隧道访问远程计算机的27017端口,因为这是最简单的方法,也是一种安全的方式。

ssh -L 27017:localhost:27017 username@remoteaddress.com

此命令说明本地计算机的27017端口转发到远程计算机的localhost:27017。 如果您没有设置ssh密钥,系统将提示您输入密码(远程计算机)。现在您可能会收到远程计算机的ssh提示,除非您要关闭端口转发,打开终端的新选项卡或Robomongo,现在可以连接到localhost:27017。因此,就像MongoDB安装在本地计算机上一样,实际上,它是使用ssh从远程计算机上提供的。

要了解有关ssh隧道的更多信息,请阅读:https://www.ssh.com/ssh/tunneling

相关问题