구성 계획
IP | Master 포터 | Slave 포트 |
---|---|---|
192.168.0.21 | 6379 | 6380 |
192.168.0.22 | 6379 | 6380 |
192.168.0.23 | 6379 | 6380 |
Redis 설치
192.168.0.21 ~ 23 공통
# 관련 패키지 설치
sudo apt install -y gcc make pkg-config libjemalloc-dev libjemalloc2 tcl libssl-dev libsystemd-dev
# redis 설치
wget http://download.redis.io/releases/redis-7.2.6.tar.gz
tar xvzf redis-7.2.6.tar.gz
cd redis-7.2.6
cd deps
make hiredis jemalloc linenoise lua
cd ..
make USE_SYSTEMD=yes
make test
make install PREFIX=/home/kalva/redis_6379
make install PREFIX=/home/kalva/redis_6380
cp redis.conf /home/kalva/redis_6379/redis_6379.conf
cp redis.conf /home/kalva/redis_6380/redis_6380.conf
# 로그 디렉토리 생성
mkdir /home/kalva/redis_6379/logs
mkdir /home/kalva/redis_6380/logs
# 모든 접속 허용
sed -i 's/^bind 127\.0\.0\.1 -::1$/bind 0.0.0.0/' /home/kalva/redis_6379/redis_6379.conf
sed -i 's/^bind 127\.0\.0\.1 -::1$/bind 0.0.0.0/' /home/kalva/redis_6380/redis_6380.conf
# 데몬으로 구동
sed -i 's/^daemonize no$/daemonize yes/' /home/kalva/redis_6379/redis_6379.conf
sed -i 's/^daemonize no$/daemonize yes/' /home/kalva/redis_6380/redis_6380.conf
# 보호모드 중지
sed -i 's/^protected-mode yes$/protected-mode no/' /home/kalva/redis_6379/redis_6379.conf
sed -i 's/^protected-mode yes$/protected-mode no/' /home/kalva/redis_6380/redis_6380.conf
# redis_6380 의 포트 변경
sed -i 's/^port 6379$/port 6380/' /home/kalva/redis_6380/redis_6380.conf
sed -i 's|^pidfile /var/run/redis_6379\.pid$|pidfile /home/kalva/redis_6379/redis_6379.pid|' /home/kalva/redis_6379/redis_6379.conf
sed -i 's|^pidfile /var/run/redis_6380.pid$|pidfile /home/kalva/redis_6380/redis_6380.pid|' /home/kalva/redis_6380/redis_6380.conf
sed -i 's|^logfile ""$|logfile /home/kalva/redis_6379/logs/redis_6379.log|' /home/kalva/redis_6379/redis_6379.conf
sed -i 's|^logfile ""$|logfile /home/kalva/redis_6380/logs/redis_6380.log|' /home/kalva/redis_6380/redis_6380.conf
sed -i.bak 's|^dir \./$|dir /home/kalva/redis_6379/|' /home/kalva/redis_6379/redis_6379.conf
sed -i.bak 's|^dir \./$|dir /home/kalva/redis_6380/|' /home/kalva/redis_6380/redis_6380.conf
# 패스워드 설정
sed -i 's|^# masterauth <master-password>$|masterauth mypasswd|' /home/kalva/redis_6379/redis_6379.conf
sed -i 's|^# masterauth <master-password>$|masterauth mypasswd|' /home/kalva/redis_6380/redis_6380.conf
sed -i 's|^# requirepass foobared$|requirepass mypasswd|' /home/kalva/redis_6379/redis_6379.conf
sed -i 's|^# requirepass foobared$|requirepass mypasswd|' /home/kalva/redis_6380/redis_6380.conf
# 클러스터 관련 설정
sed -i 's|^# cluster-enabled yes$|cluster-enabled yes|' /home/kalva/redis_6379/redis_6379.conf
sed -i 's|^# cluster-enabled yes$|cluster-enabled yes|' /home/kalva/redis_6380/redis_6380.conf
sed -i 's|^# cluster-config-file nodes-6379.conf$|cluster-config-file nodes-6379.conf|' /home/kalva/redis_6379/redis_6379.conf
sed -i 's|^# cluster-config-file nodes-6379.conf$|cluster-config-file nodes-6380.conf|' /home/kalva/redis_6380/redis_6380.conf
sed -i 's|^# cluster-node-timeout 15000$|cluster-node-timeout 3000|' /home/kalva/redis_6379/redis_6379.conf
sed -i 's|^# cluster-node-timeout 15000$|cluster-node-timeout 3000|' /home/kalva/redis_6380/redis_6380.conf
# 클러스터 구동
/home/kalva/redis_6379/bin/redis-server /home/kalva/redis_6379/redis_6379.conf
/home/kalva/redis_6380/bin/redis-server /home/kalva/redis_6380/redis_6380.conf
# redis 6379, 6380 노드가 떠있는지 확인
ps -ef | grep redis
클러스터에 master 노드 추가
- 노드중 한대에서 실행
/home/kalva/redis_6379/bin/redis-cli -a mypasswd --cluster create 192.168.0.21:6379 192.168.0.22:6379 192.168.0.23:6379 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Performing hash slots allocation on 3 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 M: ec4ef88dab3114407e2dd51e5e2d306d471a53a5 192.168.0.21:6379 slots:[0-5460] (5461 slots) master M: a31c6591e47d73b7f71312747ae1e1d162990226 192.168.0.22:6379 slots:[5461-10922] (5462 slots) master M: 433a817cf1fef7bd32b009739af468091f496e39 192.168.0.23:6379 slots:[10923-16383] (5461 slots) master 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.0.21:6379) M: ec4ef88dab3114407e2dd51e5e2d306d471a53a5 192.168.0.21:6379 slots:[0-5460] (5461 slots) master M: a31c6591e47d73b7f71312747ae1e1d162990226 192.168.0.22:6379 slots:[5461-10922] (5462 slots) master M: 433a817cf1fef7bd32b009739af468091f496e39 192.168.0.23:6379 slots:[10923-16383] (5461 slots) master [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
192.168.0.21의 Master log 확인
tail -n 3 /home/kalva/redis_6379/logs/redis_6379.log
1430:M 30 Nov 2024 07:33:03.750 * configEpoch set to 1 via CLUSTER SET-CONFIG-EPOCH
1430:M 30 Nov 2024 07:36:24.762 * IP address for this node updated to 192.168.0.21
1430:M 30 Nov 2024 07:36:25.066 * Cluster state changed: ok
192.168.0.22의 Master log 확인
tail -n 3 /home/kalva/redis_6379/logs/redis_6379.log
1564:M 30 Nov 2024 07:36:24.692 * configEpoch set to 2 via CLUSTER SET-CONFIG-EPOCH
1564:M 30 Nov 2024 07:36:24.861 * IP address for this node updated to 192.168.0.22
1564:M 30 Nov 2024 07:36:27.675 * Cluster state changed: ok
192.168.0.23의 Master log 확인
tail -n 3 /home/kalva/redis_6379/logs/redis_6379.log
1354:M 30 Nov 2024 07:36:24.692 * configEpoch set to 3 via CLUSTER SET-CONFIG-EPOCH
1354:M 30 Nov 2024 07:36:24.860 * IP address for this node updated to 192.168.0.23
1354:M 30 Nov 2024 07:36:27.679 * Cluster state changed: ok
# 클러스터에 slave 노드 추가
- 노드중 한대에서 실행
```shell
/home/kalva/redis_6379/bin/redis-cli -a mypasswd --cluster add-node 192.168.0.21:6380 192.168.0.21:6379 --cluster-slave
/home/kalva/redis_6379/bin/redis-cli -a mypasswd --cluster add-node 192.168.0.22:6380 192.168.0.22:6379 --cluster-slave
/home/kalva/redis_6379/bin/redis-cli -a mypasswd --cluster add-node 192.168.0.23:6380 192.168.0.23:6379 --cluster-slave
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.0.21:6380 to cluster 192.168.0.21:6379
>>> Performing Cluster Check (using node 192.168.0.21:6379)
M: ec4ef88dab3114407e2dd51e5e2d306d471a53a5 192.168.0.21:6379
slots:[0-5460] (5461 slots) master
M: a31c6591e47d73b7f71312747ae1e1d162990226 192.168.0.22:6379
slots:[5461-10922] (5462 slots) master
M: 433a817cf1fef7bd32b009739af468091f496e39 192.168.0.23:6379
slots:[10923-16383] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 192.168.0.21:6379
>>> Send CLUSTER MEET to node 192.168.0.21:6380 to make it join the cluster.
Waiting for the cluster to join
.
>>> Configure node as replica of 192.168.0.21:6379.
[OK] New node added correctly.
# 192.168.0.21의 Master log 확인
tail -n 11 /home/kalva/redis_6379/logs/redis_6379.log
1430:M 30 Nov 2024 07:40:32.116 * Replica 192.168.0.21:6380 asks for synchronization
1430:M 30 Nov 2024 07:40:32.116 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for '8fcc2bae37559b5542d2ff5a022f892afc2a25b8', my replication IDs are '99a275c14e36bc06e269cd6144c27978ce33175b' and '0000000000000000000000000000000000000000')
1430:M 30 Nov 2024 07:40:32.116 * Replication backlog created, my new replication IDs are 'e90468779cd2154eadd9d78d26918c06ba9e7bef' and '0000000000000000000000000000000000000000'
1430:M 30 Nov 2024 07:40:32.116 * Delay next BGSAVE for diskless SYNC
1430:M 30 Nov 2024 07:40:37.628 * Starting BGSAVE for SYNC with target: replicas sockets
1430:M 30 Nov 2024 07:40:37.628 * Background RDB transfer started by pid 1596
1596:C 30 Nov 2024 07:40:37.631 * Fork CoW for RDB: current 0 MB, peak 0 MB, average 0 MB
1430:M 30 Nov 2024 07:40:37.631 * Diskless rdb transfer, done reading from pipe, 1 replicas still up.
1430:M 30 Nov 2024 07:40:37.635 * Background RDB transfer terminated with success
1430:M 30 Nov 2024 07:40:37.636 * Streamed RDB transfer with replica 192.168.0.21:6380 succeeded (socket). Waiting for REPLCONF ACK from replica to enable streaming
1430:M 30 Nov 2024 07:40:37.636 * Synchronization with replica 192.168.0.21:6380 succeeded
# 192.168.0.21의 Slave log 확인
tail -n 16 /home/kalva/redis_6380/logs/redis_6380.log
1432:S 30 Nov 2024 07:40:32.115 * Connecting to MASTER 192.168.0.21:6379
1432:S 30 Nov 2024 07:40:32.115 * MASTER <-> REPLICA sync started
1432:S 30 Nov 2024 07:40:32.115 * Cluster state changed: ok
1432:S 30 Nov 2024 07:40:32.115 * Non blocking connect for SYNC fired the event.
1432:S 30 Nov 2024 07:40:32.115 * Master replied to PING, replication can continue...
1432:S 30 Nov 2024 07:40:32.116 * Trying a partial resynchronization (request 8fcc2bae37559b5542d2ff5a022f892afc2a25b8:1).
1432:S 30 Nov 2024 07:40:37.628 * Full resync from master: e90468779cd2154eadd9d78d26918c06ba9e7bef:14
1432:S 30 Nov 2024 07:40:37.630 * MASTER <-> REPLICA sync: receiving streamed RDB from master with EOF to disk
1432:S 30 Nov 2024 07:40:37.630 * Discarding previously cached master state.
1432:S 30 Nov 2024 07:40:37.630 * MASTER <-> REPLICA sync: Flushing old data
1432:S 30 Nov 2024 07:40:37.630 * MASTER <-> REPLICA sync: Loading DB in memory
1432:S 30 Nov 2024 07:40:37.635 * Loading RDB produced by version 7.2.6
1432:S 30 Nov 2024 07:40:37.635 * RDB age 0 seconds
1432:S 30 Nov 2024 07:40:37.635 * RDB memory usage when created 1.74 Mb
1432:S 30 Nov 2024 07:40:37.635 * Done loading RDB, keys loaded: 0, keys expired: 0.
1432:S 30 Nov 2024 07:40:37.635 * MASTER <-> REPLICA sync: Finished with success
# 192.168.0.22의 Master log 확인
tail -n 11 /home/kalva/redis_6379/logs/redis_6379.log
1564:M 30 Nov 2024 07:40:51.541 * Replica 192.168.0.22:6380 asks for synchronization
1564:M 30 Nov 2024 07:40:51.541 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for '437e582b5fe52fb6ce63b96e6d9cd8980767bb5e', my replication IDs are '9def95aadae68ad27af0691868bfc2273e37a815' and '0000000000000000000000000000000000000000')
1564:M 30 Nov 2024 07:40:51.541 * Replication backlog created, my new replication IDs are '19cf246e6a39a1c0f4c60c43cec6b9d72c97c73d' and '0000000000000000000000000000000000000000'
1564:M 30 Nov 2024 07:40:51.541 * Delay next BGSAVE for diskless SYNC
1564:M 30 Nov 2024 07:40:56.989 * Starting BGSAVE for SYNC with target: replicas sockets
1564:M 30 Nov 2024 07:40:56.990 * Background RDB transfer started by pid 1606
1606:C 30 Nov 2024 07:40:56.991 * Fork CoW for RDB: current 0 MB, peak 0 MB, average 0 MB
1564:M 30 Nov 2024 07:40:56.991 * Diskless rdb transfer, done reading from pipe, 1 replicas still up.
1564:M 30 Nov 2024 07:40:56.996 * Background RDB transfer terminated with success
1564:M 30 Nov 2024 07:40:56.996 * Streamed RDB transfer with replica 192.168.0.22:6380 succeeded (socket). Waiting for REPLCONF ACK from replica to enable streaming
1564:M 30 Nov 2024 07:40:56.996 * Synchronization with replica 192.168.0.22:6380 succeeded
# 192.168.0.22의 Slave log 확인
kalva@kalva:~$ tail -n 16 /home/kalva/redis_6380/logs/redis_6380.log
1447:S 30 Nov 2024 07:40:51.540 * Connecting to MASTER 192.168.0.22:6379
1447:S 30 Nov 2024 07:40:51.540 * MASTER <-> REPLICA sync started
1447:S 30 Nov 2024 07:40:51.540 * Cluster state changed: ok
1447:S 30 Nov 2024 07:40:51.540 * Non blocking connect for SYNC fired the event.
1447:S 30 Nov 2024 07:40:51.541 * Master replied to PING, replication can continue...
1447:S 30 Nov 2024 07:40:51.541 * Trying a partial resynchronization (request 437e582b5fe52fb6ce63b96e6d9cd8980767bb5e:1).
1447:S 30 Nov 2024 07:40:56.990 * Full resync from master: 19cf246e6a39a1c0f4c60c43cec6b9d72c97c73d:14
1447:S 30 Nov 2024 07:40:56.990 * MASTER <-> REPLICA sync: receiving streamed RDB from master with EOF to disk
1447:S 30 Nov 2024 07:40:56.990 * Discarding previously cached master state.
1447:S 30 Nov 2024 07:40:56.991 * MASTER <-> REPLICA sync: Flushing old data
1447:S 30 Nov 2024 07:40:56.991 * MASTER <-> REPLICA sync: Loading DB in memory
1447:S 30 Nov 2024 07:40:56.995 * Loading RDB produced by version 7.2.6
1447:S 30 Nov 2024 07:40:56.995 * RDB age 0 seconds
1447:S 30 Nov 2024 07:40:56.995 * RDB memory usage when created 1.77 Mb
1447:S 30 Nov 2024 07:40:56.995 * Done loading RDB, keys loaded: 0, keys expired: 0.
1447:S 30 Nov 2024 07:40:56.995 * MASTER <-> REPLICA sync: Finished with success
# 192.168.0.23의 Master log 확인
tail -n 11 /home/kalva/redis_6379/logs/redis_6379.log
1354:M 30 Nov 2024 07:40:56.420 * Replica 192.168.0.23:6380 asks for synchronization
1354:M 30 Nov 2024 07:40:56.420 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for '5f36e0ff7abcdd458cdaa5c7638ba46f7d1a5ff1', my replication IDs are 'ee75400b0f5f357dd5778f49a5b1c93cbd418b1a' and '0000000000000000000000000000000000000000')
1354:M 30 Nov 2024 07:40:56.420 * Replication backlog created, my new replication IDs are '4f7a1b0917ba1aa9f59a1f312c7ac22d1857dfd6' and '0000000000000000000000000000000000000000'
1354:M 30 Nov 2024 07:40:56.420 * Delay next BGSAVE for diskless SYNC
1354:M 30 Nov 2024 07:41:01.901 * Starting BGSAVE for SYNC with target: replicas sockets
1354:M 30 Nov 2024 07:41:01.901 * Background RDB transfer started by pid 1399
1399:C 30 Nov 2024 07:41:01.902 * Fork CoW for RDB: current 0 MB, peak 0 MB, average 0 MB
1354:M 30 Nov 2024 07:41:01.902 * Diskless rdb transfer, done reading from pipe, 1 replicas still up.
1354:M 30 Nov 2024 07:41:01.907 * Background RDB transfer terminated with success
1354:M 30 Nov 2024 07:41:01.907 * Streamed RDB transfer with replica 192.168.0.23:6380 succeeded (socket). Waiting for REPLCONF ACK from replica to enable streaming
1354:M 30 Nov 2024 07:41:01.907 * Synchronization with replica 192.168.0.23:6380 succeeded
# 192.168.0.23의 Slave log 확인
kalva@kalva:~$ tail -n 16 /home/kalva/redis_6380/logs/redis_6380.log
1227:S 30 Nov 2024 07:40:56.419 * Connecting to MASTER 192.168.0.23:6379
1227:S 30 Nov 2024 07:40:56.419 * MASTER <-> REPLICA sync started
1227:S 30 Nov 2024 07:40:56.419 * Cluster state changed: ok
1227:S 30 Nov 2024 07:40:56.419 * Non blocking connect for SYNC fired the event.
1227:S 30 Nov 2024 07:40:56.420 * Master replied to PING, replication can continue...
1227:S 30 Nov 2024 07:40:56.420 * Trying a partial resynchronization (request 5f36e0ff7abcdd458cdaa5c7638ba46f7d1a5ff1:1).
1227:S 30 Nov 2024 07:41:01.901 * Full resync from master: 4f7a1b0917ba1aa9f59a1f312c7ac22d1857dfd6:14
1227:S 30 Nov 2024 07:41:01.902 * MASTER <-> REPLICA sync: receiving streamed RDB from master with EOF to disk
1227:S 30 Nov 2024 07:41:01.902 * Discarding previously cached master state.
1227:S 30 Nov 2024 07:41:01.902 * MASTER <-> REPLICA sync: Flushing old data
1227:S 30 Nov 2024 07:41:01.902 * MASTER <-> REPLICA sync: Loading DB in memory
1227:S 30 Nov 2024 07:41:01.906 * Loading RDB produced by version 7.2.6
1227:S 30 Nov 2024 07:41:01.906 * RDB age 0 seconds
1227:S 30 Nov 2024 07:41:01.906 * RDB memory usage when created 1.77 Mb
1227:S 30 Nov 2024 07:41:01.906 * Done loading RDB, keys loaded: 0, keys expired: 0.
1227:S 30 Nov 2024 07:41:01.906 * MASTER <-> REPLICA sync: Finished with success
클러스터 정보 확인
kalva@kalva:~$ /home/kalva/redis_6379/bin/redis-cli
127.0.0.1:6379> auth mypasswd
OK
127.0.0.1:6379> 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:3
cluster_my_epoch:1
cluster_stats_messages_ping_sent:4036
cluster_stats_messages_pong_sent:4057
cluster_stats_messages_sent:8093
cluster_stats_messages_ping_received:4054
cluster_stats_messages_pong_received:4036
cluster_stats_messages_meet_received:3
cluster_stats_messages_received:8093
total_cluster_links_buffer_limit_exceeded:0
127.0.0.1:6379> cluster nodes
db37ced5fdd81a8638abc40dbd87055c22f69544 192.168.0.21:6380@16380 slave ec4ef88dab3114407e2dd51e5e2d306d471a53a5 0 1732953623040 1 connected
59ba65b01e657c1ab74b3502f2382cda995dbacd 192.168.0.22:6380@16380 slave a31c6591e47d73b7f71312747ae1e1d162990226 0 1732953622538 2 connected
a31c6591e47d73b7f71312747ae1e1d162990226 192.168.0.22:6379@16379 master - 0 1732953622036 2 connected 5461-10922
ec4ef88dab3114407e2dd51e5e2d306d471a53a5 192.168.0.21:6379@16379 myself,master - 0 1732953622000 1 connected 0-5460
3a63fdc4ef504b77b8120c369288baf34a393b0e 192.168.0.23:6380@16380 slave 433a817cf1fef7bd32b009739af468091f496e39 0 1732953622538 3 connected
433a817cf1fef7bd32b009739af468091f496e39 192.168.0.23:6379@16379 master - 0 1732953623040 3 connected 10923-16383
'Redis' 카테고리의 다른 글
복제 구성, sentinel (0) | 2024.11.27 |
---|---|
Redis 관리 (0) | 2024.11.27 |
WSL2 + Rocky Linux 8 + Redis 7.2 설치 (0) | 2023.12.10 |