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?
This question is related to
ubuntu
configuration
redis
I was struggling with the remote connection to Redis for some days. Finally I made it. Here is the full check list I put together to follow to get connected. Some of solutions are given in the answers above. Yet I wanted my answer to be a nano-wiki on the subject:) I added some useful links too.
$ redis-cli
127.0.0.1:6379>ping
PONG
127.0.0.1:6379>
See /etc/redis/redis.conf
config (this is default locaion for Ubuntu 18.04, you may have it in the different location):
# The following line should be commented
# requirepass <some pass if any>
# The following line should be uncommented
protected-mode no
# The following line should be commented
# bind 127.0.0.1 ::1
(here for Ubuntu 18.04) Check it allows for incoming internet traffic to go to port 6379
(the Redis default port)
# To check if it the port is open
$ sudo ufw status
Status: active
To Action From
-- ------ ----
...
6379/tcp ALLOW Anywhere
6379/tcp (v6) ALLOW Anywhere (v6)
...
# To open the port
$ sudo ufw allow 6379/tcp
Do not forget to restart the Redis service for changes to take effect and see it is running:
$ sudo systemctl restart redis.service
$ sudo systemctl status redis
from your command line use redis-cli
as if Redis server were on the remote server:
$ redis-cli -h <your-server-ip>
<your-server-ip>:6379> ping
PONG
<your-server-ip>:6379> exit
$
If you can ping-PONG your Redis server via your internet server connected as a remote server than the remote Redis connection works.
All the above makes your Redis data to be completely open to anybody from the internet.
To basically secure Redis use requirepass
and protected-mode yes
settings in Redis config (see above) and block the dangerous Redis commands (see the link above), for a deeper understanding see this article and Redis site security section ).
Some links to help How to install and secure Redis on Ubuntu 18.04 and how to setup Ubuntu 18.04 firewall.
Hope it helps.
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
In addition to the excellent answer given by Orabîg:
I resolved this issue by removing the bind
section entirely and setting protected-mode
to no
.
#bind 127.0.0.1
protected-mode no
Never use this method on publicly exposed servers.
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 default
bind 127.0.0.1
to
bind 0.0.0.0
Then restart your service (service redis-server restart
)
You can then now check that redis is listening on non-local interface with
redis-cli -h 192.168.x.x ping
(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.
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
bind 10.0.2.15
then, restart redis:
sudo systemctl restart redis
It shall work!
Setting tcp-keepalive to 60 (it was set to 0) in server's redis configuration helped me resolve this issue.
Source: Stackoverflow.com