Comments (4)
I haven't tried them.. However, not sure if I really want to go that route (building Redis high availability logic into the application or library). I recently started using Sentinel myself and in my setup the HAProxy instances do the health checks against the redis servers, not the sentinels and they require a node to be "role:master". In this way the HAProxy instances will always direct traffic to the master and the clients simply connect directly to HAProxy and do not need to be sentinel-aware. The sentinels can be ignored by the client application entirely, although they are still useful for automating the cluster initialization and failover.
defaults
mode tcp
timeout client 1h
timeout server 1h
timeout connect 1000
frontend redis-tcp
bind *:6379
default_backend redis
# The tcp-check will ensure that only reachable master nodes are considered "up".
backend redis
balance first
option tcplog
option tcp-check
tcp-check send info\ replication\r\n
tcp-check expect string role:master
default-server inter 5000 downinter 5000 fastinter 1000 rise 2 fall 3 maxconn 256 maxqueue 128
{{HOSTS}}
server node${num} ${ip}:6379 check
{{/HOSTS}}
The {{HOSTS}} part renders one line per server. See https://github.com/colinmollenhour/haproxy-service
from credis.
Hi @colinmollenhour,
Thanks for your reply. I'm trying to understand your configuration. It appears you are instructing HAProxy to do health-checks against the Redis master servers.
I have a similar HAProxy configuration, it looks as follows:
defaults
mode tcp
timeout connect 4s
timeout server 30s
timeout client 30s
frontend redis-tcp
bind *:26379 name redis
default_backend redis-alpha
backend redis
option tcp-check
tcp-check send AUTH\ OMMITED_REDIS_PWD\r\n
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send QUIT\r\n
tcp-check expect string +OK
server redis-1 X.X.X.1:6379 maxconn 1024 check inter 1s
server redis-2 X.X.X.2:6379 maxconn 1024 check inter 1s
server redis-3 X.X.X.3:6379 maxconn 1024 check inter 1s
server redis-4 X.X.X.4:6379 maxconn 1024 check inter 1s
server redis-5 X.X.X.5:6379 maxconn 1024 check inter 1s
After reading your reply, I'm trying to understand if your configuration allow slaves? The ideal scenario would be to utilize the slaves for high availability/load balancing and the master for writes. When health check fails on a master a new master is promoted.
Can you share an example your sentinel.conf
?
Thanks!
from credis.
My HAProxy does health checks against all redis nodes, but not redis sentinels. It only considers the master node to be up and considers all others to be down. I'm only going for redundancy but if you wanted to also go for load balancing reads I would recommend having two HAProxy backends, one for writes (only the master is up) and one for reads (all nodes that are part of the replication).
from credis.
Good call on two backends, that is going to be what I do. Thanks Colin, much appreciated.
from credis.
Related Issues (20)
- [1.11.2] syntax error, unexpected 'string' (T_STRING), expecting ';' or ','
- PHP Redis extension support TLS connections since 5.3.0
- Uncaught RedisException: read error on connection HOT 8
- Request For Adding Force Master Mode
- Deprecation of Credis_Cluster is not in line with documentation HOT 1
- CredisException: Failed to write entire command to stream in Credis/Client.php:1277 HOT 1
- Provide Compatibility with PHP 8 HOT 4
- [question] How to set redis options (such as serializer) ? HOT 1
- [redis 6] Authenticate with userpass from ACL HOT 8
- Socket connection error in PHP 8.1: deprecated parameter type HOT 3
- Credis_Client port issues ? HOT 3
- Moved error while using cluster HOT 2
- read error on connection to REDIS:6379 HOT 9
- PHP 8.2 Use of self in callables is deprecated HOT 3
- Suggest to remove `define('CRLF')` or use a const for it HOT 2
- Re-format code with modern PHP style?
- Use of "self" in callables is deprecated in Credis/Client.php HOT 3
- Some functions early-return false in pipeline mode
- Best practise to add a new command name. HOT 4
- PHP Warning: Trying to access array offset on value of type bool in colinmollenhour/credis/Client.php on line 1156 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from credis.