- Fork the repository
- Clone your fork:
git clone https://github.com/thuongtruong109/reluster.git
- Make changes
- Run tests:
make ha-test
- Submit a pull request
graph LR
subgraph Replica_HA_Sentinel
commander[commander]
ha[ha]
ha-master[ha-master]
ha-slave[ha-slave]
ha-test-failover[ha-test-failover]
ha-bench[ha-bench]
ha-backup[ha-backup]
ha-health[ha-health]
ha-ready[ha-ready]
ha-scan[ha-scan]
ha-cli[ha-cli]
end
subgraph Cluster_Sharding
clt[clt]
clt-init[clt-init]
clt-ready[clt-ready]
clt-monitor[clt-monitor]
clt-scan[clt-scan]
clt-test[clt-test]
clt-bench[clt-bench]
clt-rollback[clt-rollback]
clt-scale[clt-scale]
clt-health[clt-health]
clt-cli[clt-cli]
end
%% Example dependencies (bạn có thể bổ sung thêm nếu muốn)
ha --> ha-master
ha --> ha-slave
ha --> ha-test-failover
ha --> ha-bench
ha --> ha-backup
ha --> ha-health
ha --> ha-ready
ha --> ha-scan
ha --> ha-cli
clt --> clt-init
clt-init --> clt-ready
clt-ready --> clt-monitor
clt-ready --> clt-scan
clt-ready --> clt-test
clt-ready --> clt-bench
clt-ready --> clt-rollback
clt-ready --> clt-scale
clt-ready --> clt-health
clt-ready --> clt-cli
reluster/
├── docker-compose.ha.yml # Sentinel/HA setup (master, replicas, sentinels, commander)
├── docker-compose.cluster.yml # Redis Cluster (6 nodes + RedisInsight)
├── Makefile # Automation commands
├── README.md # Main documentation
├── LICENSE # Apache 2.0 License
├── todo.md # Roadmap / Future enhancements
├── backups/ # Backup storage
│ ├── dump.rdb
│ └── dump_YYYY-MM-DD_HH-MM-SS.rdb
├── commander/
│ └── ha.json # Redis Commander config
├── ha/
│ ├── master.conf # Master Redis config
│ ├── sentinel.conf # Sentinel config
│ └── slave.conf # Replica Redis config
├── cluster/
│ └── node.conf # Cluster node config
├── scripts/
│ ├── ha-backup.sh # Backup & restore script
│ └── ha-health.sh # Health check script
└── tests/
├── ha-failover.sh # Sentinel failover test
├── ha.sh # HA integration test
└── clt.sh # Cluster test
# Start Sentinel/replica/master/commander
docker-compose -f docker-compose.ha.yml up -d# Start 6 Redis nodes + RedisInsight
docker-compose -f docker-compose.cluster.yml up -d
# Create cluster (run once):
# (see Makefile or scripts for cluster creation)- Master:
redis-master(port 6379, password:masterpass) - Replicas:
slave_1(6380),slave_2(6381),slave_3(6382) - Sentinels:
sentinel_1(26379),sentinel_2(26380),sentinel_3(26381) - Redis Commander: http://localhost:8081
docker exec -it redis-master redis-cli -a masterpass
docker exec -it slave_1 redis-cli -a masterpass
docker exec -it sentinel_1 redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster- Nodes:
node-1...node-6(ports 7001-7006) - RedisInsight: http://localhost:8001
# See Makefile or scripts for cluster creationYou can use the provided script to simulate failover:
# On Linux/WSL/Git Bash:
chmod +x tests/ha-failover.sh
./tests/ha-failover.sh
# On PowerShell:
# (Manual steps below)Or run manually:
- Check current master:
docker exec -it sentinel_1 redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster - Stop master:
docker stop redis-master
- Check new master:
docker exec -it sentinel_1 redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster - Check replica role:
docker exec -it slave_1 redis-cli -a masterpass INFO replication | grep role
- Restart old master:
docker start redis-master
If you see errors with config files (especially on Windows), ensure files use LF (not CRLF) endings.
dos2unix ha/sentinel.conf ha/master.conf ha/slave.conf
sed -i 's/\r$//' ha/sentinel.conf ha/master.conf ha/slave.confOr use Notepad++: Edit → EOL Conversion → Unix (LF) → Save.
# Check network
docker network inspect redisnet
# Check container status
docker ps -a --format "table {{.Names}}\t{{.Status}}"
# View logs
docker-compose -f docker-compose.ha.yml logs -f sentinel_1
# Access Redis Commander
start http://localhost:8081
start http://localhost:8001- Extend: Add your own application containers to test integration with Redis.
This project includes several automation scripts to help with management and testing:
Comprehensive health monitoring for the Redis cluster:
# Basic health check
# Full health check with metrics
# Load testing
# Generate health report
./scripts/ha-health.sh --report
Features:
- Container status monitoring
- Redis connectivity tests
- Memory usage tracking
- Automated reporting
### Backup & Restore (`scripts/ha-backup.sh`)
Automated backup and restore functionality:
```bash
./scripts/ha-backup.sh
# Restore from latest backupFeatures:
- Automatic RDB file backup
- Restore verification
- Cleanup of old backups (7+ days)
./tests/ha-failover.sh
Simulates master failure and verifies automatic failover to replica.
### Integration Tests (`tests/ha.sh`)
Comprehensive integration testing:
```bash
# Run full integration test suite
./tests/ha.sh
Tests:
- Service startup and readiness
- Master-slave replication
- Automatic failover
- Data consistency
- Recovery procedures
Test Redis Cluster functionality:
# Run cluster test suite
./tests/clt.shUse the provided Makefile for common operations:
# Format configuration files (fix line endings)
make format
# Start Sentinel/HA cluster
make ha
# Get current master
make ha-master
# Get slave info
make ha-slave
# Run failover test
make ha-test-failover
# Run integration tests
make ha-test
# Run backup
make ha-backup
# Run health checks
make ha-health
# Start Redis Cluster
make clt
# Create cluster
make clt-create
# Check cluster status
make clt-check
# Run cluster tests
make clt-test