Sto provando a creare un server mongodb remoto con cui lavorare con il mio progetto java.Impossibile connettersi al server mongodb remoto
Sto usando vagrante + ansible per creare l'ambiente, ma so che non riesco a ottenere una connessione.
Ricevo sempre la connessione rifiutata attraverso la rete. lo stesso codice su localhost funziona perfettamente.
Sto usando scatola vagabondo: chef/centos-6.5
ed i miei compiti ansible sono i seguenti:
- name: Download EPEL Repo get_url: url=http://dl.fedoraproject.org/pub/epel/6/x86_64/epel- release-6-8.noarch.rpm dest=/tmp/epel-release-6-8.noarch.rpm - name: Install EPEL Repo command: rpm -ivh /tmp/epel-release-6-8.noarch.rpm creates=/etc/yum.repos.d/epel.repo - name: Install libselinux-python yum: name=libselinux-python - name: Create the repository for 10Gen copy: src=10gen.repo.j2 dest=/etc/yum.repos.d/10gen.repo - name: Create the EPEL Repository. copy: src=epel.repo.j2 dest=/etc/yum.repos.d/epel.repo - name: Create the GPG key for EPEL copy: src=RPM-GPG-KEY-EPEL-6 dest=/etc/pki/rpm-gpg - name: Create the mongod user user: name=mongod comment="MongoD" - name: Create the data directory for the namenode metadata file: path={{ mongodb_datadir_prefix }} owner=mongod group=mongod state=directory - name: Install the mongodb package yum: name={{ item }} state=installed with_items: - libselinux-python - mongo-10gen - mongo-10gen-server - bc - python-pip - name: Install the latest pymongo package pip: name=pymongo state=latest use_mirrors=no
ho aggiunto le iptables eccezioni:
sudo iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
che è attivo:
[[email protected] ~]# iptables -L -v Chain INPUT (policy ACCEPT 209 packets, 13148 bytes) pkts bytes target prot opt in out source destination 1070 68777 ACCEPT tcp -- any any anywhere anywhere tcp dpt:27017
mio codice Java che definisce MongoDbFactory
public @Bean MongoDbFactory mongoDbFactory() throws Exception { MongoClient mongo = new MongoClient("<ip-of-machine>", 27017); return new SimpleMongoDbFactory(mongo, "test"); }
ma ottengo sempre la seguente eccezione quando si tenta di connettersi ad esso.
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=192.168.1.11:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused}}]
se corro MongoDB da localhost e cambiare l'IP di conseguenza, tutto funziona bene.
Grazie
Si può telnet per l'indirizzo di destinazione e la porta? 'telnet 27017' –
no, questo non funziona: MacBook-Pro: ~ me $ telnet 192.168.1.11:27017 192.168.1.11:27017: nomenodo e nomeserver forniti o non noti. Ping funziona anche se – Gleeb
Non è giusto, non utilizzare i due punti tra host e porta quando si utilizza Telnet. 'telnet 192.168.1.11 27017' –