Using homebrew to install Redis but when I try to ping Redis it shows this error:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
If after install you need to run redis
on all time, just type in terminal:
redis-server &
Running redis using upstart on Ubuntu
I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis
onto the box and here's how I did it and some things to look out for.
To install:
sudo apt-get install redis-server
That will create a redis
user and install the init.d
script for it. Since upstart
is now the replacement for using init.d, I figure I should convert it to run using upstart
.
To disable the default init.d
script for redis
:
sudo update-rc.d redis-server disable
Then create /etc/init/redis-server.conf
with the following script:
description "redis server"
start on runlevel [23]
stop on shutdown
exec sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf
respawn
What this is the script for upstart
to know what command to run to start the process. The last line also tells upstart
to keep trying to respawn if it dies.
One thing I had to change in /etc/redis/redis.conf
is daemonize yes
to daemonize no
. What happens if you don't change it then redis-server
will fork and daemonize itself, and the parent process goes away. When this happens, upstart
thinks that the process has died/stopped and you won't have control over the process from within upstart
.
Now you can use the following commands to control your redis-server
:
sudo start redis-server
sudo restart redis-server
sudo stop redis-server
Hope this was helpful!
This work for me :
sudo service redis-server start
After installing redis
, type from terminal
:
redis-server
And Redis-Server will be started
I was stuck on this for a long time. After a lot of tries I was able to configured it properly.
There can be different reasons of raising the error. I am trying to provide the reason and the solution to overcome from that situation.
6379 Port
is not allowed by ufw firewall.
Solution: type following command sudo ufw allow 6379
The issue can be related to permission of redis
user. May be redis user doesn't have permission of modifying necessary redis
directories. The redis
user should have permissions in the following directories:
/var/lib/redis
/var/log/redis
/run/redis
/etc/redis
To give the owner permission to redis
user, type the following commands:
sudo chown -R redis:redis /var/lib/redis
sudo chown -R redis:redis /var/log/redis
sudo chown -R redis:redis /run/redis
sudo chown -R redis:redis /etc/redis
.Now restart redis-server
by following command:
sudo systemctl restart redis-server
Hope this will be helpful for somebody.
First you need to up/start the all the redis nodes using below command, one by one for all conf files. @Note : if you are setting up cluster then you should have 6 nodes, 3 will be master and 3 will be slave.redis-cli will automatically select master and slave out of 6 nodes using --cluster command as shown in my below commands.
[xxxxx@localhost redis-stable]$ redis-server xxxx.conf
then run
[xxxxx@localhost redis-stable]$ redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
output of above should be like:
>>> Performing hash slots allocation on 6 nodes...
2nd way to set up all things automatically: you can use utils/create-cluster scripts to set up every thing for you like starting all nodes, creating cluster you an follow https://redis.io/topics/cluster-tutorial
Thanks
It's the better way to connect to your redis.
At first, check the ip address of redis server like this.
ps -ef | grep redis
The result is kind of " redis 1184 1 0 .... /usr/bin/redis-server 172.x.x.x:6379
And then you can connect to redis with -h(hostname) option like this.
redis-cli -h 172.x.x.x