Connection Problem in mongodb 4.2.8 on AWS ec2 - mongodb

I have created new Instance on AWS ec2 and installed the mongodb 4.2.8 on server but I'm unable to connect with mongodb using local terminal of Ubuntu 18.0.2. I'm hitting a command which will import a mongodb dump database into the server database the command is given below
mongorestore --host IPv4_Public_IP --port 27017 --db db_name dump/dataDb/
The error I'm facing is
error connecting to host: could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: IPv4_Public_IP:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp IPv4_Public_IP:27017: connect: connection refused }, ] }
And how to set the Inboud rules for that instance. For now these are
SSH TCP 22 0.0.0.0/0 -
Custom TCP 27017 my_ip -

Related

Connection error while connecting linode mongodb server

I have installed mogodb linode "mongodb-app" and its running .. created user and collections and able to access it from shell
now trying to connect to the server from my local but getting server timeout
'''
pymongo.errors.ServerSelectionTimeoutError: 170.187.248.15:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 6218a8cccb94c35a2569ce55, topology_type: Single, servers: [<ServerDescription ('170.187.248.15', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('170.187.248.15:27017: timed out')>]>
default_config = {'MONGODB_SETTINGS': {
#Local DB
'db': 'test_db',
'host': 'localhost',
'port': 27017
#linode "mongodb-app"
'db': '<db name>',
'host': '<server ip>',
'port': 27017,
'username': '<db user>,
'password': '<db password>',
'authentication_source': 'admin'
}
'''
I have followed couple of steps :
'''
1. updated /etc/mongod.conf from the server
net:
port: 27017
bindIp:0.0.0.0
'''
2. sudo ufw status
sudo: unable to resolve host 170-187-248-15
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
27017 ALLOW 0.0.0.0
22 (v6) ALLOW Anywhere (v6)
but still facing the same error
On your linux server where mongodb is running, run these two commands:
iptables -A INPUT -s <ip-address-of-your-app> -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d <ip-address-of-your-app> -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
Taken from https://docs.mongodb.com/manual/tutorial/configure-linux-iptables-firewall/#traffic-to-and-from-mongod-instances

access postgres into docker container when postgres locally is also running

I have postgres on docker container that I run using the following command:
docker run -d --name timescaledb -p 127.0.0.1:5433:5433 -e POSTGRES_PASSWORD=somepass timescale/timescaledb:latest-pg12
Meanwhile I also have postgres installed locally in my machine and port 5432 is listening:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 124 postgres 7u IPv6 0x38eef62419af50a3 0t0 TCP *:5432 (LISTEN)
postgres 124 postgres 8u IPv4 0x38eef624199e6d5b 0t0 TCP *:5432 (LISTEN)
com.docke 3520 alex 39u IPv4 0x38eef62428c6b7fb 0t0 TCP localhost:5433 (LISTEN)
com.docke 3520 alex 42u IPv4 0x38eef62428c3581b 0t0 TCP *:49816 (LISTEN)
I'm trying to set up a connection with psycopg2 using this command:
connection = psycopg2.connect(host=config.DB_HOST,database=config.DB_NAME,user=config.DB_USER,password=config.DB_PASS,port=config.DB_PORT)
of which config.xxx is :
DB_HOST = 'localhost'
DB_USER = 'postgres'
DB_PASS = 'somepass'
DB_NAME = 'etfdb'
DB_PORT = '5433'
but I'm getting the following error:
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "localhost" (::1), port 5433 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5433 failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
It's worth noting that the command docker ps shows me port 5432 for some reason I don't know:
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d2623bd4055 timescale/timescaledb:latest-pg12 "docker-entrypoint.s…" 6 days ago Up 17 minutes 5432/tcp, 127.0.0.1:5433->5433/tcp timescaledb

Lost connection to MySQL server with Mongo connector

I'm getting the following error when trying to connect to power bi "ODBC: ERROR [08S01] [MySQL][ODBC 1.4(a) Driver]Lost connection to MySQL server at 'waiting for initial communication packet', system error: 10060".
My bi connector is on vm where my mongo server is allocated, I created a service which is running and I have no error logs but I still can't connect using powerbi. This is the mongosqld.conf I'm using
systemLog:
path: '/var/log/mongosqld.log'
net:
bindIp: '127.0.0.1'
port: 3307
mongodb:
net:
uri: 'server_ip'
ssl:
enabled: false
auth:
username: user
password: pwd
security:
enabled: true
What I'm doing wrong?!

Can't connect to mongodb using shell but can connect using compas

From the same client, I can connect to my remote mongodb using this string:
mongodb://siteadmin:mypassword#myip:27017
But from the shell when I run
mongo "mongodb://siteadmin:mypassword#myip:27017"
DB.prototype._authOrThrow#src/mongo/shell/db.js:1608:20
#(auth):6:1
#(auth):1:2
exception: login failed
root#shadow:~/website-fron
Any idea?
My config is simple:
security:
authorization: 'enabled'
net:
port: 27017
bindIp: 0.0.0.0

How to connect to Postgres Amazon-RDS from TypeORM?

Have tried to connect to my RDS Postgres instance from postgres client (Docker image)...
docker run -it --rm jbergknoff/postgresql-client postgresql://username:******#somepostgres.sometext.us-west-2.rds.amazonaws.com:5432
and it works...
When I try it from typeorm... it complain about getaddrinfo ENOTFOUND.
Here is my connection option:
{
type: 'postgres',
logging: true,
host: process.env.DB_HOST,
port: 5432,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
extra: {
ssl: true
}
}
And this is the error:
[Nest] 25882 - 06/09/2019, 12:19 PM [TypeOrmModule] Unable to connect to the database. Retrying (1)... +3291ms
Error: getaddrinfo ENOTFOUND postgres.sometext.us-west-2.rds.amazonaws.com postgres.sometext.us-west-2.rds.amazonaws.com.com:5432
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:58:26)
EDIT:
When I use the IP. it works. But still curious... why the address not working tho.
EDIT 2:
Found it. My local node js can't connect to RDS because my nameserver is not configured correctly.
To fix it in linux you do it like,
# /etc/resolv.conf
# I use google here
nameserver 8.8.8.8
namaserver 8.8.4.4
And the reason why i can access it from docker, i guess docker have its own nameserver configuration.