구성 계획

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

구성 계획

  • 192.168.0.11 redis, sentinel
  • 192.168.0.12 redis, sentinel
  • 192.168.0.13 redis, sentinel
  • redis 포트 : 6379
  • sentinel 포트 : 26379

redis 설치, 설정

192.168.0.11 ~ 192.168.0.13 공통

# 관련 패키지 설치 
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.4.tar.gz
tar xvzf redis-7.2.4.tar.gz 
cd redis-7.2.4
cd deps
make hiredis jemalloc linenoise lua
cd ..
make USE_SYSTEMD=yes
make test 
make install PREFIX=/home/kalva/redis_6379

# 설정 파일 복사
cp redis.conf /home/kalva/redis_6379/redis_6379.conf
cp sentinel.conf /home/kalva/redis_6379/sentinel_26379.conf

# 로그 디렉토리 생성 
cd /home/kalva/redis_6379
mkdir logs

192.168.0.11 redis 설정, 구동

vi /home/kalva/redis_6379/redis_6379.conf
# 모두 접속 허용
bind 0.0.0.0
# 백그라운드로 동작
daemonize yes
# pid파일 위치
pidfile "/home/kalva/redis_6379/redis_6379.pid"
# log파일 위치
logfile "/home/kalva/redis_6379/logs/redis_6379.log"
# rdb 파일 디렉토리 
dir /home/kalva/redis-7.2.4/
# 슬레이브가 마스터 서버와 통신하기 위한 패스워드 
masterauth mypass
# redis 클라이언트가 redis 와 통신하기 위한 패스워드 
requirepass mypass
appendonly yes
appendfsync everysec

# Redis 구동 
/home/kalva/redis_6379/bin/redis-server /home/kalva/redis_6379/redis_6379.conf

192.168.0.12, 192.168.0.13 redis 설정, 구동

vi /home/kalva/redis_6379/redis_6379.conf
# 모두 접속 허용
bind 0.0.0.0
# 백그라운드로 동작
daemonize yes
# pid파일 위치
logfile "/home/kalva/redis_6379/logs/redis_6379.log"
# log파일 위치
pidfile "/home/kalva/redis_6379/redis_6379.pid"
# rdb 파일 디렉토리 
dir /home/kalva/redis-7.2.4/
# 슬레이브가 마스터 서버와 통신하기 위한 패스워드 
masterauth mypass
# redis 클라이언트가 redis 와 통신하기 위한 패스워드 
requirepass mypass
appendonly yes
appendfsync everysec

# 복제 마스터 서버 정보 
replicaof 192.168.0.11 6379

# Redis 구동 
/home/kalva/redis_6379/bin/redis-server /home/kalva/redis_6379/redis_6379.conf

sentinel 설정

192.168.0.11 ~ 192.168.0.13 redis 설정, 구동

vi /home/kalva/redis_6379/sentinel_26379.conf
# 백그라운드로 동작
daemonize yes
# pid파일 위치
pidfile "/home/kalva/redis_6379/sentinel_26379.pid"
# log파일 위치
logfile "/home/kalva/redis_6379/logs/sentinel_26379.log"
# 모니터링 대상 master정보, 쿼럼설정 
sentinel monitor mymaster 192.168.0.11 6379 2
# master비번
sentinel auth-pass mymaster mypass
# master 다운판정 시간 6초
sentinel down-after-milliseconds mymaster 6000
# failover 완료되어야 하는 시간
sentinel failover-timeout mymaster 180000

# sentinel 구동 
/home/kalva/redis_6379/bin/redis-sentinel /home/kalva/redis_6379/sentinel_26379.conf

구동 테스트

복제 정보, 센티널 정보 확인

# 복제 정보 확인 
kalva@kalva:~$ /home/kalva/redis_6379/bin/redis-cli -h 192.168.0.11 
192.168.0.11:6379> auth mypass
OK
192.168.0.11:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.0.12,port=6379,state=online,offset=406,lag=0
slave1:ip=192.168.0.13,port=6379,state=online,offset=406,lag=0
master_failover_state:no-failover
master_replid:bd536db1af0fc367cce17cb5bede06e52ac778e3
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:406
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:406
192.168.0.11:6379> 

# 센티널 노드 확인
# slaves=2,sentinels=3 가 맞는지 확인 
kalva@kalva:~$ /home/kalva/redis_6379/bin/redis-cli -h 192.168.0.11 -p 26379 info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_tilt_since_seconds:-1
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.0.11:6379,slaves=2,sentinels=3

master 노드 확인

kalva@kalva:~$ /home/kalva/redis_6379/bin/redis-cli -h 192.168.0.11 -p 26379  sentinel get-master-addr-by-name mymaster
1) "192.168.0.11"
2) "6379"

Failover 테스트

# 192.168.0.13 서버 우선순위 50으로 설정
# replica-priority 값이 낮을수록 우선순위기 높다. 
kalva@kalva:~$ /home/kalva/redis_6379/bin/redis-cli
127.0.0.1:6379> auth mypass
OK
127.0.0.1:6379> CONFIG SET replica-priority 50
OK

# FAILOVER
kalva@kalva:~$ /home/kalva/redis_6379/bin/redis-cli -h 192.168.0.11 -p 26379 
192.168.0.11:26379> SENTINEL FAILOVER mymaster
OK

# 마스터 노드 확인 
192.168.0.11:26379> SENTINEL GET-MASTER-ADDR-BY-NAME mymaster
1) "192.168.0.13"
2) "6379"

# 192.168.0.13 에서 확인 
kalva@kalva:~/redis_6379$ /home/kalva/redis_6379/bin/redis-cli 
127.0.0.1:6379> auth mypass
OK
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.0.12,port=6379,state=online,offset=554510,lag=0
slave1:ip=192.168.0.11,port=6379,state=online,offset=554510,lag=0
master_failover_state:no-failover
master_replid:ef914c9e01ccbc78289a259f66c5894b4818e248
master_replid2:bd536db1af0fc367cce17cb5bede06e52ac778e3
master_repl_offset:554649
second_repl_offset:453815
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:554635


kalva@kalva:~$ /home/kalva/redis_6379/bin/redis-cli -h 192.168.0.11 -p 26379 
192.168.0.11:26379> SENTINEL SENTINELS mymaster
1)  1) "name"
    2) "93275507e9835dc182df09356d8fe829715b3eae"
    3) "ip"
    4) "192.168.0.12"
    5) "port"
    6) "26379"
    7) "runid"
    8) "93275507e9835dc182df09356d8fe829715b3eae"
    9) "flags"
   10) "sentinel"
   11) "link-pending-commands"
   12) "0"
   13) "link-refcount"
   14) "1"
   15) "last-ping-sent"
   16) "0"
   17) "last-ok-ping-reply"
   18) "270"
   19) "last-ping-reply"
   20) "270"
   21) "down-after-milliseconds"
   22) "6000"
   23) "last-hello-message"
   24) "1868"
   25) "voted-leader"
   26) "?"
   27) "voted-leader-epoch"
   28) "0"
2)  1) "name"
    2) "c4c59fc8e54187cd99f926a677f3e4a9bf88c68b"
    3) "ip"
    4) "192.168.0.13"
    5) "port"
    6) "26379"
    7) "runid"
    8) "c4c59fc8e54187cd99f926a677f3e4a9bf88c68b"
    9) "flags"
   10) "sentinel"
   11) "link-pending-commands"
   12) "0"
   13) "link-refcount"
   14) "1"
   15) "last-ping-sent"
   16) "0"
   17) "last-ok-ping-reply"
   18) "270"
   19) "last-ping-reply"
   20) "270"
   21) "down-after-milliseconds"
   22) "6000"
   23) "last-hello-message"
   24) "233"
   25) "voted-leader"
   26) "?"
   27) "voted-leader-epoch"
   28) "0"

'Redis' 카테고리의 다른 글

클러스터 구성  (0) 2024.12.01
Redis 관리  (0) 2024.11.27
WSL2 + Rocky Linux 8 + Redis 7.2 설치  (0) 2023.12.10
  • Redis 의 대표적 특징

    • Single threaded
    • 한번에 하나의 명령어만 실행 가능
    • 처리시간이 긴 명령어를 실생하면 그뒤에 있는 명령어들은 전부 대기
      • 전체 키를 불러오는 Keys명령어 처리가 오래 걸림
      • Keys 명령어 실행시 뒤의 Get/Set 명령어들은 대기로 타임아웃 또는 실패 할수도 있음
  • Redis 서버의 메메로 한계 도달시

    • 메모리 한계 maxmemory 로 설정
    • maxmemory 까지 메모리 사용시 maxmemory policy 에 따라 추가 메모리 확보
  • maxmemory policy 설정값 (메모리 확보 정책)

    • noeviction
      • 기존 데이터 삭제안함
      • 메모리 부족시 OOM(Out Of Memory) 오류 반환후 새로운 데이터 삭제
    • allkeys-lru
      • LRU(Least Recently Used) 페이지 교체 알고리즘으로 데이터 삭제
    • volatile-lru
      • expire set을 가진 것중 LRU로 삭제
    • allkeys-random
      • 램덤으로 데이터 삭제
    • volatile-random
      • expire set을 가진것 중 랜덤으로 데이터 삭제
    • volatile-ttl
      • expire set을 가진것 중 TTL(Time To Live) 값이 짧은것부터 삭제
    • allkeys-lfu
      • 가장 적게 액세스한 키 제거
    • volatile-lfu
      • expire set을 가진것 중 가장 적게 액세스한 키부터 제거
  • eviction

    • maxmemory 초과로 데이터가 지워지는것
    • redis-cli 에서 INFO 명령어 실행시 evicted_keys 수치로 eviction 발생 여부 확인 가능
    • evicted_keys
      • evicted된 키들의 count 로 크면 클루록 많은 데이터가 메모리에서 삭제된것임
  • maxmemory 설정 예외

    • 쓰기 요청 처리시 COW(Copy On Write) 방식으로 작동
    • 쓰기 요청은 OS는 fork()를 통해 자식 프로세스를 생성함
    • fork() 시에 가상 메모리 주소를 할당받지만 물리 메모리 블록을 공유함
    • 쓰기 작업 시작시 수정할 메모리 페이지 복사후 쓰기 작업 진행
      • 추가 메모리 필요
    • fork 시 복사할 사이즈만큼 free memory 필요
  • /porc/sys/vm/overcommit_memory 값 1로 설정 필요

    • overcommit_memory=0
      • OS는 주어진 메모리량보다 크게 할당 불가
      • fork()시에 OS가 충분한 메모리가 없다고 판단해서 에러 발생
    • overcommit_memory=1
      • OS에게 over 해서 메모리 할당가능하게 설정
      • maxmemory에 도달시 policy 에 따라 처리됨
  • used_memory_rss

    • redis 의 memory 수치중 주요 모니터링 항목
    • 데이터를 포함해서 redis 가 실제로 사용하고 있는 메모리 크기
    • 실제로 사용하고 있는 used_memory 보다 클수 있음
      • OS가 메모리 할당시 page 사이즈의 배수만큼 할당하기 때문
      • page size = 4096 일때, 요청 메모리 사이즈가 10이라도 OS는 4096만큼 할당함, 이를 Pragmentation (파편화) 현상이라고함

'Redis' 카테고리의 다른 글

클러스터 구성  (0) 2024.12.01
복제 구성, sentinel  (0) 2024.11.27
WSL2 + Rocky Linux 8 + Redis 7.2 설치  (0) 2023.12.10

WSL2 에 Rocky Linux 8 설치

PS E:\Hyper-V> wsl --import Redis72 E:\Hyper-V\Redis72 E:\Hyper-V\Rocky-8-Container-Base.latest.x86_64.tar.xz --version 2


PS E:\Hyper-V> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-22.04    Stopped         2
  Redis72         Stopped         2
  PostgreSQL14    Stopped         2

PS E:\Hyper-V> wsl -d Redis72

Redis 7.2 설치

-- 저장소 설치 
[root@RT-PC Hyper-V]# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
[root@RT-PC Hyper-V]# dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

-- redis 모듈 검색 
[root@RT-PC Hyper-V]# dnf module list redis
Rocky Linux 8 - AppStream
Name                 Stream                  Profiles                  Summary
redis                5 [d]                   common [d]                Redis persistent key-value database
redis                6                       common [d]                Redis persistent key-value database

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name                 Stream                  Profiles                  Summary
redis                remi-5.0                common [d]                Redis persistent key-value database
redis                remi-6.0                common [d]                Redis persistent key-value database
redis                remi-6.2                common [d]                Redis persistent key-value database
redis                remi-7.0                common [d]                Redis persistent key-value database
redis                remi-7.2                common [d]                Redis persistent key-value database

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

-- 7.2 버전 설치 
[root@RT-PC Hyper-V]# dnf module reset redis
[root@RT-PC Hyper-V]# dnf module install redis:remi-7.2

-- redis 서비스 사용 설정 
[root@RT-PC ~]# systemctl enable redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.

-- redis 서비스 시작 
[root@RT-PC ~]# systemctl start redis
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

-- systemctl 사용 설정 
[root@RT-PC ~]# echo "[boot]
systemd=true" | tee /etc/wsl.conf

-- Redis72 를 재기동한다. 
[root@RT-PC ~]# exit
logout

PS E:\Hyper-V> wsl -t Redis72
작업을 완료했습니다.

PS E:\Hyper-V> wsl -d Redis72

-- redis 서비스 상태확인 
[root@RT-PC Hyper-V]# systemctl status redis
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Sat 2023-12-09 12:21:56 KST; 53s ago
 Main PID: 49 (redis-server)
   Status: "Ready to accept connections"
    Tasks: 5 (limit: 26213)
   Memory: 11.8M
   CGroup: /system.slice/redis.service
           └─49 /usr/bin/redis-server 127.0.0.1:6379

Dec 09 12:21:56 RT-PC systemd[1]: Starting Redis persistent key-value database...
Dec 09 12:21:56 RT-PC systemd[1]: Started Redis persistent key-value database.

-- redis 접속 
[root@RT-PC Hyper-V]# redis-cli
127.0.0.1:6379>

'Redis' 카테고리의 다른 글

클러스터 구성  (0) 2024.12.01
복제 구성, sentinel  (0) 2024.11.27
Redis 관리  (0) 2024.11.27

+ Recent posts