redis-service/README.md

112 lines
2.9 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