MongoDB:连接到MongoDB的resolv.conf的DNS问题 [英] MongoDB: DNS issue of resolv.conf connecting to MongoDB

查看:102
本文介绍了MongoDB:连接到MongoDB的resolv.conf的DNS问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从MongoDB Atlas导出一些数据.

如果我执行以下命令,它将尝试连接 localhost 并导出数据.

  mongoexport --uri ="mongodb + srv://<用户名>:<密码> @ name-of-project-x2lpw.mongodb.net/test"-收集用户--out/tmp/testusers.json 

注意:如果您从Windows CMD运行此命令,到 1.1.1.1 的连接成功,请参见以下内容:

 #该文件由man:systemd-resolved(8)管理.不要编辑.##这是一个动态的resolv.conf文件,用于将本地客户端连接到#systemd-resolved的内部DNS存根解析器.该文件列出了所有#个配置的搜索域.##运行"systemd-resolve --status"以查看有关上行DNS服务器的详细信息#当前正在使用.##第三方程序不得直接访问此文件,而只能通过#在/etc/resolv.conf中的符号链接.要以不同的方式管理man:resolv.conf(5),#用静态文件或其他符号链接替换此符号链接.##有关支持的模式的详细信息,请参见man:systemd-resolved.service(8).#对/etc/resolv.conf的操作.域名服务器1.1.1.1选项edns0搜索name.com 

哪个成功导致了连接,如下所示:

如何的问题在于,它不是直接连接到 MongoDB 集群的名称,而是连接到 localhost 非常奇怪,因为我成功导出了从实际连接中寻找的文件.这意味着是指计算机已通过 localhost 正确连接到数据库.

根据此来源,一切似乎都领先以及此处到DNS通过终端连接到 MongoDB 导出导出集合时出现问题.现在从上一篇文章开始,由于多种原因不建议手动更改此地址,因此,在使用 DNS 1.1.1.1 成功导出数据之后,我将其更改回了原始的 DNS 127.0.0.53.但是,我认为这不应该是一种正确的行为,因为每次需要导出数据时,我都必须连续不断地手动更改此地址.

这种奇怪行为的原因可能是什么?因此,如果不手动在DNS地址之间进行切换,那将是一个长期的解决方案呢?

感谢您指出解决此问题的正确方向.

解决方案

似乎大家都已经准备好在提到的链接中找到答案.我将总结一下:

安装resolvconf(对于Ubuntu apt install resolvconf ),将 nameserver 8.8.8.8 行添加到/etc/resolvconf/resolv.conf.d/base,然后运行 sudo resolvconf -u ,并确保 service resolvconf重新启动.要验证运行 systemd-resolve --status .

您应该在第一行看到您的DNS服务器,如下所示:

  DNS服务器:8.8.8.8DNS域:sa-east-1.compute.internalDNSSEC NTA:10.in-addr.arpa16.172.in-addr.arpa 

此解决方案在两次重新启动之间仍然存在.

I want to export some data from MongoDB Atlas.

If I execute the command below, It tries connect localhost and export the data.

mongoexport --uri="mongodb+srv://<username>:<password>@name-of-project-x2lpw.mongodb.net/test" --collection users --out /tmp/testusers.json

Note: If you run this command from Windows CMD, it works fine

After researching the problem and with the help of a user, everything seems to point to a DNS problem and to the related resolv.conf file.

Below the original /etc/resolv.conf:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0
search name.com

At the beginning that resulted into a connection failure as shown below:

But if I would change that address into the following public available address according to what advised on this post to 1.1.1.1 the connection is successful, see below:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 1.1.1.1
options edns0
search name.com

Which resulted into a connection success as shown below:

HOWEVER the problem is that instead of explicitly connecting to the name of the MongoDB cluster, it will connect to the localhost, which is very strange as I successfully exported the files I was looking for from the real connection. Which means that the machine was correctly connecting to the database but via localhost.

Everything seems to lead, also according to this source and also here to a DNS problem while connecting to MongoDB via terminal to export collections. Now from this last post it not advisable to manually change this address for several reasons, therefore right after successfully exporting the data using DNS 1.1.1.1 I changed it back to its original DNS 127.0.0.53. However I don't think this should be a proper behavior as every time I need to export data I will have to continuously and manually change this address.

What could be the reason for this strange behavior? And therefore what could be a long term solution without manually switching between DNS addresses?

Thanks for pointing to the right direction for solving this issue.

解决方案

It seems you all ready have the answer in the links you mentioned. I will summarize this:

Install resolvconf (for Ubuntu apt install resolvconf), add the line nameserver 8.8.8.8 to /etc/resolvconf/resolv.conf.d/base, then run sudo resolvconf -u and to be sure service resolvconf restart. To verify run systemd-resolve --status.

You should see on the first line your DNS server like here:

         DNS Servers: 8.8.8.8
          DNS Domain: sa-east-1.compute.internal
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa

This solution persists between reboots.

这篇关于MongoDB:连接到MongoDB的resolv.conf的DNS问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆