-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose-IP-Addresses.yaml
More file actions
153 lines (140 loc) · 4.44 KB
/
docker-compose-IP-Addresses.yaml
File metadata and controls
153 lines (140 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#------------------------------------------------------------------------------------------
# This works!!!!!
# Process: Redis high availability with static IP addresses.
#------------------------------------------------------------------------------------------
# [Window 1]: docker compose --file docker-compose-IP-Addresses.yaml up -d
# [Window 2]: docker logs sentinel-1 -f
# [Window 1]: docker container stop redis-master
# [Window 2]: see logs and failover unfold
#------------------------------------------------------------------------------------------
# Helper commands:
# docker exec -it redis-master bash -c "redis-cli info replication"
# docker exec -it redis-slave-1 bash -c "redis-cli info replication"
# docker exec -it sentinel-1 bash -c "redis-cli -p 26379 sentinel get-master-addr-by-name mymaster"
# docker container start redis-master
# docker container stop redis-slave-1
# docker container start redis-slave-1
#------------------------------------------------------------------------------------------
name: redistest
services:
redis-master:
image: redis:8.2.2
container_name: redis-master
hostname: redis-master
volumes:
- redismaster:/data
command:
[
"redis-server",
"--appendonly",
"yes",
"--protected-mode",
"no"
]
networks:
redis-net:
ipv4_address: 172.21.0.141
redis-slave-1:
image: redis:8.2.2
container_name: redis-slave-1
hostname: redis-slave-1
depends_on:
- redis-master
volumes:
- redisslave1:/data
command:
[
"redis-server",
"--appendonly",
"yes",
"--replicaof",
"172.21.0.141",
"6379",
"--protected-mode",
"no"
]
networks:
redis-net:
ipv4_address: 172.21.0.142
redis-slave-2:
image: redis:8.2.2
container_name: redis-slave-2
hostname: redis-slave-2
depends_on:
- redis-master
volumes:
- redisslave2:/data
command:
[
"redis-server",
"--appendonly",
"yes",
"--replicaof",
"172.21.0.141",
"6379",
"--protected-mode",
"no"
]
networks:
redis-net:
ipv4_address: 172.21.0.143
sentinel-1:
image: redis:8.2.2
container_name: sentinel-1
hostname: sentinel-1
depends_on:
- redis-master
command: >
sh -c 'echo "bind 0.0.0.0" > /etc/sentinel.conf &&
echo "sentinel monitor mymaster 172.21.0.141 6379 2" >> /etc/sentinel.conf &&
echo "sentinel down-after-milliseconds mymaster 5000" >> /etc/sentinel.conf &&
echo "sentinel failover-timeout mymaster 10000" >> /etc/sentinel.conf &&
echo "sentinel parallel-syncs mymaster 1" >> /etc/sentinel.conf &&
redis-sentinel /etc/sentinel.conf'
networks:
redis-net:
ipv4_address: 172.21.0.151
sentinel-2:
image: redis:8.2.2
container_name: sentinel-2
hostname: sentinel-2
depends_on:
- redis-master
command: >
sh -c 'echo "bind 0.0.0.0" > /etc/sentinel.conf &&
echo "sentinel monitor mymaster 172.21.0.141 6379 2" >> /etc/sentinel.conf &&
echo "sentinel down-after-milliseconds mymaster 5000" >> /etc/sentinel.conf &&
echo "sentinel failover-timeout mymaster 10000" >> /etc/sentinel.conf &&
echo "sentinel parallel-syncs mymaster 1" >> /etc/sentinel.conf &&
redis-sentinel /etc/sentinel.conf'
networks:
redis-net:
ipv4_address: 172.21.0.152
sentinel-3:
image: redis:8.2.2
container_name: sentinel-3
hostname: sentinel-3
depends_on:
- redis-master
command: >
sh -c 'echo "bind 0.0.0.0" > /etc/sentinel.conf &&
echo "sentinel monitor mymaster 172.21.0.141 6379 2" >> /etc/sentinel.conf &&
echo "sentinel down-after-milliseconds mymaster 5000" >> /etc/sentinel.conf &&
echo "sentinel failover-timeout mymaster 10000" >> /etc/sentinel.conf &&
echo "sentinel parallel-syncs mymaster 1" >> /etc/sentinel.conf &&
redis-sentinel /etc/sentinel.conf'
networks:
redis-net:
ipv4_address: 172.21.0.153
volumes:
redismaster:
redisslave1:
redisslave2:
networks:
redis-net:
ipam:
config:
# HostMin: 172.21.0.1 - HostMax: 172.21.0.254
- subnet: 172.21.0.0/24
# HostMin: 172.21.0.1 - HostMax: 172.21.0.126
ip_range: 172.21.0.0/25