Does redis3 cluster support socket connections? - redis

I'm running redis-3.0.4 in cluster mode. the os is centos6.6 x86_64
10.0.0.1:6379 master, 10.0.0.1:6380 slave
10.0.0.2:6379 master, 10.0.0.2:6380 slave
10.0.0.3:6379 master, 10.0.0.3:6380 slave
all the 6 processes are listening both tcp and unixsocket.
when I connect to the cluster via tcp, it works. all the operations are okay.
but when I save keys into the cluster via unixsocket, it throws out:
exception 'myfilename' with message 'Redis error: MOVED 6118 10.0.0.2:6379
I tested it on command line via:
redis-cli -c -s /tmp/redis-6379.sock
redis /tmp/redis-6379.sock> set hello world
it throws out a lot of:
...
-> Redirected to slot [3300] located at 10.0.0.3:6379
...
(it doesn't stop till I pressed ctrl+c)
How can I use a socket to connect to the redis3 cluster?

Related

Redis connection refused error in the application logs

We saw "Connection refused to ip:263*" to redis instances from the application logs. To solve we changed the port number from 26** to 6379 and it worked fine.
Upon analysis we found one one of the slave redis servers have the port number 26380 opened using
netstat -tupln
command. but the other server is not. Upon reading found that 26380, 26379, 26381 are ports used by sentinel. We suspect this 2**** ports should be opened on all servers and sue to some reasons it is not.
Please tell us how to check the logs in sentinel
checking if sentinel is configured.
checking if it is running.
checking what could have caused this to stop suddenly.
redis logs for port
EDIT
this is what I can see from the sentinel logs
2907:signal-handler (1653294181) Received SIGTERM scheduling shutdown...
2907:X 23 May 16:23:01.105 # User requested shutdown...
2907:X 23 May 16:23:01.105 * Removing the pid file.
2907:X 23 May 16:23:01.106 # Sentinel is now ready to exit, bye bye...
433:X 23 May 16:25:08.364 # Creating Server TCP listening socket ipaddress:26379: bind: Cannot assign requested address
anotheripaddress

how to check the message published from redis sentinel to redis master?

Question Background:
I deploy a redis cluster in k8s cluster and use Redis-Sentinel to implement ha for redis cluster. My redis cluster structure likes below:
One master
One slave
three sentinel (serve a specific redis cluster)
When i login the container of the one of sentinels, i execute a command:
sentinel sentinels mymaster
Luckly, i get a desirable output. These are two sentinel's infos. After a period of time, i execute "sentinels mymaster" command again, i found that there is a additional sentinel and don't find this instance through IP address or runId。
I know that sentinel discover other sentinels and master and slave through sub the channel of sentinel:hello in redis master.
Question:
how to check the message published from redis sentinel to redis master? I have opened log for master and set the log level to debug.
You can see the Sentinel's activity (when it discovers a sentinel, a replica, failsover to a new master, etc.) in the sentinel log file, not the master. If a sentinel is running on a host, it will be in the same directory the master or replica log file is. For me on CentOS it's /var/log/redis/sentinel.log.

How to switch redis master in sentinel configuration

I have a redis sentinel configuration with one master, two slaves and 3 sentinels running. I noticed that at some point the sentinels may switch the master electing one of the slaves as master. This is causing problems to an application which is connecting to the master node as a standalone client(I'm working on changing the code to use sentinels). I wanted to know if it is possible to switch the master by connecting to the sentinel client i.e. through 'redis-cli'
Can somebody let me know if there is a command that I can use to switch the master IP?
The client applications should use a client library that supports sentinel in the case where a redis master goes down and the sentinels select a new master. Not sure how beneficial it is to have sentinel setup if your client applications are not taking advantage of it. A client application that supports sentinel will query sentinel for the master ip and should be somewhat tolerant to faults occurring with the master connection. You can trigger a manual failover like the other answer states:
redis-cli -h {sentinel-ip} -p {26379 or sentinel port} sentinel failover {mastername}
But you will not be able to pick which node it fails over to. You can control a configuration value slave_priority in the redis.conf file so that it prefers a node over the rest. A description of the slave priority can be found here: https://redis.io/topics/sentinel
You can manually trigger a failover by running:
redis-cli -a {password} -p {sentinel_port} SENTINEL failover {cluster_name}
If you are using Lettuce Client you can use masterSlaveStatefulConnection and pass the sentinel URI it will perform auto discovery in the background and will refresh the master node internally.
https://github.com/lettuce-io/lettuce-core/wiki/Master-Replica

Redis replication through ssh not starting

Migrating bit by bit a Rails app infrastructure from one hosting zone to another (with only public internet linking them) I need to migrate a Redis instance from one side to the other.
Rather than dumping the data (even small : just queues), I'd prefer to use a master-slave setup to ensure that nothing is lost and that we don't have any down time.
Internet says SSH is my friend.
Old1 is the old server hosting the primary Redis server. Redis there is bound to a private network IP of the server.
New1 is the new server hosting the new Redis server.
On New1 I setup the ssh tunnel / port forwarding :
ssh -L 7380:<private_old1_ip>:6379 username#old1.publicname.ex
Still on New1 I check that I can connect to both instances :
redis-cli -p 6379
redis-cli -p 7380
In both bases, info works.
On New1:Redis, through redis-cli I setup the slave mode :
salveof localhost 7380
Now here is what info says on New1:Redis :
# Replication
role:slave
master_host:localhost
master_port:7380
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
master_link_down_since_seconds:1399544048
slave_priority:100
slave_read_only:1
connected_slaves:0
While Old1:Redis (through the tunnel still) :
# Replication
role:master
connected_slaves:1
slave0:<private_old1_ip>,6379,online
So the tunnel is up, and working.
There is plenty of memory available.
The slave appears connected on Old1 side (but appears with the Old1 ip).
The slave says master link status is down and that the sync is not in progress.
What am I missing ?
The problem was quite simple in fact.
The log destination was set to /dev/null so nothing was appearing in /var/log
The storage directory was set to ./ which obviously don't play well with daemon settings and was causing permissions errors on synchronisation.

Redis master/slave replication - single point of failure?

How does one upgrade to a newer version of Redis with zero downtime? Redis slaves are read-only, so it seems like you'd have to take down the master and your site would be read-only for 45 seconds or more while you waited for it to reload the DB.
Is there a way around this?
Redis Team has very good documentation on this
Core Steps:
Setup your new Redis instance as a slave for your current Redis instance. In order to do so you need a different server, or a server that has enough RAM to keep two instances of Redis running at the same time.
If you use a single server, make sure that the slave is started in a different port than the master instance, otherwise the slave will not be able to start at all.
Wait for the replication initial synchronization to complete (check the slave log file).
Make sure using INFO that there are the same number of keys in the master and in the slave. Check with redis-cli that the slave is working as you wish and is replying to your commands.
Configure all your clients in order to use the new instance (that is, the slave).
Once you are sure that the master is no longer receiving any query (you can check this with the MONITOR command), elect the slave to master using the SLAVEOF NO ONE command, and shut down your master.
Full Documentation:
Upgrading or restarting a Redis instance without downtime
When taking the node offline, promote the slave to master using the SLAVEOF command, then when you bring it back online you set it up as a slave and it will copy all data from the online node.
You may also need to make sure your client can handle changed/missing master nodes appropriately.
If you want to get really fancy, you can set up your client to promote a slave if it detects an error writing to the master.
You can use Redis Sentinel for doing this, the sentinel will automatically promote a slave as new master.
you can find more info here http://redis.io/topics/sentinel.
Sentinel is a system used to manage redis servers , it monitors the redis master and slaves continuously, and whenever a master goes down it will automatically promote a slave in to master. and when the old master is UP it will be made as slave of the new master.
Here there will be no downtime or manual configuration of config file is needed.
You can visit above link to find out how to configure sentinel for your redis servers.
Note, you may have to check and set the following config to write to your slave.
("Since Redis 2.6 by default slaves are read-only")
redis-cli config set slave-read-only no
-- Example
-bash-4.1$ redis-cli info
Server
redis_version:2.6.9
-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK
-bash-4.1$ redis-cli set temp 42
(error) READONLY You can't write against a read only slave.
-bash-4.1$ redis-cli slaveof no one
OK
-bash-4.1$ redis-cli set temp 42
OK
-bash-4.1$ redis-cli get temp
"42"
-bash-4.1$ redis-cli config set slave-read-only no
OK
-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK
-bash-4.1$ redis-cli set temp 42
OK
-bash-4.1$ redis-cli get temp
"42"