Print
카테고리: [ NoSQL ]
조회수: 39413

redis_m / redis_s 두 대의 redis 서버를 준비한 후 replication 설정한 내용입니다.

master 설정 변경

vi redis.conf

bind 0.0.0.0
requirepass test123
masterauth test123

slave 설정 변경

vi redis.conf

bind 0.0.0.0
replicaof 172.17.0.3 6379
requirepass test123
masterauth test123

replication 관련 설정

127.0.0.1:6001> info replication
# Replication
role:slave
master_host:172.17.0.3
master_port:6001
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:3329
master_link_down_since_seconds:5
127.0.0.1:6001> set repl_test "test"
(error) NOREPLICAS Not enough good replicas to write.
127.0.0.1:6001> info replication
# Replication
role:master
connected_slaves:1
min_slaves_good_slaves:1   <======
slave0:ip=172.17.0.4,port=6001,state=online,offset=357,lag=0

replication 확인

39:M 30 Nov 2019 04:29:03.487 * Replica 172.17.0.4:6001 asks for synchronization
39:M 30 Nov 2019 04:29:03.487 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for 'b72ca0f0f59fb399aed279a8adc78b38f266d7e3', my replication IDs are 'e4067cd14f8d810f685f5630f4f66bd1d61051d2' and '0000000000000000000000000000000000000000')
39:M 30 Nov 2019 04:29:03.487 * Starting BGSAVE for SYNC with target: disk
39:M 30 Nov 2019 04:29:03.488 * Background saving started by pid 46
46:C 30 Nov 2019 04:29:03.494 * DB saved on disk
46:C 30 Nov 2019 04:29:03.495 * RDB: 0 MB of memory used by copy-on-write
39:M 30 Nov 2019 04:29:03.586 * Background saving terminated with success
39:M 30 Nov 2019 04:29:03.586 * Synchronization with replica 172.17.0.4:6001 succeeded
38:S 24 Nov 2019 07:58:49.979 # Server initialized
38:S 24 Nov 2019 07:58:49.979 * DB loaded from disk: 0.000 seconds
38:S 24 Nov 2019 07:58:49.979 * Ready to accept connections
38:S 24 Nov 2019 07:58:49.979 * Connecting to MASTER 172.17.0.3:6001
38:S 24 Nov 2019 07:58:49.980 * MASTER <-> REPLICA sync started
38:S 24 Nov 2019 07:58:49.980 * Non blocking connect for SYNC fired the event.
38:S 24 Nov 2019 07:58:49.980 * Master replied to PING, replication can continue...
38:S 24 Nov 2019 07:58:49.982 * Partial resynchronization not possible (no cached master)
38:S 24 Nov 2019 07:58:49.984 * Full resync from master: 50dd3a815e739404d415f8d4a398896cf3c15d29:0
38:S 24 Nov 2019 07:58:49.999 * MASTER <-> REPLICA sync: receiving 186 bytes from master
38:S 24 Nov 2019 07:58:49.999 * MASTER <-> REPLICA sync: Flushing old data
38:S 24 Nov 2019 07:58:49.999 * MASTER <-> REPLICA sync: Loading DB in memory
38:S 24 Nov 2019 07:58:49.999 * MASTER <-> REPLICA sync: Finished with success
127.0.0.1:6001> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=172.17.0.4,port=6001,state=online,offset=560,lag=1
master_replid:50dd3a815e739404d415f8d4a398896cf3c15d29
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:560
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:560

127.0.0.1:6001> set replication_test "ok"
OK
127.0.0.1:6001> info replication
# Replication
role:slave
master_host:172.17.0.3
master_port:6001
master_link_status:up
master_last_io_seconds_ago:7
master_sync_in_progress:0
slave_repl_offset:252
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:50dd3a815e739404d415f8d4a398896cf3c15d29
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:252
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:252

127.0.0.1:6001> set replication_test "hi"
(error) READONLY You can't write against a read only replica.
127.0.0.1:6001> get replication_test
"ok"