2016-01-23 35 views
12

Ho installato mongo su machine1 (Ubuntu 14.04.3 LTS server) nella mia rete locale. Ho anche aperto la porta 27017 come indicato nel this guida utilizzando i seguenti comandi:Impossibile collegarsi a mongo sul server remoto

sudo iptables -A INPUT -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT 
sudo iptables -A OUTPUT -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT 

regole attuali sono (iptables -L):

Chain INPUT (policy ACCEPT) 
target  prot opt source    destination 
ACCEPT  tcp -- anywhere    anywhere    tcp dpt:27017 state NEW,ESTABLISHED 

Chain FORWARD (policy ACCEPT) 
target  prot opt source    destination 

Chain OUTPUT (policy ACCEPT) 
target  prot opt source    destination 
ACCEPT  tcp -- anywhere    anywhere    tcp spt:27017 state ESTABLISHED 

Ma io non sono in grado di connettersi a questa porta da machine2 (nella stessa rete):

$ mongo --host 192.168.0.108 
MongoDB shell version: 3.0.4 
connecting to: 192.168.0.108:27017/test 
2016-01-23T18:02:14.848+0530 W NETWORK Failed to connect to 192.168.0.108:27017, reason: errno:61 Connection refused 
2016-01-23T18:02:14.850+0530 E QUERY Error: couldn't connect to server 192.168.0.108:27017 (192.168.0.108), connection attempt failed 
    at connect (src/mongo/shell/mongo.js:181:14) 
    at (connect):1:6 at src/mongo/shell/mongo.js:181 
exception: connect failed 

Ho anche provato a verificare se la porta è stata aperta o meno:

$ nc -v 192.168.0.108 27017 
nc: connectx to 192.168.0.108 port 27017 (tcp) failed: Connection refused 

Non sono sicuro di ciò che mi manca. Deve essere un errore stupido mentre sto installando mongo per la prima volta. Aiuto di Pls.

Update (per i dubbi sollevati nelle risposte correnti)

  1. Già la sua esecuzione. Sono in grado di connettermi a mongo formando la stessa macchina ma non dall'altra macchina. Il demone è in esecuzione: $ service mongod status mongod start/running, process 31205 e la porta è 27017 $ sudo netstat -tulpn |grep 27017 tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 31205/mongod
  2. Ho cambiato il bind_ip in 0.0.0.0 e riavviato mongo. Ancora lo stesso errore sta arrivando.

Mongo registra:

$ cat /var/log/mongodb/mongod.log 
2016-01-23T16:28:13.155+0530 I CONTROL [initandlisten] MongoDB starting : pid=31205 port=27017 dbpath=/var/lib/mongodb 64-bit host=dexter 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] db version v3.2.1 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] allocator: tcmalloc 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] modules: none 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] build environment: 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten]  distmod: ubuntu1404 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten]  distarch: x86_64 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten]  target_arch: x86_64 
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } } 
2016-01-23T16:28:13.173+0530 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-01-23T16:28:14.444+0530 I CONTROL [initandlisten] 
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] **  We suggest setting it to 'never' 
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] 
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] **  We suggest setting it to 'never' 
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] 
2016-01-23T16:28:14.444+0530 I FTDC  [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data' 
2016-01-23T16:28:14.444+0530 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker 
2016-01-23T16:28:14.949+0530 I NETWORK [initandlisten] waiting for connections on port 27017 
2016-01-23T16:38:37.046+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37032 #1 (1 connection now open) 
2016-01-23T16:39:31.447+0530 I NETWORK [conn1] end connection 127.0.0.1:37032 (0 connections now open) 
2016-01-23T16:49:24.240+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37033 #2 (1 connection now open) 
2016-01-23T16:49:38.249+0530 I NETWORK [conn2] end connection 127.0.0.1:37033 (0 connections now open) 
2016-01-23T16:51:51.707+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37034 #3 (1 connection now open) 
2016-01-23T16:51:55.785+0530 I NETWORK [conn3] end connection 127.0.0.1:37034 (0 connections now open) 
2016-01-23T17:32:15.546+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37036 #4 (1 connection now open) 
2016-01-23T17:32:21.180+0530 I NETWORK [conn4] end connection 127.0.0.1:37036 (0 connections now open) 
2016-01-23T18:11:57.885+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37037 #5 (1 connection now open) 
2016-01-23T18:29:55.365+0530 I NETWORK [conn5] end connection 127.0.0.1:37037 (0 connections now open) 
+0

Sarebbe possibile aggiungere i log del server mongod da qualche parte? Le 100 linee iniziali sarebbero sufficienti. – nobody

+0

@nobody Aggiornato i registri mongo –

+0

Spero che tu abbia già indizi dai log. – nobody

risposta

5

La questione era bindIp non è cambiata. C'è stato qualche problema nel riavviare Mongo dalla mia parte.

L'abitudine dovrebbe essere quella di verificare se il bindIp è effettivamente cambiato o meno. (usando sudo netstat -tulpn | grep 27017)

0

Assicurarsi di avere un demone in esecuzione sul macchina1 che ascolto sulla porta 27017. Siamo stati sempre lo stesso errore e ha scoperto che il demone non era in funzione.

+0

Sì, è in corso. Sono in grado di connettermi a mongo formando la stessa macchina ma non dall'altra macchina.Il demone è in esecuzione: 'servizio $ stato mongod mongod inizio/corsa, processo 31205' e la porta è 27017 ' $ sudo netstat -tulpn | grep 27017 tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 31205/mongod' –

11

assicurarsi che MongoDB daemon è in esecuzione e in ascolto su 0.0.0.0, ma non porta 127.0.0.1

per esempio, per la mia MongoDB locali, ha questa configurazione:

[[email protected] ~]$ cat /etc/mongod.conf 
## 
### Basic Defaults 
## 

# Comma separated list of ip addresses to listen on (all local ips by default) 
bind_ip = 127.0.0.1 

# Specify port number (27017 by default) 
#port = 27017 

per server di MongoDB per ascoltare per le connessioni remote, è possibile modificare

# Comma separated list of ip addresses to listen on (all local ips by default) 
bind_ip = 0.0.0.0 
+0

Ho cambiato 'bind_ip' e ho riavviato mongo. Ancora lo stesso errore sta arrivando. –

+0

è stato aperto il firewall? quale distro linux è usato? SELINUX è abilitato? ci sono informazioni nei log di mongodb? – vodolaz095

+0

Cosa intendi per firewall aperto? Non ne so molto del firewall. Ho appena aggiunto le regole in 'iptables'. Distro: '$ cat/etc/* rilasciare DISTRIB_ID = Ubuntu DISTRIB_RELEASE = 14.04 DISTRIB_CODENAME = fidato DISTRIB_DESCRIPTION = "Ubuntu 14.04.3 LTS" NAME = "Ubuntu" version = "14.04.3 LTS, Trusty Tahr" ID = ubuntu ID_LIKE = debian pretty_name = "Ubuntu 14.04.3 LTS" version_id = "14.04" ' Non c'è niente nei registri –

Problemi correlati