CentOS Stream 9
Sponsored Link

Valkey : Configure Replication2024/12/04

 

Configure Valkey Replication. This configuration is general Primary-Replica settings.

[1] Change Settings on Primary Host.
[root@dlp ~]#
vi /etc/valkey/valkey.conf
# line 89 : change to own IP address or [0.0.0.0]

bind
0.0.0.0 -::
# line 308 : change (run as daemon)

daemonize
yes
# line 834 : add follows if need
# min-replicas-to-write : if number of Replica Hosts are online, Primary Host accepts write requests
# min-replicas-max-lag : decision time(sec) for online if Replica Hosts return answer within specified time

min-replicas-to-write 1
min-replicas-max-lag 10
# line 1082 : authentication password

requirepass password
[root@dlp ~]#
systemctl restart valkey
[2] Change Settings on Replica Host.
[root@node01 ~]#
vi /etc/valkey/valkey.conf
# line 88 : change to own IP address or [0.0.0.0]

bind
0.0.0.0 -::
# line 308 : change (run as daemon)

daemonize
yes
# line 553 : add Primary Host IP address and port

replicaof 10.0.0.30 6379
# line 571 : add authentication password set on Primary Host

primaryauth password
# line 602 : verify parameter (set Replica Hosts read-only)

replica-read-only yes
[root@node01 ~]#
systemctl restart valkey
[3] On all Nodes, if Firewalld is running, allow service.
[root@dlp ~]#
firewall-cmd --add-service=redis

success
[root@dlp ~]#
firewall-cmd --runtime-to-permanent

success
[4] Verify statistics on Replica Hosts, then it's OK if [master_link_status:up] is shown.
[root@node01 ~]#
valkey-cli

127.0.0.1:6379> auth password 
OK

# show statistics
127.0.0.1:6379> info Replication 
# Replication
role:slave
master_host:10.0.0.30
master_port:6379
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_read_repl_offset:188
slave_repl_offset:188
replicas_repl_buffer_size:0
replicas_repl_buffer_peak:0
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
replicas_waiting_psync:0
master_failover_state:no-failover
master_replid:a49e6217c98bb5470e0a68fd85c019e83a53f82d
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:188
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:10485760
repl_backlog_first_byte_offset:105
repl_backlog_histlen:84

# verify to get keys set on Primary Host
127.0.0.1:6379> get key_on_master 
"value_on_master"
Matched Content