153 lines
3.8 KiB
Markdown
153 lines
3.8 KiB
Markdown
# Redis Service for LXC Container
|
|
|
|
This repository contains a production-ready Docker Compose configuration for running a Redis server in an LXC container on Proxmox.
|
|
|
|
## Overview
|
|
|
|
This setup provides:
|
|
- Redis server with password authentication
|
|
- Data persistence using AOF (Append Only File)
|
|
- Automatic container restart
|
|
- Health checks
|
|
- Volume management for data persistence
|
|
|
|
## Prerequisites
|
|
|
|
- LXC container configured for Docker (as described in the Proxmox setup guide)
|
|
- Docker and Docker Compose installed on the LXC container
|
|
- Network connectivity from the container
|
|
|
|
## Configuration
|
|
|
|
The service is configured using environment variables defined in the `.env` file:
|
|
|
|
| Variable | Description | Default |
|
|
|----------|-------------|---------|
|
|
| `REDIS_VERSION` | Redis Docker image version | 7.0.12 |
|
|
| `REDIS_PASSWORD` | Password for Redis authentication | *Must be set* |
|
|
| `REDIS_PORT` | Port mapping for Redis | 6379 |
|
|
| `TIMEZONE` | Container timezone | UTC |
|
|
|
|
## Installation
|
|
|
|
1. Clone this repository to your LXC container:
|
|
```bash
|
|
mkdir -p /opt/redis-service
|
|
cd /opt/redis-service
|
|
# Clone your repository or copy files manually
|
|
```
|
|
|
|
2. Create a proper `.env` file with secure credentials:
|
|
```bash
|
|
cp .env.example .env
|
|
nano .env
|
|
```
|
|
|
|
Make sure to set a strong password for `REDIS_PASSWORD`.
|
|
|
|
3. Start the Redis service:
|
|
```bash
|
|
docker-compose up -d
|
|
```
|
|
|
|
4. Verify that the container is running:
|
|
```bash
|
|
docker-compose ps
|
|
```
|
|
|
|
## Data Persistence
|
|
|
|
Redis data is stored in a Docker volume named `redis-data`. This ensures that your data persists even if the container is restarted or recreated.
|
|
|
|
The Redis server is configured with AOF (Append Only File) persistence using the `--appendonly yes` option, which provides better durability for your data.
|
|
|
|
## Connecting to Redis
|
|
|
|
To connect to your Redis server from another container or service:
|
|
|
|
```
|
|
redis-cli -h <container-ip> -p 6379 -a <your-redis-password>
|
|
```
|
|
|
|
For applications using the Redis server, use the following connection string:
|
|
|
|
```
|
|
redis://:your_redis_password@redis-server:6379/0
|
|
```
|
|
|
|
## Maintenance
|
|
|
|
### Viewing Logs
|
|
|
|
```bash
|
|
docker-compose logs redis
|
|
```
|
|
|
|
### Backing Up Redis Data
|
|
|
|
```bash
|
|
# Create a backup directory
|
|
mkdir -p /opt/redis-backups
|
|
|
|
# Run the backup command
|
|
docker exec redis-server redis-cli -a your_redis_password SAVE
|
|
docker cp redis-server:/data/dump.rdb /opt/redis-backups/redis-backup-$(date +%Y%m%d%H%M%S).rdb
|
|
```
|
|
|
|
### Updating Redis
|
|
|
|
To update the Redis version, modify the `REDIS_VERSION` in your `.env` file and restart the service:
|
|
|
|
```bash
|
|
docker-compose down
|
|
docker-compose up -d
|
|
```
|
|
|
|
## Security Considerations
|
|
|
|
- The Redis server is password-protected
|
|
- Only expose the Redis port if necessary
|
|
- Consider using a firewall to restrict access to the Redis port
|
|
- For production environments, consider implementing additional security measures like network isolation
|
|
|
|
## Performance Test Results
|
|
|
|
The repository includes a Python script (`redis_load_test.py`) for load testing the Redis server with 100 concurrent threads. Below are sample test results:
|
|
|
|
```
|
|
===== TEST SUMMARY =====
|
|
|
|
Operation: CREATE
|
|
Total operations: 10000
|
|
Successful operations: 10000
|
|
Failed operations: 0
|
|
Duration: 3.33 seconds
|
|
Operations per second: 3001.43
|
|
|
|
Operation: UPDATE
|
|
Total operations: 10000
|
|
Successful operations: 10000
|
|
Failed operations: 0
|
|
Duration: 4.15 seconds
|
|
Operations per second: 2408.91
|
|
|
|
Operation: DELETE
|
|
Total operations: 10000
|
|
Successful operations: 10000
|
|
Failed operations: 0
|
|
Duration: 1.29 seconds
|
|
Operations per second: 7771.63
|
|
=========================
|
|
```
|
|
|
|
These results demonstrate the Redis server's performance capabilities:
|
|
- Create operations: ~3,000 ops/sec
|
|
- Update operations: ~2,400 ops/sec
|
|
- Delete operations: ~7,700 ops/sec
|
|
|
|
To run the performance test yourself:
|
|
|
|
```bash
|
|
python redis_load_test.py
|
|
```
|