redis clustering

This commit is contained in:
marcel-dempers 2020-08-09 15:01:15 +10:00
parent 4b8f92df85
commit af6a960c17
7 changed files with 108 additions and 79 deletions

View File

@ -3,11 +3,23 @@
Documentation [here](https://redis.io/topics/replication)
### Configuration
```
#persistence
dir /data
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
```
### redis-0 Configuration
```
protected-mode no
port 6379
#authentication
masterauth a-very-complex-password-here
requirepass a-very-complex-password-here
```
@ -17,8 +29,11 @@ requirepass a-very-complex-password-here
protected-mode no
port 6379
slaveof redis-0 6379
#authentication
masterauth a-very-complex-password-here
requirepass a-very-complex-password-here
```
### redis-2 Configuration
@ -26,13 +41,17 @@ requirepass a-very-complex-password-here
protected-mode no
port 6379
slaveof redis-0 6379
#authentication
masterauth a-very-complex-password-here
requirepass a-very-complex-password-here
```
```
```
# remember to update above in configs!
docker network create redis
cd .\storage\redis\clustering\
@ -58,10 +77,51 @@ docker run -d --rm --name redis-2 `
```
## Example Application
Run example application in video, to show application writing to the master
```
cd .\storage\redis\applications\client\
docker build . -t aimvector/redis-client:v1.0.0
docker run -it --net redis `
-e REDIS_HOST=redis-0 `
-e REDIS_PORT=6379 `
-e REDIS_PASSWORD="a-very-complex-password-here" `
-p 80:80 `
aimvector/redis-client:v1.0.0
```
## Test Replication
Technically written data should now be on the replicas
```
# go to one of the clients
docker exec -it redis-2 sh
redis-cli
auth "a-very-complex-password-here"
keys *
```
## Running Sentinels
Documentation [here](https://redis.io/topics/sentinel)
```
#********BASIC CONFIG************************************
port 5000
sentinel monitor mymaster redis-0 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster a-very-complex-password-here
#********************************************
```
Starting Redis in sentinel mode
```
@ -81,4 +141,18 @@ docker run -d --rm --name sentinel-2 --net redis `
-v ${PWD}/sentinel-2:/etc/redis/ `
redis:6.0-alpine `
redis-sentinel /etc/redis/sentinel.conf
docker logs sentinel-0
docker exec -it sentinel-0 sh
redis-cli -p 5000
info
sentinel master mymaster
# clean up
docker rm -f redis-0 redis-1 redis-2
docker rm -f sentinel-0 sentinel-1 sentinel-2
```

View File

@ -241,7 +241,7 @@ supervised no
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis_6379.pid
pidfile "/var/run/redis_6379.pid"
# Specify the server verbosity level.
# This can be one of:
@ -336,7 +336,7 @@ rdbcompression yes
rdbchecksum yes
# The filename where to dump the DB
dbfilename dump.rdb
dbfilename "dump.rdb"
# Remove RDB files used by replication in instances without persistence
# enabled. By default this option is disabled, however there are environments
@ -359,7 +359,7 @@ rdb-del-sync-files no
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /data/
dir "/data"
################################# REPLICATION #################################
@ -389,7 +389,7 @@ dir /data/
# starting the replication synchronization process, otherwise the master will
# refuse the replica request.
#
masterauth a-very-complex-password-here
masterauth "a-very-complex-password-here"
#
# However this is not enough if you are using Redis ACLs (for Redis version
# 6 or greater), and the default user is not capable of running the PSYNC
@ -1568,7 +1568,7 @@ hll-sparse-max-bytes 3000
# zero, the limit is ignored, so for instance it is possible to set just a
# max entires limit by setting max-bytes to 0 and max-entries to the desired
# value.
stream-node-max-bytes 4096
stream-node-max-bytes 4kb
stream-node-max-entries 100
# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
@ -1830,3 +1830,5 @@ jemalloc-bg-thread yes
#
# Set bgsave child process to cpu affinity 1,10,11
# bgsave_cpulist 1,10-11
# Generated by CONFIG REWRITE
user default on #fd2729bf2f67ef4a0941d633dd9055aebae62734b63505a4937e98ca1ecbcbad ~* +@all

View File

@ -4,7 +4,7 @@
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
replicaof 172.22.0.2 6379
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#

View File

@ -4,7 +4,7 @@
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
replicaof 172.22.0.2 6379
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#

View File

@ -1,21 +1,6 @@
port 26379
sentinel myid 33e6a688bbe5298b638ff8761e6c17a241cb4e9c
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 172.22.0.2 6379 2
port 5000
sentinel monitor mymaster redis-0 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
# sentinel monitor mymaster redis-0 6379 2
# sentinel down-after-milliseconds mymaster 5000
# sentinel failover-timeout mymaster 60000
# sentinel parallel-syncs mymaster 1
# Generated by CONFIG REWRITE
user default on nopass ~* +@all
dir "/data"
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster a-very-complex-password-here
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-replica mymaster 172.22.0.3 6379
sentinel known-replica mymaster 172.22.0.4 6379
sentinel known-sentinel mymaster 172.22.0.6 26379 d12ca24ea1a9a0790c0afb72785e78dc63a50f7b
sentinel known-sentinel mymaster 172.22.0.7 26379 c13ed147aa1fb839758aaed52928f49df37e7192
sentinel current-epoch 0

View File

@ -1,22 +1,6 @@
port 26379
sentinel myid d12ca24ea1a9a0790c0afb72785e78dc63a50f7b
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 172.22.0.2 6379 2
port 5000
sentinel monitor mymaster redis-0 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
# sentinel monitor mymaster redis-0 6379 2
# sentinel down-after-milliseconds mymaster 5000
# sentinel failover-timeout mymaster 60000
# sentinel parallel-syncs mymaster 1
# Generated by CONFIG REWRITE
user default on nopass ~* +@all
dir "/data"
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster a-very-complex-password-here
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-replica mymaster 172.22.0.4 6379
sentinel known-replica mymaster 172.22.0.3 6379
sentinel known-sentinel mymaster 172.22.0.7 26379 c13ed147aa1fb839758aaed52928f49df37e7192
sentinel known-sentinel mymaster 172.22.0.5 26379 33e6a688bbe5298b638ff8761e6c17a241cb4e9c
sentinel current-epoch 0

View File

@ -1,22 +1,6 @@
port 26379
sentinel myid c13ed147aa1fb839758aaed52928f49df37e7192
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 172.22.0.2 6379 2
port 5000
sentinel monitor mymaster redis-0 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
# sentinel monitor mymaster redis-0 6379 2
# sentinel down-after-milliseconds mymaster 5000
# sentinel failover-timeout mymaster 60000
# sentinel parallel-syncs mymaster 1
# Generated by CONFIG REWRITE
user default on nopass ~* +@all
dir "/data"
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster a-very-complex-password-here
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-replica mymaster 172.22.0.3 6379
sentinel known-replica mymaster 172.22.0.4 6379
sentinel known-sentinel mymaster 172.22.0.5 26379 33e6a688bbe5298b638ff8761e6c17a241cb4e9c
sentinel known-sentinel mymaster 172.22.0.6 26379 d12ca24ea1a9a0790c0afb72785e78dc63a50f7b
sentinel current-epoch 0