mirror of
https://github.com/marcel-dempers/docker-development-youtube-series.git
synced 2025-06-06 17:01:30 +00:00
redis clustering
This commit is contained in:
parent
4b8f92df85
commit
af6a960c17
@ -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
|
||||
|
||||
|
||||
```
|
||||
|
@ -142,7 +142,7 @@ tcp-keepalive 300
|
||||
# server to connected clients, masters or cluster peers. These files should be
|
||||
# PEM formatted.
|
||||
#
|
||||
# tls-cert-file redis.crt
|
||||
# tls-cert-file redis.crt
|
||||
# tls-key-file redis.key
|
||||
|
||||
# Configure a DH parameters file to enable Diffie-Hellman (DH) key exchange:
|
||||
@ -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
|
||||
@ -760,8 +760,8 @@ replica-priority 100
|
||||
# ACL LOG
|
||||
#
|
||||
# The ACL Log tracks failed commands and authentication events associated
|
||||
# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked
|
||||
# by ACLs. The ACL Log is stored in memory. You can reclaim memory with
|
||||
# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked
|
||||
# by ACLs. The ACL Log is stored in memory. You can reclaim memory with
|
||||
# ACL LOG RESET. Define the maximum entry length of the ACL Log below.
|
||||
acllog-max-len 128
|
||||
|
||||
@ -1293,18 +1293,18 @@ lua-time-limit 5000
|
||||
# cluster-replica-no-failover no
|
||||
|
||||
# This option, when set to yes, allows nodes to serve read traffic while the
|
||||
# the cluster is in a down state, as long as it believes it owns the slots.
|
||||
# the cluster is in a down state, as long as it believes it owns the slots.
|
||||
#
|
||||
# This is useful for two cases. The first case is for when an application
|
||||
# This is useful for two cases. The first case is for when an application
|
||||
# doesn't require consistency of data during node failures or network partitions.
|
||||
# One example of this is a cache, where as long as the node has the data it
|
||||
# should be able to serve it.
|
||||
# should be able to serve it.
|
||||
#
|
||||
# The second use case is for configurations that don't meet the recommended
|
||||
# three shards but want to enable cluster mode and scale later. A
|
||||
# The second use case is for configurations that don't meet the recommended
|
||||
# three shards but want to enable cluster mode and scale later. A
|
||||
# master outage in a 1 or 2 shard configuration causes a read/write outage to the
|
||||
# entire cluster without this option set, with it set there is only a write outage.
|
||||
# Without a quorum of masters, slot ownership will not change automatically.
|
||||
# Without a quorum of masters, slot ownership will not change automatically.
|
||||
#
|
||||
# cluster-allow-reads-when-down no
|
||||
|
||||
@ -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
|
||||
@ -1829,4 +1829,6 @@ jemalloc-bg-thread yes
|
||||
# aof_rewrite_cpulist 8-11
|
||||
#
|
||||
# Set bgsave child process to cpu affinity 1,10,11
|
||||
# bgsave_cpulist 1,10-11
|
||||
# bgsave_cpulist 1,10-11
|
||||
# Generated by CONFIG REWRITE
|
||||
user default on #fd2729bf2f67ef4a0941d633dd9055aebae62734b63505a4937e98ca1ecbcbad ~* +@all
|
||||
|
@ -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:
|
||||
#
|
||||
|
@ -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:
|
||||
#
|
||||
|
@ -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 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
|
||||
sentinel parallel-syncs mymaster 1
|
||||
sentinel auth-pass mymaster a-very-complex-password-here
|
@ -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 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
|
||||
sentinel parallel-syncs mymaster 1
|
||||
sentinel auth-pass mymaster a-very-complex-password-here
|
@ -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 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
|
||||
sentinel parallel-syncs mymaster 1
|
||||
sentinel auth-pass mymaster a-very-complex-password-here
|
Loading…
x
Reference in New Issue
Block a user