Managing logging effectively is a crucial skill for any system administrator. This tutorial provides step-by-step instructions for fluentd configuration, along with best practices for production environments.
Prerequisites
- Docker Engine 24.0+ installed
- A registered domain name (for public-facing services)
- Root or sudo access to the server
- Docker Compose v2 installed
Creating the Docker Compose File
If you encounter issues during setup, check the system logs first. Most problems can be diagnosed by examining the output of journalctl or the application-specific log files in /var/log/.
# docker-compose.yml
version: '3.8'
services:
app:
image: logging:latest
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- app_data:/data
environment:
- NODE_ENV=production
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
volumes:
app_data:
Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.
- Keep all software components up to date
- Use strong, unique passwords for all services
- Use SSH keys instead of password authentication
- Enable firewall and allow only necessary ports
- Set up fail2ban for brute force protection
Building the Container Image
It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.
# Multi-stage Dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
Important Notes
Performance benchmarks show that properly tuned logging can handle significantly more concurrent connections than the default configuration. The key improvements come from adjusting worker processes and connection pooling.
Configuring Volumes and Networks
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
# Container management commands
docker compose up -d
docker compose logs -f app
docker compose exec app sh
docker system prune -af --volumes # Caution: removes unused data
Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.
- Profile before optimizing - measure first
- Use connection pooling for database connections
- Implement caching at every appropriate layer
Managing Container Lifecycle
Security should be a primary consideration when configuring logging. Always use strong passwords, keep software updated, and restrict network access to only the necessary ports and IP addresses.
# docker-compose.yml
version: '3.8'
services:
app:
image: logging:latest
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- app_data:/data
environment:
- NODE_ENV=production
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
volumes:
app_data:
The output should show the service running without errors. If you see any warning messages, address them before proceeding to the next step.
Performance Considerations
It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.
Summary
You've successfully configured logging on your VPS. Remember to monitor performance, keep your software updated, and maintain regular backups. If you run into issues, consult the official documentation or open a support ticket for assistance.