How can I create a service name and password in redis-sentinel - redis

I am getting this error when I run celery beat -S redbeat.RedBeatScheduler.
beat raised exception : ConnectionError('Error -2 connecting to redis-sentinel:26379. Name or service not known.',)
How can I create a service_name and password in redis-sentinel
I am not trying to use redis as a message broker. I am using celery-redbeat to store celerybeat data in redis-sentinel cluster from this page.https://pypi.org/project/celery-redbeat/
and
from this configuration
redbeat_redis_url = 'redis-sentinel://redis-sentinel:26379/0'
redbeat_redis_options = {
'sentinels': [('192.168.1.1', 26379),
('192.168.1.2', 26379),
('192.168.1.3', 26379)],
'socket_timeout': 0.1,
}
I add 192.168.1.1:26379 instead of redis-sentinel:/26379 but when master node down in redis-sentinel cluster beat is down too.
redbeat_redis_url = 'redis-sentinel://192.168.1.1:26379/0'
redbeat_redis_options = {
'sentinels': [('192.168.1.2', 26379),
('192.168.1.3', 26379)],
'socket_timeout': 0.1,
}

Unless you have redis-sentinel in your /etc/hosts file it will not be able to resolve it to a correct IP address. You may try to replace redis-sentinel with an IP address of your Redis server. Furthermore, it does not look like a proper Redis Sentinel configuration. Redis Configuration section explains how to connect to Redis Sentinel, please read it.

Related

ArgoCD 2.5.x ha install results in redis pods initializing issue

We are trying to install the ha argocd of verser 2.5.x(current stable version) on Kubernetes: v1.23.13
But the argocd-redis-ha-server-0 pod does not finalize the Initialization because the config-init container fails with
Start...
Initializing config..
Copying default redis config..
to '/data/conf/redis.conf'
Copying default sentinel config..
to '/data/conf/sentinel.conf'
Identifying redis master (get-master-addr-by-name)..
using sentinel (argocd-redis-ha), sentinel group name (argocd)
Could not connect to Redis at argocd-redis-ha:26379: Try again
Could not connect to Redis at argocd-redis-ha:26379: Try again
Could not connect to Redis at argocd-redis-ha:26379: Try again
Did not find redis master ()
Identify announce ip for this pod..
using (argocd-redis-ha-announce-0) or (argocd-redis-ha-server-0)
identified announce ()
/readonly-config/init.sh: line 239: Error: Could not resolve the announce ip for this pod.: not found
Installed ArgoCD resource - https://github.com/argoproj/argo-cd/blob/master/manifests/ha/install.yaml
Does anyone have any idea on how to resolve the above issue?

should I handle the master redis ip by myself in redis single master multi slave cluster

I am using a single master multi slave redis cluster in kubernetes v1.16.0,but today I found the master ip changed(another node change to master and legacy master change to slave) and cause my cluster down. I am install my redis like this:
./helm install stable/redis-ha --generate-name -n middleware
and specify ip through the master service ip. what should I do to make it handle it automaticlly.This is service status:

Redis Sentinel Authentication

I have 3 Servers with Redis and Sentinel Running.
All instances have in the configuration
requirepass XXX
masterauth XXX
I can connect with redis-cli to the redis server but if I try to connect to the sentinel I can not authenticate.
root#ip-:/usr/lib/nagios/plugins# redis-cli -p 26379
127.0.0.1:26379> AUTH xxx
(error) ERR unknown command 'AUTH'
127.0.0.1:26379>
If I use the same command but with the redis port it works.
Thanks
best
You have to setup auth for sentinels, too. I mean requirepass=<password> in sentinel.conf. More info on this here and here. Be careful, as not every client supports this setup.
Also, you need to set sentinel auth-pass <master-name> <password> in that file, in order for the sentinels to be able to administrate secured redis servers. (But I'm guessing you already did that).

How Do I Connect to a Redis Sentinel that requirespass with ServiceStack.Redis?

I have a simple redis cluster on my local machine that consists of:
master on port 3679
slave on port 6380
sentinel on port 26379
I am using ServiceStack.Redis to connect with no problems so far. Today I added a password to each of them using the requirepass 42 setting. I can connect to all of them using Redis Desktop Manager fine and everything works as expected.
Using the following code, I get an error when I attempt to connect. Removing the password works as expected.
var config = RedisConfiguration.Instance;
Func<string, string> hostFilter = host => string.IsNullOrEmpty(config.SecurityKey)
? $"{host}?db={config.Database}"
: $"{config.SecurityKey}#{host}?db={config.Database}";
var sentinelHosts = config.SentinelHosts.Select(hostFilter);
var sentinel = new RedisSentinel(sentinelHosts, config.ServiceName)
{
HostFilter = hostFilter,
RedisManagerFactory = (master, slaves) => new RedisManagerPool(master)
};
sentinel.OnFailover += manager => Logger?.Warn($"Redis fail over to {sentinel.GetMaster()}");
sentinel.Start()
This code throw a RedisException "No Redis Sentinels were available" with an inner exception of "unknown command 'AUTH'".
I am not clear if I am using the ServiceStack.Redis library improperly or my Redis cluster configuration is incorrect.
Can some one point me in the right direction?
You can use HostFilter to specify the password:
sentinel.HostFilter = host => $"{config.SecurityKey}#{host}?db={config.Database}";
But when using a password, it needs to be configured everywhere, i.e. in both Master and Slave configurations using:
requirepass password
masterauth password
The Redis Sentinels also need to be configured to use the same password so it can control the redis instances it's monitoring, which can be configured in your sentinel.conf with:
sentinel auth-pass mymaster pasword
The windows-password folder in the redis-config project shows an example of a password-protected Redis Sentinel configuration.

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