There's some strange behavior i've found with node_redis on Aws EC2.
Let's say i have two EC2 instances.
First one is used for DB (Redis, MYSQL, etc.) and it has an IP like so ip-1-1-1-1.eu-west-1.compute.internal
Second one is for app based on NodeJS and it's IP is ip-2-2-2-2.eu-west-1.compute.internal
In the Security Groups i've added this:
6379 sg-351a0441 (default)
6379 sg-333b9044 (quicklaunch-0)
I use node_redis module to communicate with Redis. I need to connect from one instance to another.
So now i (probably) can connect to Redis (first server) from another one:
redis = require('redis');
client = redis.createClient(6379, 'ip-1-1-1-1.eu-west-1.compute.internal');
But this way causes error:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
It tries to connect (!) to 127.0.0.1 istead of 1.1.1.1.
I've said "OK. Let's try another way!"
redis = require('redis');
client = redis.createClient(6379, '1.1.1.1');
And.. BANG! The same error here:
Error: Redis connection to 1.1.1.1:6379 failed - connect ECONNREFUSED
So, maybe full redis url will help?
redis = require('redis');
client = redis.createClient(6379, 'redis://1.1.1.1');
No :(
Error: Redis connection to redis://10.248.118.246:6379 failed - getaddrinfo EADDRINFO
And same one when using internal url:
Error: Redis connection to redis://ip-1.1.1.1.eu-west-1.compute.internal:6379 failed - getaddrinfo EADDRINFO
So, what's wrong with it? Thanks in advance.
Related
I am trying to use redis using this segment of code:
const redis = require('redis');
const client = redis.createClient();
I am getting the following error:
events.js:174
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:1097:14)
You will need to first install redis on your system. To do so, follow the instructions here.
Then run the following command in your command prompt/terminal:
redis-server
If you want to run redis in the background without having to start it everytime, then you can use:
redis-server --daemonize yes
You can check if your server is running by using the command:
redis-cli set a 3 & redis-cli get a
If this works then your redis server has started successfully.
After this, your previous code should be able to connect to the redis-server provided the server is running on the default port (6379).
I have a NodeJS application using MongoDB as the database. I'm using mongoose for mongodb related activities.
I have an account in MongoLab and I use that for my database related activities of my application.
When trying to connect to MongoLab as below from nodejs
mongoose.connect("<db_url_with_username_password>", function(err) {
if(err)
{
console.log("Error is "+err);
throw err;
}
});
It's logging the following line
Error is MongoError: connect ECONNREFUSED 54.161.65.217:19058
I thought the server could be down, hence I checked the website online, it's working perfectly.
I pinged the server with the following
ping 54.161.65.217
and it's working fine.
64 bytes from 54.161.65.217: icmp_seq=0 ttl=28 time=271.396 ms
64 bytes from 54.161.65.217: icmp_seq=1 ttl=28 time=268.824 ms
However, When I'm trying to connect using the mongo command to connect, it's failing
mongo 54.161.65.217:19058/<db_name> -u <username> -p <password>
MongoDB shell version: 3.2.1
connecting to: 54.161.65.217:19058/arogyavath
2016-03-14T10:28:27.200+0530 W NETWORK [thread1] Failed to connect to 54.161.65.217:19058, reason: errno:61 Connection refused
2016-03-14T10:28:27.201+0530 E QUERY [thread1] Error: couldn't connect to server 54.161.65.217:19058, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
I looked around and found the following questions which could be similar to mine
Node.js Error: connect ECONNREFUSED
ECONNREFUSED error when connecting to mongodb from node.js
But the answers I found there didn't help me fix the issue.
Could the server ip address be blocked from my network or something? How do I fix this?
I would be very glad if someone can point me in the right direction. Thanks in Advance.
After deploying the Ghost blogging platform with success, i tried to configure it to use Mysql instead of sqllite3 using this database section of their config page, which says:
Database
By default, Ghost comes configured to use an SQLite database, which
requires no configuration.
Alternatively Ghost can also be used with a MySQL database by changing
the database configuration. You must create a database and user first,
you can then change the existing sqlite config to something like:
database: { client: 'mysql', connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'ghost_db',
charset : 'utf8' }
}
So ok, the setup is straight forward. but i'm still unable to connect ghost with mysql. The error i receive after starting the platform using npm start --production is :
> ghost#0.6.2 start /var/www/ghost
> node index
Migrations: Database initialisation required for version 003
Migrations: Creating tables...
Migrations: Creating table: posts
ERROR: connect ECONNREFUSED
Error: connect ECONNREFUSED
at errnoException (net.js:905:11)
at Object.afterConnect [as oncomplete] (net.js:896:19)
--------------------
at Protocol._enqueue (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:110:48)
at Protocol.handshake (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:42:41)
at Connection.connect (/var/www/ghost/node_modules/mysql/lib/Connection.js:98:18)
at /var/www/ghost/node_modules/knex/lib/dialects/mysql/index.js:105:16
at tryCatch2 (/var/www/ghost/node_modules/bluebird/js/main/util.js:53:21)
at Promise._resolveFromResolver (/var/www/ghost/node_modules/bluebird/js/main/promise.js:544:13)
at new Promise (/var/www/ghost/node_modules/bluebird/js/main/promise.js:84:37)
at Client_MySQL.acquireRawConnection (/var/www/ghost/node_modules/knex/lib/dialects/mysql/index.js:104:10)
at Object.create (/var/www/ghost/node_modules/knex/lib/pool.js:33:19)
at Object.Pool.createResource (/var/www/ghost/node_modules/knex/node_modules/generic-pool-redux/pool.js:288:12)
I'm not sure what could be wrong, since i have other applications using mysql working without any problems.
Thanks in advance.
connection refused = tcp connection was attempted, but nothing is listening on the port, or was explicitly denied. Unless you explicitly enabled TCP support in mysql (and have the correct ip/port), you should probably be using a local unix-domain socket instead.
Hi im trying to connect to redis from node.js which is successful, now i hosted my node.js server app on amazon ec2 instance and redis on amazon elastic cache instance the connection to redis is succesful but once in a while i'm getting the below mentioned error.
var pub = redis.createClient(6379,'quizredis.qnsdtp.0001.apse1.cache.amazonaws.com');
events.js:72
throw er; // Unhandled 'error' event
^ Error: Redis connection to quizredis.qnsdtp.0001.apse1.cache.amazonaws.com:6379 failed - getaddrinfo ENOTFOUND
at RedisClient.on_error (/home/ec2-user/roomChat-7/node_modules/redis/index.js:196:24)
at Socket.<anonymous> (/home/ec2-user/roomChat-7/node_modules/redis/index.js:106:14)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:813:16
Im using the redis-npm module;
From what I understand, this is a DNS resolution error.
Elasticache Redis is a VPC specific service. Its DNS records are available within the VPC only and often times, VPC is using custom DHCP options with custom DNS server - it may not have the records.
Check a few things -
DNS server configured in your VPC. Check here.
Check the output of nslookup command in your machine - if your using linux shell
nslookup quizredis.qnsdtp.0001.apse1.cache.amazonaws.com
Cheers!
Sometimes my node-redis client take a long time to a initial connect to redis server.
I log .on('error'), .on('end'), .on('connect') and .on('ready') events here:
Redis: storage#0 <localhost:6381> end
Redis: error storage#0 <localhost:6381> [Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]
/*... much of same errors, sometimes up to 5minutes ...*/
Redis: error storage#0 <localhost:6381> [Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]
Redis: storage#0 <localhost:6381> connect
Redis: storage#0 <localhost:6381> ready
While it happened I can normally connect to the redis-server using redis-cli.
Have somebody any ideas about reason of this?
Error "[Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]" seems to point to an address resolution issue.
A simple proposal was therefore to use 127.0.0.1 instead of localhost to bypass the call to getaddrinfo, and the associated DNS query which can fail.
The result with 127.0.0.1 was slightly different: still an error, but the message was now ECONNREFUSED meaning that the remote Redis server was probably not listening to the provided port - or perhaps the connection timeout was set too low.