Skip to content

Commit af91c50

Browse files
Add support for Redis Sentinel sessions. (librenms#17203)
* Add support for Redis Sentinel sessions. Updated Redis configuration to use environment variables for connections * lint: fix database.php * fix: Leftover cluster variable casued redis+sentinel to fail If cluster is really needed, functionality for determining if cluster is used, shall be added. Having this variable in the config-file was causing redis+sentinel based solution to fail (only this particular set-up, normal redis was fine) * Fix redis session config. * docs: rename connection -> driver for redis session * Style CI * revert session config changes This reverts commit 79ba4d9 * Revert cache config change This partially reverts commit a997981. * docs: Ensure that sessions use redis as well * fix: remove php-logic for redis-sentinel * docs: Update variables used for redis-sentinel configuration. This aligns with the config changes. * style ci --------- Co-authored-by: Justin Lentz <[email protected]>
1 parent d7a00d2 commit af91c50

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

config/database.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
'client' => env('REDIS_CLIENT', 'predis'),
126126

127127
'options' => [
128-
'cluster' => env('REDIS_CLUSTER', 'redis'),
129128
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
130129
],
131130

@@ -149,6 +148,30 @@
149148
'database' => env('REDIS_CACHE_DB', '1'),
150149
],
151150

151+
'sentinel_session' => [
152+
...explode(',', env('REDIS_SENTINEL_HOSTS', '')),
153+
'options' => [
154+
'replication' => 'sentinel',
155+
'service' => env('REDIS_SENTINEL_SERVICE', 'mymaster'),
156+
'parameters' => [
157+
'password' => env('REDIS_PASSWORD', ''),
158+
'database' => env('REDIS_SESSION_DB', '0'),
159+
],
160+
],
161+
],
162+
163+
'sentinel_cache' => [
164+
...explode(',', env('REDIS_SENTINEL_HOSTS', '')),
165+
'options' => [
166+
'replication' => 'sentinel',
167+
'service' => env('REDIS_SENTINEL_SERVICE', 'mymaster'),
168+
'parameters' => [
169+
'password' => env('REDIS_PASSWORD', ''),
170+
'database' => env('REDIS_CACHE_DB', '1'),
171+
],
172+
],
173+
],
174+
152175
],
153176

154177
];

doc/Extensions/Redis-Sentinel.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,30 @@ To configure the Web UI to use a Redis Sentinel cluster, add the following param
1616

1717
```
1818
# Configure these values according to your environment
19-
REDIS_SENTINEL=192.168.1.10:26379,192.168.1.11:26379,192.168.1.12:26379
19+
REDIS_SENTINEL_HOSTS=redis://192.168.1.10:26379,redis://192.168.1.11:26379,redis://192.168.1.12:26379
2020
REDIS_SENTINEL_SERVICE=mymaster
21-
REDIS_SENTINEL_PASSWORD=your_sentinel_password
21+
# optionally set password if your redis-backend has it enabled, this is not for sentinel.
2222
REDIS_PASSWORD=your_redis_password
2323
2424
# These values tell the web app to use Sentinel as the Redis backend - do not change
2525
REDIS_BROADCAST_CONNECTION=sentinel_cache
2626
REDIS_CACHE_CONNECTION=sentinel_cache
2727
REDIS_LOCK_CACHE_CONNECTION=sentinel_cache
28+
SESSION_DRIVER=redis
2829
SESSION_CONNECTION=sentinel_session
2930
```
3031

32+
### Redis Sentinel Authentication
33+
34+
If your Redis Sentinel cluster is password-protected, you need to append `password=your_redis_password` to each Redis Sentinel URL in the `REDIS_SENTINEL_HOSTS` variable.
35+
Optionally, if you are using ACLs, you must also include `username=your_redis_username` in the URL.
36+
37+
For example:
38+
39+
```
40+
REDIS_SENTINEL_HOSTS=redis://192.168.1.10:26379?password=your_redis_password,redis://192.168.1.11:26379?password=your_redis_password,redis://192.168.1.12:26379?password=your_redis_password
41+
```
42+
3143
### Poller Configuration
3244

3345
To configure the Poller to use a Redis Sentinel cluster, add the following to your `.env` file:

0 commit comments

Comments
 (0)