Skip to content

qyqyardy/dragonfly-ha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DragonflyDB HA Cluster

Production-ready DragonflyDB dengan automatic failover.


📋 Quick Info

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)

🚀 Connect

redis-cli -h 192.168.69.100 -p 6379 -a DragonflySecure2024!

📊 Check Status

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
done

Cek 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

🔄 Restart Services

# On each VM
cd ~/dragonfly-ha
docker-compose restart

cd ~/dragonfly-ha/keepalived
docker-compose restart

🧪 Test Failover

# 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"

📝 View Logs

docker logs dragonfly      # DragonflyDB logs
docker logs sentinel       # Sentinel logs
docker logs keepalived     # Keepalived logs

🔧 Troubleshooting

Split-Brain (Semua jadi master)

# 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

VIP Ga Pindah

# Test health check
docker exec keepalived /usr/local/bin/check_dragonfly.sh
echo $?  # 0=master, 1=replica

# Restart Keepalived
docker restart keepalived

Replication Error

# 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

📂 Files Location

~/dragonfly-ha/
├── docker-compose.yml
├── sentinel.conf
├── scripts/
│   ├── notify.sh
│   └── reconfig.sh
└── keepalived/
    ├── docker-compose.yml
    ├── check_dragonfly.sh
    └── notify_telegram.sh

💡 How It Works

  1. Normal: VM1 master dengan VIP, VM2+VM3 replica
  2. Failover: Sentinel auto-promote VM2/VM3 jadi master
  3. VIP Move: Keepalived auto-pindahin VIP ke master baru
  4. Recovery: VM1 balik jadi replica (bukan master)

⚠️ Important

  • 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

📞 Quick Commands

# 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 masters

Made with ❤️ by Mang Iki

About

DragonflyDB HA

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors