Restarting MongoDB on a non default port - mongodb

how do I restart mongodb service in Ubuntu for a mongo instance running on a non-default port, ex. 27018?
'sudo service mongodb restart' doesnt seem to allow port parameter to specify a port.
Thanks

To start/run mongodb as a service on another port:
1) sudo service mongod stop
2)
add this in the config file /etc/mongod.conf:
net:
port: 27018
3) sudo service mongod start

Related

not able to connect to internet via HTTPS minikube pods

cluster info:
Minikube installation steps on centos VM:
curl -LO https://storage.googleapis.com/minikube/releases/v1.21.0/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start --addons=ingress --vm=true --memory=8192 --driver=none
PODs of this minikube cluster are not able to connect to internet.
However My host VM has internet connection with no firewall or iptables setup.
Can anybody help me debug this connection refused error
UPDATE:
I have noticed just now , I am able to connect non-https URLs, but not https URLs
How you have started the Minikube on the VM ? Which command did you used ?
If you are using the minikube --driver=docker it might won't work.
for starting the minikube on VM you have to change the driver
minikube --driver=none
in docker driver, it will create the container and install the kubernetes inside it and spawn the POD into further.
Check more at : https://minikube.sigs.k8s.io/docs/drivers/none/
if you on docker you can try :
pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d
"It will force docker to recreate the bridge and reinit all the network rules"
reference : https://github.com/moby/moby/issues/866#issuecomment-19218300
Try with
docker run --net=host -it ubuntu
Or else add dns in the config file in /etc/default/docker
DOCKER_OPTS="--dns 208.67.222.222 --dns 208.67.220.220"
Please check your container port and target port. This is my pod setup:
spec:
containers:
name: hello
image: "nginx"
ports:
containerPort: 5000
This is my service setup:
ports:
protocol: TCP
port: 60000
targetPort: 5000
If your target port and container port don't match, you will get a curl: (7) connection refused error(Source).
Checkout similar Stackoverflowlink for more information.

Could not resolve host mongo, elasticsearch

We created a docker swarm for 2 containers, mongo (alias mongo), ES (alias elasticsearch). Because of the unique use case our application is not part of the swarm but it still on bridge/default network. We want to reach out to mongo & ES from our app but we face the error
gradle#f63662b54a29:~/project$ curl -XGET http://mongo:27017
curl: (6) Could not resolve host: mongo
We are using the independent images available from mongo and ES.
These are the things we verified
sudo docker inspect --format '{{ .HostConfig.NetworkMode }}' container_id All the 3 containers have the default network config
The containers belong to the same security group and all the traffic is open from itself
We experimented with bindIp values
net:
port: 27017
bindIp: 127.0.0.1 // Also changed it to 0.0.0.0
We curled to google.com and it worked so shouldn't be a dns issue
Any pointers what else we could try to get to the bottom of this?

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.

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

Connect Robomongo to Virtual Machine

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.