Coder Social home page Coder Social logo

mongodb connection about nitrite-java HOT 15 CLOSED

nitrite avatar nitrite commented on June 6, 2024
mongodb connection

from nitrite-java.

Comments (15)

anidotnet avatar anidotnet commented on June 6, 2024 1

Can you please try with adding --net="host" to the command? It will connect your host machine's network with docker container and can access any server running in the host using localhost.

For further info you can consult this SO answer.

from nitrite-java.

anidotnet avatar anidotnet commented on June 6, 2024

What is the docker command you are using to run the image?

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

I used docker run image_id

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

2017-06-08 03:20:22.213 INFO 5 --- [ main] org.mongodb.driver.cluster : No server chosen by WritableSe
Description{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=0.0.0.0:27017, type=UNKNOWN, sta
cketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]}

Is the error I got even adding the --net="host" . I 'll try to check the set up without docker also.
Thanks. I'll come back later with some feedback

from nitrite-java.

anidotnet avatar anidotnet commented on June 6, 2024

First modify your docker file as you are not using the ssl certificate file (you will not be able to expose https endpoint)

FROM dizitart/nitrite-datagate

##COPY keystore.jks /

## Connection details (Replace with your own values)
ENV DATAGATE_HOST "0.0.0.0"
ENV DATAGATE_HTTP_PORT "8080"
##ENV DATAGATE_HTTPS_PORT "8443"
ENV DATAGATE_MONITOR_PORT "9090"
##ENV DATAGATE_KEY_STORE "keystore.jks"
##ENV DATAGATE_KEY_PASSWORD "s3cret"

## Mongo connection details (Replace with your own values)
ENV DATAGATE_MONGO_HOST "127.0.0.1"
ENV DATAGATE_MONGO_PORT "27017"
ENV DATAGATE_MONGO_USER "admin"
ENV DATAGATE_MONGO_PASSWORD "password"
ENV DATAGATE_MONGO_DATABASE "demo"

## Starts the server
RUN ["chmod", "+x", "./datagate.sh"]
ENTRYPOINT [ "./datagate.sh" ]

Now run the below commands from the same directory as your Dockerfile

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker build -t datagate-test .
docker run --net='host' -p 8080:8080 -p 9090:9090 --name datagate-test datagate-test

You will see the spring boot logs are coming up. Once it is loaded, you can access the portal using the url - http://localhost:8080/datagate/

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

Thank you!
I think the problem is that datagate has problem to connect to my mongoDB instance.
I will take a look to the source code to understand what's going there.
I 'll come back by the end of the day.

Thanks for your help

from nitrite-java.

anidotnet avatar anidotnet commented on June 6, 2024

Just wondering have you tried the steps i mentioned? It should be get you going.

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

Hello @anidotnet
I think I've solved my problem partially with mongo. I got datagate to connect to it but the authentication failed. I got this error:

mp/jetty-docbase.7893720865126747271.8080/,AVAILABLE}
2017-06-08 23:34:17.929  INFO 5 --- [           main] org.eclipse.jetty.server.Server          : Started @5100ms
2017-06-08 23:34:18.182  INFO 5 --- [           main] Nitrite DataGate                         : jolokia: No access restrictor found, access to any MBean is allowed
2017-06-08 23:34:18.456  INFO 5 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requir
edClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2017-06-08 23:34:18.612  INFO 5 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server 127.0.0.1:27017

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='admin', source='demo', password=<hidden>, mechanismProperties={}}
        at com.mongodb.connection.SaslAuthenticator.wrapInMongoSecurityException(SaslAuthenticator.java:157) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:37) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:66) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:44) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:162) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:44) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:109) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:46) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongo-java-driver-3.4.2.jar!/:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 127.0.0.1:27017. The full response is { "ok" : 0.0, "errmsg"
: "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
        at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:117) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator.access$000(SaslAuthenticator.java:37) ~[mongo-java-driver-3.4.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:50) ~[mongo-java-driver-3.4.2.jar!/:na]
        ... 9 common frames omitted

2017-06-08 23:34:18.635  INFO 5 --- [           main] org.mongodb.driver.cluster               : No server chosen by WritableServerSelector from cluster description Cluster
Description{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.Mongo
SecurityException: Exception authenticating MongoCredential{mechanism=null, userName='admin', source='demo', password=<hidden>, mechanismProperties={}}}, caused by {com.mon
godb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 127.0.0.1:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication
failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}]}. Waiting for 30000 ms before timing out

Do you have any idea about it ?
I'll keep looking for the solution.
I'll come back if I solved it

from nitrite-java.

anidotnet avatar anidotnet commented on June 6, 2024

Please make sure the the demo database exists in mongo and the admin user is an authorized user to access demo. Test the connectivity with a mongo client first. And of course password provided is correct without any trailing whitespace.

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

Hey @anidotnet. I've FINALLY got datagate up and running without problem.
You were right. I did set up well the security stuff at my mongodb side..

But http://localhost:8080/datagate/ is not working.

When I run docker ps I got :

C:\Users\Kalmogo>docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
604540db7e6c        datagate-test       "./datagate.sh"          6 minutes ago       Up 6 minutes                                   datagate-test7
9f0513f1fb83        34ba9aead272        "docker-entrypoint..."   About an hour ago   Up About an hour    0.0.0.0:27017->27017/tcp   determined_swanson

Any idea why I can access to http://localhost:8080/datagate/ ?
Thanks!!

from nitrite-java.

anidotnet avatar anidotnet commented on June 6, 2024

Your datagate-test image is not exposing any port. Can you please tell me what command have you used to run the image?

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

I used to run docker run --net='host' -p 8080:8080 -p 9090:9090 --name datagate-test datagate-test
It is what you suggested me to do.
I noticed the missing exposed port. I've reached to link a port but it is marked as tcp.
I think it is the last remaining step before having my datagate running correctly

from nitrite-java.

rokal avatar rokal commented on June 6, 2024

I finally get nitrite datagate configured.
I've downloaded zip, installed mongoDb locally, created my .keystore using keystore explorer specify the path in the config file, and everythink works fine now. I'm planning to use nitrite database in javafx application.

It is a very nice tool you guys have built.

I'll stick around for anyone who need help (no very advanced but I can help somehow).

Thanks @anidotnet for all your advices !!!

from nitrite-java.

anidotnet avatar anidotnet commented on June 6, 2024

Good to know that you have found it useful. Please spread the word if you like it.

from nitrite-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.