Redis Cluster x Docker)๊ณผ ์ด์ด์ง๋ ๋ด์ฉ์ด๋ค.
Redis cluster์ slave node๋ฅผ ์ถ๊ฐํด๋ณด์.
Slave node๋ master node์ ๋ณต์ ๋ณธ์ด๊ณ , master node์์ ์ฅ์ ๋ฐ์ ์ master๋ก ์น๊ฒฉํ๋ค.
์ด์์ ์ธ HA๋ฅผ ์ํด ๋์ผ ์ ๋ณด๋ฅผ ์ ์ฅํ๊ณ ์๋ master์ slave๋ ๋ค๋ฅธ ์๋ฒ์ ๋ถ๋ฆฌ์์ผ ๋๋ ๊ฒ์ด ์ข๋ค.
์ด๋ฆ | ์ฃผ์ | ํด๋ฌ์คํฐ |
---|---|---|
node1 | 192.168.56.100 | redis-master-1, redis-slave-3 |
node2 | 192.168.56.101 | redis-master-2, redis-slave-1 |
node3 | 192.168.56.102 | redis-master-3, redis-slave-2 |
master | slave | |
---|---|---|
1 | redis-master-1 | redis-slave-1 |
2 | redis-master-2 | redis-slave-2 |
3 | redis-master-3 | redis-slave-3 |
--cluster-replicas
๋ฅผ 1๋ก ์ค์ ํ์ฌ ํ๋์ master๋น ํ๋์ slave๋ก ๊ตฌ์ฑํ๋ค.
master๋ ์์์ ๋ถํฐ ์ฐจ๋ก๋๋ก ํ ๋น๋๋ฉฐ ํ ๋น์ด ๋๋ ํ slave๋ ์ฐจ๋ก๋๋ก master์ ๋งคํ๋๋ค.
$ docker exec -it redis-master-1 bash
$ redis-cli --cluster create 192.168.56.100:7001 192.168.56.101:7001 192.168.56.102:7001 192.168.56.100:7002 192.168.56.101:7002 192.168.56.102:7002 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.56.101:7002 to 192.168.56.100:7001
Adding replica 192.168.56.102:7002 to 192.168.56.101:7001
Adding replica 192.168.56.100:7002 to 192.168.56.102:7001
M: 5b56d458a0d8e64d5f40ece0a99713dcb9c70723 192.168.56.100:7001
slots:[0-5460] (5461 slots) master
M: c952f5ef4783b5c19129bc630b88e8e3bf602622 192.168.56.101:7001
slots:[5461-10922] (5462 slots) master
M: 22110f4ea10f11a8cb6ea283dedfc27c6ffabc07 192.168.56.102:7001
slots:[10923-16383] (5461 slots) master
S: 30a99d668af3ddda16e2a9d3ee97fb53a5ebfa6d 192.168.56.100:7002
replicates 22110f4ea10f11a8cb6ea283dedfc27c6ffabc07
S: e0d9ee09b593889cd093d217a16a0b535e6abef2 192.168.56.101:7002
replicates 5b56d458a0d8e64d5f40ece0a99713dcb9c70723
S: 094af2ab1db0d147d7f475f3954429ae7d18dee0 192.168.56.102:7002
replicates c952f5ef4783b5c19129bc630b88e8e3bf602622
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 192.168.56.100:7001)
M: 5b56d458a0d8e64d5f40ece0a99713dcb9c70723 192.168.56.100:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: e0d9ee09b593889cd093d217a16a0b535e6abef2 192.168.56.101:7002
slots: (0 slots) slave
replicates 5b56d458a0d8e64d5f40ece0a99713dcb9c70723
S: 30a99d668af3ddda16e2a9d3ee97fb53a5ebfa6d 192.168.56.100:7002
slots: (0 slots) slave
replicates 22110f4ea10f11a8cb6ea283dedfc27c6ffabc07
M: 22110f4ea10f11a8cb6ea283dedfc27c6ffabc07 192.168.56.102:7001
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
M: c952f5ef4783b5c19129bc630b88e8e3bf602622 192.168.56.101:7001
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 094af2ab1db0d147d7f475f3954429ae7d18dee0 192.168.56.102:7002
slots: (0 slots) slave
replicates c952f5ef4783b5c19129bc630b88e8e3bf602622
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
redis-cli --cluster create $MASTER_1 ... $MASTER_N $SLAVE_1 ... $SLAVE_N --cluster-replicas 1
--cluster-replicas
๋งํผ ๋ณต์ ๋ณธ์ ๊ฐ์ง cluster๋ฅผ ์์ฑํ๋ค.$ redis-cli -c -p 7001
127.0.0.1:7001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:800
cluster_stats_messages_pong_sent:810
cluster_stats_messages_sent:1610
cluster_stats_messages_ping_received:805
cluster_stats_messages_pong_received:800
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1610
127.0.0.1:7001> cluster nodes
e0d9ee09b593889cd093d217a16a0b535e6abef2 192.168.56.101:7002@17002 slave 5b56d458a0d8e64d5f40ece0a99713dcb9c70723 0 1624430604104 1 connected
30a99d668af3ddda16e2a9d3ee97fb53a5ebfa6d 192.168.56.100:7002@17002 slave 22110f4ea10f11a8cb6ea283dedfc27c6ffabc07 0 1624430604000 3 connected
22110f4ea10f11a8cb6ea283dedfc27c6ffabc07 192.168.56.102:7001@17001 master - 0 1624430604000 3 connected 10923-16383
c952f5ef4783b5c19129bc630b88e8e3bf602622 192.168.56.101:7001@17001 master - 0 1624430604306 2 connected 5461-10922
094af2ab1db0d147d7f475f3954429ae7d18dee0 192.168.56.102:7002@17002 slave c952f5ef4783b5c19129bc630b88e8e3bf602622 0 1624430603000 2 connected
5b56d458a0d8e64d5f40ece0a99713dcb9c70723 192.168.56.100:7001@17001 myself,master - 0 1624430603000 1 connected 0-5460
cluster_size:3
cluster_known_nodes
redis๊ฐ ํต์ ์ด ๋์ง ์์ ๋ ๋ค์์ ํ์ธํด๋ณธ๋ค.
1. docker container๊ฐ host network๋ฅผ ์ฌ์ฉํด์ผํ๋ค.
2. redis.conf
์์ cluster-config-file
์ค์ ์ด ๊ฐ๋ฆฌํค๋ ํ์ผ์ node ๋ณ ํ๋์ฉ ์กด์ฌํด์ผ ํ๋ค.
3. ๋ฐฉํ๋ฒฝ์ ํ์ธํ๋ค.
docker-compose๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ, docker-compose.yaml
์ ๋ค์์ ์ถ๊ฐํ๋ค.
network_mode: "host"
redis.conf
node์ ํ๊ฒฝ ์ค์ ์ ์
ํ
ํ๋ ํ์ผ์ด๋ค.
์ฌ๊ธฐ์ cluster-config-file
์ ํตํด ์ค์ ๋์ด์ง config์ ๋ณด๋ฅผ ์ ์ฅํ ํ์ผ๋ช
์ ๊ธฐ์
ํ๋ค.
๋ง์ํ๋ docker volume mount๋ฅผ ํตํด ์ ๋ณด๋ฅผ ์ ์ฅํ ํ์ผ ๋ช
์ด ๊ฒน์น๊ฒ ๋๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค.
Linux์ ๊ฒฝ์ฐ ํํ ๋ฐ์ํ๋ ๋ฌธ์ ์ด๋ค.
๋ฐฉํ๋ฒฝ์ ๋์๋ ์์ง๋ง ๋ณด์์ ์ํด ๋ค์์ ๊ถ์ฅํ๋ค.
$ sudo firewall-cmd --list-all --permanent --zone=public
$ sudo firewall-cmd --permanent --add-port=7051/tcp --zone=public
$ sudo firewall-cmd --permanent --add-port=17051/tcp --zone=public
$ sudo firewall-cmd --permanent --add-port=7052/tcp --zone=public
$ sudo firewall-cmd --permanent --add-port=17052/tcp --zone=public
$ sudo firewall-cmd --reload
$ sudo firewall-cmd --list-all --permanent --zone=public
# ํ์ฉ๋ ํฌํธ ์ ๊ฑฐ
$ sudo firewall-cmd --permanent --remove-port=7001/tcp --zone=public
# ํ์ฉ๋ ์๋น์ค ์ ๊ฑฐ
$ sudo firewall-cmd --permanent --remove-service=http --zone=public
์๋ ํ์ธ์.
ํฌ์คํ ๋ณด๋ฉด์ ๊ณต๋ถํ๊ณ ์๋๋ฐ 1. Configuration information ์ด๋ถ๋ถ์์ ๋งํ์์ ํด๋น ๋์ปค์์ ํด๋น ์์ดํผ 3๊ฐ์ master, slave๋ก ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์...์ ๋ชจ๋ฅด๊ฒ ์ด์์ ใ ใ ๊ฐ๊ฐ์ ์ปจํ ์ด๋๋ ๊ณ ์ ์ ip๋ฅผ ๊ฐ์ง๋๋ฐ master๋ slave๊ฐ ๊ฐ์ ip๋ฅผ ์ฌ์ฉํ๊ณ port๋ง ๋ค๋ฅด๊ฒ ์ด๋ป๊ฒ ๊ตฌ์ฑํด์ผํ๋์ง.. ์๋ ค์ฃผ์ค ์ ์์๊น์? ใ ใ ..