【问题标题】:Cannot connect MongoDB remotely无法远程连接 MongoDB
【发布时间】:2016-05-21 19:17:00
【问题描述】:

我无法通过任何 GUI 连接到 MongoDB。但是 MongoDB 是运行的,因为我可以使用 shell 顺利地管理 DM。

这是日志

2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] MongoDB starting : 

pid=2559 port=27017 dbpath=/var/lib/mongo 64-bit host=ip-172-31-30-5
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] db version v3.2.1
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.0-fips 29 Mar 2010
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] modules: none
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] build environment:
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten]     distmod: amazon
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten]     distarch: x86_64
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2016-02-11T05:58:44.033+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-02-11T05:58:44.053+0000 I -        [initandlisten] Detected data files in /var/lib/mongo created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-02-11T05:58:44.053+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-02-11T05:58:44.291+0000 I CONTROL  [initandlisten] 
2016-02-11T05:58:44.291+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-02-11T05:58:44.291+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-02-11T05:58:44.291+0000 I CONTROL  [initandlisten] 
2016-02-11T05:58:44.293+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data'
2016-02-11T05:58:44.293+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
2016-02-11T05:58:44.295+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker

mongd.conf

# mongod.conf

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

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

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

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 27017
#  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

我看到了一些类似的问题,并且有一些解决方案建议评论# bindIp: 127.0.0.1 并删除/var/lib/mongodb/mongod.lock。我的设置有问题吗?

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    您无法远程连接到正在运行的 MongoDB 实例可能有多种原因。我在这里列出几个原因:

    1. 服务器(您的 MongoDB 实例在其上运行)的防火墙可能会阻止来自外部 IP 的所有传入请求
    2. 如果您使用的是 Amazon EC2 实例,防火墙是不够的。您需要通过 Amazon 控制台打开端口和 IP
    3. 端口27017可能未在服务器上打开连接(使用各种端口检查来验证,如https://www.site24x7.com/port-test.html
    4. 连接可能由于 TCP 超时而断开
    5. 尝试将bindIp 设置为0.0.0.0(参考:mongodb.conf bind_ip = 127.0.0.1 does not work but 0.0.0.0 works & MongoDB bind_ip won't work unless set to 0.0.0.0

    【讨论】:

      猜你喜欢
      • 2018-11-12
      • 2017-05-16
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      相关资源
      最近更新 更多