Production-ready DragonflyDB dengan automatic failover.
VIP: 192.168.69.100 (connect disini)
Password: DragonflySecure2024!
Nodes:
- VM1: 192.168.69.25 (Master)
- VM2: 192.168.69.26 (Replica)
- VM3: 192.168.69.27 (Replica)
redis-cli -h 192.168.69.100 -p 6379 -a DragonflySecure2024!Lihat semua nodes:
for ip in 192.168.69.25 192.168.69.26 192.168.69.27; do
echo "=== $ip ==="
redis-cli -h $ip -p 6379 -a DragonflySecure2024! --no-auth-warning INFO replication | grep role
doneCek VIP ada dimana:
for ip in 192.168.69.25 192.168.69.26 192.168.69.27; do
ssh sysadmin@$ip "ip addr show | grep 192.168.69.100" && echo "$ip has VIP"
done# On each VM
cd ~/dragonfly-ha
docker-compose restart
cd ~/dragonfly-ha/keepalived
docker-compose restart# 1. Stop master
ssh sysadmin@192.168.69.25 "docker stop dragonfly"
# 2. Wait 30 detik, cek master baru
sleep 30
redis-cli -h 192.168.69.100 -p 6379 -a DragonflySecure2024! --no-auth-warning PING
# 3. Start master lama (akan jadi replica)
ssh sysadmin@192.168.69.25 "docker start dragonfly"docker logs dragonfly # DragonflyDB logs
docker logs sentinel # Sentinel logs
docker logs keepalived # Keepalived logs# Force VM1 jadi master
redis-cli -h 192.168.69.25 -p 6379 -a DragonflySecure2024! --no-auth-warning REPLICAOF NO ONE
redis-cli -h 192.168.69.26 -p 6379 -a DragonflySecure2024! --no-auth-warning REPLICAOF 192.168.69.25 6379
redis-cli -h 192.168.69.27 -p 6379 -a DragonflySecure2024! --no-auth-warning REPLICAOF 192.168.69.25 6379
# Restart semua Sentinel
for ip in 192.168.69.25 192.168.69.26 192.168.69.27; do
ssh sysadmin@$ip "docker restart sentinel"
done
# Restart semua Keepalived
for ip in 192.168.69.25 192.168.69.26 192.168.69.27; do
ssh sysadmin@$ip "docker restart keepalived"
done# Test health check
docker exec keepalived /usr/local/bin/check_dragonfly.sh
echo $? # 0=master, 1=replica
# Restart Keepalived
docker restart keepalived# Cek status replication
redis-cli -h 192.168.69.26 -p 6379 -a DragonflySecure2024! --no-auth-warning INFO replication | grep master_link_status
# Force resync
redis-cli -h 192.168.69.26 -p 6379 -a DragonflySecure2024! --no-auth-warning REPLICAOF 192.168.69.25 6379~/dragonfly-ha/
├── docker-compose.yml
├── sentinel.conf
├── scripts/
│ ├── notify.sh
│ └── reconfig.sh
└── keepalived/
├── docker-compose.yml
├── check_dragonfly.sh
└── notify_telegram.sh
- Normal: VM1 master dengan VIP, VM2+VM3 replica
- Failover: Sentinel auto-promote VM2/VM3 jadi master
- VIP Move: Keepalived auto-pindahin VIP ke master baru
- Recovery: VM1 balik jadi replica (bukan master)
- Selalu connect via VIP (192.168.69.100)
- Failover butuh 5-30 detik
- Old master TIDAK auto jadi master lagi
- Backup otomatis tiap 6 jam di
/var/lib/dragonfly/dump.rdb
# Status cluster
for ip in 192.168.69.25 192.168.69.26 192.168.69.27; do
ROLE=$(redis-cli -h $ip -p 6379 -a DragonflySecure2024! --no-auth-warning INFO replication 2>/dev/null | grep 'role:' | cut -d: -f2 | tr -d '\r\n ')
echo "$ip: $ROLE"
done
# Test VIP
redis-cli -h 192.168.69.100 -p 6379 -a DragonflySecure2024! --no-auth-warning PING
# Sentinel info
redis-cli -h 192.168.69.25 -p 26379 SENTINEL mastersMade with ❤️ by Mang Iki