redis master slave and haproxy

İbrahim Yıldız
1 min readOct 12, 2024

Redis Replikasyon

Redis, verilerin güvenliğini ve erişilebilirliğini artırmak amacıyla replikasyon özelliğini destekler. Replikasyon, bir Redis sunucusunun (master) verilerini başka bir veya daha fazla Redis sunucusuna (slave) kopyalamasını sağlar. Bu özellik, veri kaybını önler, okuma yükünü dengelemeye yardımcı olur ve yüksek erişilebilirlik sağlar.

  1. Master Sunucuda Yapılacaklar:
cp redis.conf redis-slave.conf

bind 127.0.0.1
protected-mode yes

./redis-server /path/to/redis.conf
  1. Slave Sunucuda Yapılacaklar:
vi redis-slave.conf

port 6380
replicaof 127.0.0.1 6379

./redis-server /path/to/redis-slave.conf

2. Master ve Slave Sunucuda Yapılacaklar:

MASTER

redis-cli -h 127.0.0.1 -p 6379

info replication

# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6380,state=online,offset=14,lag=0
master_failover_state:no-failover
...

SLAVE

redis-cli -h 127.0.0.1 -p 6380
info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
slave_read_only:1
...

HAPROXY

brew install haproxy
vi /opt/homebrew/etc/haproxy.cfg
global
log /dev/log local0
maxconn 2000

defaults
log global
option httplog
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms

frontend redis_front
bind *:5000
default_backend redis_back

backend redis_back
balance roundrobin
server master 127.0.0.1:6379 check
server slave 127.0.0.1:6380 check
brew services restart haproxy
ibrahimyildiz@192 src % ./redis-cli -h localhost -p 5000 ping
PONG

--

--

No responses yet