How to connect to redis which is running on EC2, from node.js application running on local system using Express.js? - node.js

I am writing an Node.js application on Express.js. I have a Redis server installed on an EC2 instance running on UBUNTU Server 16.04. I have installed npm modules for Redis.I have mentioned the port and the host like this:-
var redis = require('redis');
var client = redis.createClient(6379,"127.0.0.1");
When I try connecting to EC2 instance of Redis, I get an error like this:-
events.js:141
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)
How do I connect to redis which is running on ec2?

from the error message, it seems like redis isn't actually running on your host. i would check that redis is indeed running like this:
ps auxwg | grep redis
and check for a running redis process. another, simpler way would be to use the 'telnet' command to attempt to connect your local redis instance like:
wintermute:~ 07:52:58 melgart$ telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
in my case, redis is up and running so i get the 'connected' response. HTH

Related

Greenlock #v4 don't create ssl sertificate

When i start node js server that are using greenlock i got this message
Listening on 0.0.0.0:80 for ACME challenges, and redirecting to HTTPS
Listening on 0.0.0.0:443 for secure traffic
Ready to Serve:
But 2 minutes later i got error message
Error cert_issue:
connect ENETUNREACH 172.31.240.54:80
code: ENETUNREACH
Error: connect ENETUNREACH 172.31.240.54:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
I use virtual server and domen that i buy on GoDaddy

How to install MongoDB Enterprise 4.4 on remote redhat server?

I followed the instructions listed here, https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-red-hat/, and tried to install on a remote server from my local machine. I ssh from my local machine into the server and performed the steps for installation.
I'm not sure if there are additional steps that need to be completed or whether you have to set Directory Paths that are not the default ones since you are using a server instead of local machine. My current error is when I run mongo from my terminal and I get this error
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
[h699972#csc2cxp00020938 ~]$ mongo --host
sudo vim /etc/mongod.conf and setting bindIp: 0.0.0.0 did not work. Any help would be appreciated.

I am running a redis(docker image) on local nodejs application [duplicate]

This question already has answers here:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
(7 answers)
Closed 1 year ago.
i'm trying to use redis connection on local node js application but it throwing an error ---
events.js:183
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
If I understand correctly, you are running node inside a Docker container. This node process is trying to reach redis instance running at localhost.
This does not work, because container (node) has its own network stack, and 127.0.0.1 does not point to the host.
In this case you'd need to either
Run redis in its own container (and use e.g. docker-compose) OR
Change the Node connection host for redis from localhost (or 127.0.0.1) to your host IP address. See How to get the primary IP address of the local machine on Linux and OS X? for finding IP address
You are trying to connect to the wrong port. As the docker ps command says, the port where redis is listening is 32768. Connecting to that port should solve your issue.
See the official docker documentation (in particular the flag -p) for more information about customizing port listening.
You can also resolve this error by redoing your Docker container, just add the "-p 6379: 6379" flag. Example (Redis with persistent date):
docker run --name some-redis -p 6379:6379 -d redis redis-server
--appendonly yes

I can't connect to mongo db in ubuntu

MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-10-01T17:38:22.425+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-01T17:38:22.426+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I get an error when I try to run mongo on the terminal.
I tried to reinstall and removed lock file and restarted it, but It still doesn't work. I am using AWS, is it some problem about inbound, outbound of network setting in AWS, Or any other problem?
Like the comments above, if you are trying to connect to a mongodb instance on the same host, using 127.0.0.1 it is a mongodb configuration problem, so, that is not possible to be any AWS Security Rules.
So, considering it is a mongodb problem, first try to repair it inside the host with:
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongodb restart
sudo service mongod status
Refer: https://stackoverflow.com/a/29083477/8407784
After resolved the mongodb config problem, you need to test your connection from another host, setting /etc/mongod.conf - bind_ip = 0.0.0.0 (that means all interfaces), only for testing
Then you need to set your AWS Security Rules on the host instance allowing the external instance to access it on port 27017.

MongoDB connection failed, should I restart server or restart MongoDB

my computer is Ubuntu 14.04 LTS and I am connecting to a server to run codes. I also use the mongo on this server. However, it suddenly closed and when I tried to connect to the mongo shell, it shows:
MongoDB shell version: 2.6.9
connecting to: test
2015-05-02T16:37:34.643+0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-05-02T16:37:34.643+0200 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
So should I restart mongo or should I restart the server? I use ps command to see all progresses on the server under my account, which is:
PID TTY TIME CMD
107018 pts/16 00:00:00 ps
233611 pts/16 00:00:00 bash
Does that mean that I cannot restart the server?
It seems mongodb suddenly shut down.
use sudo service mongodb restartto restart mongodb.
if it does not work and it is a test machine/personal computer ,
restart the machine is a good choice.
in addition,ps only shows your own process,sudo ps shows all process.

Resources