Connect Robomongo to Virtual Machine - mongodb

I have a problem. I'm using Virtual Box with RHEL (Red Hat Enterprise Linux) and I've installed a MongoDB and an Oracle-XE database.
I'm trying to connect to my DBs from my Windows OS.
I can connect to my oracle DB using SQL Developer, however when trying to use Robomongo to connect to my MongoDB I can't connect. And I have no idea why.
I've specified port forwarding in both cases, why does one work and the other doesn't?
I've tryed the following:
address: localhost port: 27017
address: 127.0.0.1 port: 27017
address: mongo.localhost port: 27017
And others... Why can't I connect with Robomongo?

In ubuntu I opended \etc\mongod.conf
I commented bind_ip = 0.0.0.0 to #bind_ip = 0.0.0.0
And as you know, you should use address: 192.168.0.105. port: 27017 (your linux ip; you can get Ip with command >$ hostname -I
Maybe same thing works for u in RedHat

After comment the bind_ip in \etc\mongod.conf
You need to do port forwarding in the VirtualBox setting.
Typically your VirtualBbox IP would be something like 10.0.2.15
(confirm that with the command hostname -I in VM)
and suppose your host PC's IP is 192.168.1.234
(confirm that with the command ipconfig in host PC)
now open the settings for your VM
click Network -> Port forwarding
add something like:
Name Protocol HostIP HostPort GuestIP GuestPort
Rule1 TCP 192.168.1.234 27017 10.0.2.15 27017
Rule2 TCP 192.168.1.234 80 10.0.2.15 80 (if you're hosting a web server)
now, intead of setting Robomongo's connecting IP=GuestIP
you should use address: 192.168.1.234 port: 27017
then the virtualbox should now direct your request to the right place.

Related

Can't connect to Postgres (installed through Kubernetes Helm) service from external machine, connection refused

I just installed Kubernetes with minkube on my desktop(running Ubuntu 18.10) and was then trying to install Postgresql on the desktop machine using Helm.
After installing helm, I did:
helm install stable/postgresql
When this completed successfully, I forwarded postgres port with:
kubectl port-forward --namespace default svc/wise-beetle-postgresql 5432:5432 &
and then I tested connecting to it locally from my desktop with:
psql --host 127.0.0.1 -U postgres
which succeeds.
I attempted to connect to postgres from my laptop and that fails with:
psql -h $MY_DESKTOP_LAN_IP -p 5432 -U postgres
psql: could not connect to the server: Connection refused
Is the server running on host $MY_DESKTOP_LAN_IP and accepting TCP/IP connections on port 5432?
To ensure that my desktop was indeed listening on 5432, I did:
netstat -natp | grep 5432
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 17993/kubectl
tcp6 0 0 ::1:5432 :::* LISTEN 17993/kubectl
Any help anyone? I'm lost.
you need to configure postgresql.conf to allow external client connections look for listen parameter and set it to *, it is under your postgres data directory, and then add your laptop's ip in pg_hba.conf. It controls the client access to your postgresql server, more on this here - https://www.postgresql.org/docs/9.3/auth-pg-hba-conf.html
In my case the solution was a little bit of deeper understanding of networking.
For clarity, let's call the machine on which minikube is installed "A".
The IP of this machine as it is visible from other computers on my Wifi maybe be say: 192.100.200.300.1
Since Postgres was being exposed on port 5432, my expectation was that postgres should be visible externally on: 192.100.200.300.1:5432.
But this understanding is wrong which is what was leading to unexpected behavior.
The problem was that minikube runs in a VM and it gets its own IP address. It doesn't simply use the IP of the machine on which it is running. Minikube's IP is different from the IP
of the machine on which it is running. To find out the IP of minikube, run: minikube ip. Let's call this IP $MINIKUBE_IP.
And then I had to setup port forwarding like:
kubectl port-forward --address "192.100.200.300" --namespace default svc/wise-beetle-postgresql 5000:5432 &
So now, if you called a service on: 192.100.200.300:5000 it would be forwarded to port 5432 on the machine which is running minikube and then 5432 would be received by your postgres instance.
Hope this untangles or clarifies this problem that others might encounter.

Connect to MongoDB server through Elastic IP

I have one AWS EC2 instance. I have installed MongoDB there.
Private IP :- 10.x.x.x
Port :- 27017
I can ssh into that system and connect the MongoDB server by using private IP within the VPN.
10.x.x.x:27017 - MongoDB is running here.
But, I have assigned one Elastic IP into that EC2 instance.
Public IP :- 132.x.x.x
When I am trying to connect MongoDB server by using Public IP (132.x.x.x:27017) it is showing connection timed out.
MongoDB network config, /etc/mongod.conf
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
I am starting the MongoDB server by using,
sudo mongod
inbound rules,
27017 tcp 0.0.0.0/0
27017 tcp 0.0.0.0/0, ::/0
Check to make sure your setup has the following:
The elastic IP is attached to the instance.
The security group allows incoming traffic from the client on the correct port.
The network ACL of the subnet that allow for the needed inbound and outbound traffic, or you're using the non-existent/default ACLs, which allow all inbound/outbound traffic.
An Internet Gateway is in the same VPC as the instance.
There is a rule in the subnet's route table that sends internet-bound traffic to the Internet Gateway.
You may also find this AWS article helpful for using the Internet Gateway in your VPC.

how to use a environmental variable as Bind-Ip in mongo db configuration file (mongod.conf)

I'm a newbie in mongodb and As far as I have seen, we always pass constant IP values like 127.0.0.1 or 172.17.0.5 as Bind IP in mongod.conf file.
This is the bind ip configuration in my mongod.conf>
net:
port: 27017
bindIp: 127.0.0.1, 172.17.0.5 # Listen to local interface only, comment to listen on all interfaces.
I have defined an environmental variable in /etc/environment file
DHOST= 172.17.0.5
When I try to give Below configuration in mongod.conf, I cannot connect to mongo shell:
net:
port: 27017
bindIp: 127.0.0.1, *$DHOST* # Listen to local interface only, comment to listen on all interfaces.
Please help me to add a ENV var as bind ip in mongo db configuration
You should pretty much always bind to IPv4 0.0.0.0 or IPv6 ::0 (that is, “all addresses”) for things that run inside Docker containers. The docker run -p option has an optional field that can limit what IP address on the host a published port will bind to; the container can’t be reached directly from off-host without configuration like this and so trying to bind to specific interfaces within the container isn’t especially helpful.

Connecting to a mongoDB server on a Windows Azure VM using Robomongo

I am attempting to setup a mongodb server on an Azure vm and can not seem to connect to it from an external client.
Here is what I have done so for:
I have created a windows server 2016 VM
I have installed mongodb as a service and started it on the new vm
I have added an inbound rule in the firewall for mongodb on the port 27017 with the following configuration:
Name: Allow MongoDB
Profile: All
Enabled: Yes
Action: Allow:
Override: No
Program: Any
Local Address: Any
Remote Address: Any
Protocol: TCP
Local Port: 27017
Remote Port: Any (The rest of the settings are also set to Any)
I have created a Network Security Group on Windows Azure
On the network security group I have set the Inbound security rules to the following configuration:
Priority: 100
Name: AllowHttp
Source: Any
Destination: Any
Service: Custom(Any/80)
Action: Allow
I associated the Subnet section to the virtual network of my azure vm
I am trying to connect from my local pc to the vm's mongodb installation using robomongo with the connection type Direct Connection, Address as the vm's public ip displayed on the vm's sumamry and port 27017.
When I attempt this I get the following error:
Does anyone know what I am doing wrong?
You added NSG rule for port 80 but you are trying to access on port 27017, so NSG will block you. Try to add Allow rule for 27017 on the NSG.

Mongo DB - net.bindIp for local and network access

I want the mongod instance to be accessible both from the localhost and other servers on the network.
If I set the net.bindIp value to 127.0.0.1 then mongod doesn't listen to external connections and nmap -p 27017 <server> reports that the port is closed. The same occurs if I comment out the net.bindIp line in mongod.conf.
If I set the net.bindIp value to the local IP address - 192.168.0.10 - then mongod listens for network connections on port 27017, but it doesn't allow me to connect to the mongod instance from the local host using the mongo command.
What value do I need to set net.bindIp to, to ensure I can connect both locally and over the network to the mongod instance.
I am running Ubuntu Server 14.04.
Include both the localhost and network IP address as comma separated values.
net:
port: 27017
bindIp: 127.0.0.1,192.168.0.10
and restart the service
sudo service mongod restart