I've just install Redis succesfully using the instructions on the Quick Start guide on http://redis.io/topics/quickstart on my Ubuntu 10.10 server. I'm running the service as dameon (so it can be run by init.d)
The server is part of Rackspace Cluster with Internal and External IPs. The host is running on port 6379 (standard for Redis)
I've added a row in the iptables to allow incoming connections from port 6379 as shown below:
ACCEPT tcp -- anywhere anywhere tcp dpt:6379
In my PHP code on another server, I'm trying to connect to the new Redis server here:
$this->load->helper("iredis");
$hostname = "IP ADDRESS HERE";
$redis = new iRedis(array('hostname' => $hostname, 'port' => 6379));
Once I do this - I always get a connection refused. In my redis.conf file, I have the local bind command commented out, so it should be listening on more than the localhost IP. I can connect to the database on the local machine just not on another server. I've tried the external and internal IPs with no luck.
Any suggestions on getting this to work?
I've been stuck with the same issue, and the preceding answer did not help me (albeit well written).
The solution is here : check your
/etc/redis/redis.conf
, and make sure to change the defaultto
Then restart your service (
service redis-server restart
)You can then now check that redis is listening on non-local interface with
(replace 192.168.x.x with your IP adress)
Important note : as several users stated, it is not safe to set this on a server which is exposed to the Internet. You should be certain that you redis is protected with any means that fits your needs.
Setting tcp-keepalive to 60 (it was set to 0) in server's redis configuration helped me resolve this issue.
if you downloaded redis yourself (not apt-get install redis-server) and then edited the redis.conf with the above suggestions, make sure your start redis with the config like so:
./src/redis-server redis.conf
First I'd check to verify it is listening on the IPs you expect it to be:
Depending on how you start/stop you may not have actually restarted the instance when you thought you had. The netstat will tell you if it is listening where you think it is. If not, restart it and be sure it restarts. If it restarts and still is not listening where you expect, check your config file just to be sure.
After establishing it is listening where you expect it to, from a remote node which should have access try:
You could also try that from the local host but use the IP you expect it to be listening on instead of a hostname or localhost. You should see it PONG in response in both cases.
If not, your firewall(s) is/are blocking you. This would be either the local IPTables or possibly a firewall in between the nodes. You could add a logging statement to your IPtables configuration to log connections over 6379 to see what is happening. Also, trying he redis ping from local and non-local to the same IP should be illustrative. If it responds locally but not remotely, I'd lean toward an intervening firewall depending on the complexity of your on-node IP Tables rules.
Orabig is correct.
You can bind 10.0.2.15 in Ubuntu (VirtualBox) then do a port forwarding from host to guest Ubuntu.
in /etc/redis/redis.conf
then, restart redis:
It shall work!
In addition to the excellent answer given by Orabîg:
I resolved this issue by removing the
bind
section entirely and settingprotected-mode
tono
.Never use this method on publicly exposed servers.