Setup MongoDB to be reachable from remote application - node.js

I have a web server that runs MongoDB. It will save some data that I need a second application installed in a different computer to be able to query on. The server with MongoDB is an Ubuntu, it will use Meteor (currently I'm just doing some tests, so I only have the MongoDB installed) and the other application is a NodeJS script with MongooseJS.
What should I do to setup that instance of MongoDB to be reachable from remote applications?
I'm actually finding it quite hard to understand and find information on the web. I tried
var connection = GLOBAL.database.host;
mongodb.connect('mongodb://'+GLOBAL.database.host);
But it's throwing an error Failed to connect to.... :27017
The host is a virtual machine on Koding that I set up to run these tests. How can I make sure Mongo is accessible and how can I ping it to see if the mongo is responding my requests?

By default MongoDB is restricted to allow connections only from 127.0.0.1 .
The configuration file of mongo is placed in /etc/mongod.conf. In that file you can find the following two lines:
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip = 127.0.0.1
Follow the instructions and go on commenting the bind_ip line (use the # symbol). Restart MongoDB and try again.
Make sure that you can reach your server to port 27017 (is the port that MongoDB uses). You'll have to allow it in your server if you have something like iptables or allow it in any firewall you may have.

Related

Confluence in Docker can't see PostgreSQL in Docker

I'm trying to set up both Confluence and PostgreSQL in Docker. I've got them both up and running on my fully up to date CentOS 6 machine, with volume-mapping to the host file system so I can back them up easily. I can connect to PostgreSQL using pgAdmin from another machine just fine, and I can get into Confluence from a browser from that same machine. So, basically, both apps seem to be running as expected inside their respective containers and are accessible to the outside world, which of course eliminates a whole bunch of possibilities for my issue.
And that issue is that Confluence can't talk to PostgreSQL during initial setup, which is necessary for it to function. I'm getting connection failed errors (to be specific: "Can't reach database server or port : SQLState - 08001 org.postgresql.util.PSQLException: The connection attempt failed").
PostgreSQL is using the default 5432 port, which of course is exposed, otherwise I wouldn't be able to connect to it via pgAdmin, and of course I know the ID/password I'm trying is correct for the same reason (and besides, if it was an auth problem I wouldn't expect to see this error message). When I try to configure the database connection during Confluence's initial setup, I specify the IP address of the host machine, just like from pgAdmin on the other machine, but that doesn't work. I also tried some things that I basically knew wouldn't work (0.0.0.0, 127.0.0.1 and localhost).
I'm not sure what I need to do to make this work. Is there maybe some special method to specify the IP to a container from the same host machine, some nomenclature I'm not aware of?
At this point, I'm "okay" with Docker in terms of basic operations, but I'm far from an expert, so I'm a bit lost. I'm also not a big-time *nix user generally, though I can usually fumble my way through most things... but any hints would be greatly appreciated because I'm at a loss right now otherwise.
Thanks,
Frank
EDIT 1: As requested by someone below, here's my pg_hba.conf file, minus comments:
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all all md5
try changing the second line of the pg_hba.conf file to the following:
host all all 0.0.0.0/32 trust
this will cause PostgreSQL to start accepting calls from any source address. Since a docker container is technically not operating on localhost but on its own ip, the current configuration causes PostgreSQL to block any connections to it.
Also check if confluence is searching for the database on localhost. If that is the case change that to the ip of the hostmachine within the docker network.
Success! The solution was to create a custom network and then use the image name in the connection string to PostreSQL container from Confluence container. In other words, I ran this:
docker network create -d bridge docker-net
Then, on both of the docker run commands for the PostgreSQL and Confluence containers, I added:
--network=docker-net
That way, when I ran through the Confluence configuration wizard, when it asked for the hostname for the PostgreSQL server, I used postgres (the name I gave the container) rather than an IP address or actual hostname. Docker makes that work thanks to the custom network. This also leaves the containers available via the IP of the host machine, so for example I can still connect to PostgreSQL via 192.168.123.12:5432, and of course I can launch Confluence in the browser via 192.168.123.12:8080.
FYI, I didn't even have to alter the pg_hba.conf file, I just used the official PostgreSQL image (latest) as it was, which is ideal.
Thanks very much to RSloeserwij for the suggestions... while none of them proved to be the solution I needed, they did put me on the right track in the Docker docs, which, after some reading, led me to understand a few things I didn't before and figure out the config magic I needed.

Cannot connect from windows to redis linux server

I cannot connect to redis server (ubuntu server 16.04 LTS 64 bits on separate PC) from windows 8.1 64-bits. Redis is well documented, however I found very little information how to connect redis server from separate machine.
I have installed latest version of redis into linux and locally everything works fine. I start server via redis-server and also I start redis-cli and after that I am able to add information into server and retrieve it. The same situation is in windows - everything works locally.
In order to connect from windows into linux redis server I did these changes.
In linux I set the static local IP via sudo nano /etc/network/interfaces
address 192.186.xxx.xxx
netmask 255.255.255.0
network 192.168.xxx.xxx
broadcast 192.168.xxx.xxx
gateway 192.168.xxx.xxx
dns-nameservers 8.8.8.8
In redis.conf file I bind my windows PC IP which is given by my internet service provider. I also opened TCP 6379 port in my router GUI. In windows I modify redis.windows-service.conf and redis.windows.conf files. In both of them I bind my IP address given by my internet service provider. After this I cannot start redis-cli properly (empty black cmd window is visible)
What I am doing wrong? I would be very grateful for any help.
You should modify the redis conf, my redis conf is located at /etc/redis/6379.conf.
And you should comment the line "bind 127.0.0.1" Or change to bind 0.0.0.0.
The bind specify which network interface the redis server should listen to. The default is localhost.
And also Change the protected-mode to no :
Protected mode is a layer of security protection, in order to avoid that
Redis instances left open on the internet are accessed and exploited.
When protected mode is on and if:
1) The server is not binding explicitly to a set of addresses using the
"bind" directive.
2) No password is configured.
The server only accepts connections from clients connecting from the
IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
sockets.
By default protected mode is enabled. You should disable it only if
you are sure you want clients from other hosts to connect to Redis
even if no authentication is configured, nor a specific set of interfaces
are explicitly listed using the "bind" directive.
protected-mode yes
If you don't disable the protected-mode, your redis server will not listen public ip interface. more detail see above.
If you can access the remote server from your machine, your problem is most probably with redis security config, read the Securing Redis section in this document
I found that most of the time people don't change the "bind" directive value in redis config, you can test that by setting bind 0.0.0.0 and restarting redis server, if that's the issue, you can then allow whatever subnets you need to access the server.
I have also experience the same issue trying to connect to Redis (MSOpenTech 3.0.5 and 3.2.1) By default if no binding is stated then redis(according to the comments in the conf file) will listen to all available interfaces. That said, v 3.2.1 does have 'bind 127.0.0.1' already set... in 3.0.5 Setting the binding to 'bind 127.0.0.1' still allows the redis-cli to be used. Binding to 192.168.1.2 renders the redis-cli unusable with both versions - there is no IP and Port prompt, simply a carat and the cli does not accept keyboard input. Binging to an external IP the MSOpenTech fork service will not restart and throws an error(nice). Clearing all bindings and reverting back to original state, the redis-cli becomes usable again. Also, on the MS OpenTech fork there is no 'ProtectedMode' setting in either config file. Not sure whether this can actually be set.
Have raised this as an issue on the MSOpenTech fork via github but expecting silence to be the only reply...
I'm not sure this helps you in any way other than knowing that you are not alone. I am trying to pub from PHP to AS3 subscribers - it works great in the Flash IDE but from the localhost browser, redis appears to go decididly deaf.

How to access mongodb spawned by meteor app on a remote server?

I have a meteor application with mongodb running on one of my systems. I want another application running on a different system to be able to access the mongodb that is spawned by my meteor application.
How can I accomplish this because by default the mongodb bind ip is localhost, so it's not accessible from outside.
Not recommended but you can disable the restriction of MongoDB that can be accessed only via localhost.
See: http://www.mkyong.com/mongodb/mongodb-allow-remote-access/
if your service is on the same server, then use the localhost address:
Meteor tends to expose the mongodb at its adress +1
(if meteor is on port 3000, mongodb is on port 3001)
then your service can access it at localhost:3001
If you want to access from another server, then you need to change the mongodb config to expose the port to the outside (probably also setup some firewall rules to only give access to your other server etc...)
and then use the suggested above
MONGO_URL=mongodb://hostname:port
ideally deploy your mongodb securely somewhere and plug Meteor an any other app needing it to it via the connection string.

Setting up Azure VM for Neo4j (or any local database) [duplicate]

I have installed a Neo4J instance on my server on port 7474. My domain is also using that server and I want webadmin to be used remotely with a username and a password like this:
example.com:7474
Is there a way to do that? I could not find any guideline in the Neo4J documentation.
Did you get a chance to go through Neo4j Server Configuration documentation? It says:
#allow any client to connect
org.neo4j.server.webserver.address=0.0.0.0
This line in conf/neo4j-server.properties is commented by default and limits access to port 7474 to localhost or 127.0.0.1 (which probably is the reason why things work for your domain using that server and accessing Neo4j over localhost). Uncomment that line and it should make port 7474 accessible to everyone i.e. 0.0.0.0.
In order to secure your Neo4j server with an Authorization layer, you might want to refer Securing access to the Neo4j Server documentation.
In my case on ubuntu the line to uncomment was
dbms.connector.http.address=0.0.0.0:7474
File location
Ubuntu: /etc/neo4j/neo4j.conf
Neo4j 3.0.6

MongoDB Connection EC2

I just setup a MongoDB instance to be running in EC2 using the Bitnami MEAN stack. I am trying to connect to the MongoDB instance in my node application, but I don't know what the URL path would be.
I am familiar with paths that look like this:
mongodb://username:password#candidate.37.mongolayer.com:port/database
But am unclear how I would figure out what the equivalent path is for my EC2 instance. I found that there is a mongodb-27017.sock file in one of the directories, but the below didn't work.
mongodb://{USERNAME}:{PASSWORD}#{EC2LINK}/stack/mongodb/tmp/mongodb-27017.sock/{DATABASENAME}
Is there any way to figure out what the path is?
Make sure mongo service is running: service mongod status
Make sure the port is open in the security group. (mongo defaults to 27017)
Use this connection URL (same as you're used to): mongodb://{USERNAME}:{PASSWORD}#{EC2 INSTANCE IP / HOSTNAME}/{DATABASENAME} . See Examples
Note: changing the port would require specifying it in the connection string.
Thanks for the help Reut, your suggestions helped me to narrow things down. (I wasn't completely off track).
I finally figured out that my issue was I needed to change the bind_ip config variable in my mongodb.conf file. The bind_IP variable was set (by default) to 127.0.0.1. This prevents remote connections from making their way to the db.
I've since changed that to 0.0.0.0 to allow remote connections.

Resources