简体   繁体   中英

Cannot connect MongoDB remotely

I cannot connect to MongoDB by any GUI. But MongoDB is running because I can use the shell to manage the DM smoothly.

Here is the log

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:

I saw some similar questions and there are some solutions to suggest comment the line # bindIp: 127.0.0.1 and delete the /var/lib/mongodb/mongod.lock . Is there any problem of my setting?

There could be various reasons that you are not able to connect remotely to the running instance of MongoDB. I'm listing a few reasons here:

  1. The firewall of the server (on which your MongoDB instance is running) might be blocking all the incoming request from external IP
  2. If you are using Amazon EC2 instance, Firewall isn't enough. You need to open the port and the IP via the Amazon console
  3. The port 27017 might not be open on the server to connect (Use various port check to verify like https://www.site24x7.com/port-test.html )
  4. The connection might be getting dropped due to TCP timeout
  5. Try setting bindIp to 0.0.0.0 (Reference: 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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM