无法远程连接MongoDB

时间:2016-02-11 06:17:03

标签: mongodb

我无法通过任何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。我的设置有问题吗?

1 个答案:

答案 0 :(得分:0)

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

  1. 服务器的防火墙(运行MongoDB实例)可能阻止来自外部IP的所有传入请求
  2. 如果您使用的是Amazon EC2实例,则防火墙是不够的。您需要通过亚马逊控制台打开端口和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