Traefik is a free and open-source modern HTTP reverse proxy and load balancer with automatic service discovery. Traefik is a cloud-native edge router that automatically discovers services and provides dynamic configuration, serving as an alternative to HAProxy, nginx Plus, or AWS Application Load Balancer
1. Prerequisites
2. Supported Operating Systems
This guide supports installation on:
3. Installation
RHEL/CentOS/Rocky Linux/AlmaLinux
# Install EPEL repository if needed
sudo dnf install -y epel-release
# Install Traefik
sudo dnf install -y traefik
# Enable and start service
sudo systemctl enable --now traefik
# Configure firewall
sudo firewall-cmd --permanent --add-port=80/443/tcp
sudo firewall-cmd --reload
# Verify installation
traefik version
Debian/Ubuntu
# Update package index
sudo apt update
# Install Traefik
sudo apt install -y traefik
# Enable and start service
sudo systemctl enable --now traefik
# Configure firewall
sudo ufw allow 80/443
# Verify installation
traefik version
Arch Linux
# Install Traefik
sudo pacman -S traefik
# Enable and start service
sudo systemctl enable --now traefik
# Verify installation
traefik version
Alpine Linux
# Install Traefik
apk add --no-cache traefik
# Enable and start service
rc-update add traefik default
rc-service traefik start
# Verify installation
traefik version
openSUSE/SLES
# Install Traefik
sudo zypper install -y traefik
# Enable and start service
sudo systemctl enable --now traefik
# Configure firewall
sudo firewall-cmd --permanent --add-port=80/443/tcp
sudo firewall-cmd --reload
# Verify installation
traefik version
macOS
# Using Homebrew
brew install traefik
# Start service
brew services start traefik
# Verify installation
traefik version
FreeBSD
# Using pkg
pkg install traefik
# Enable in rc.conf
echo 'traefik_enable="YES"' >> /etc/rc.conf
# Start service
service traefik start
# Verify installation
traefik version
Windows
# Using Chocolatey
choco install traefik
# Or using Scoop
scoop install traefik
# Verify installation
traefik version
Initial Configuration
Basic Configuration
# Create configuration directory
sudo mkdir -p /etc/traefik
# Set up basic configuration
# Configuration details will vary based on your specific needs
# See official documentation for detailed configuration options
# Test configuration
traefik healthcheck
5. Service Management
systemd (RHEL, Debian, Ubuntu, Arch, openSUSE)
# Enable service
sudo systemctl enable traefik
# Start service
sudo systemctl start traefik
# Stop service
sudo systemctl stop traefik
# Restart service
sudo systemctl restart traefik
# Check status
sudo systemctl status traefik
# View logs
sudo journalctl -u traefik -f
OpenRC (Alpine Linux)
# Enable service
rc-update add traefik default
# Start service
rc-service traefik start
# Stop service
rc-service traefik stop
# Restart service
rc-service traefik restart
# Check status
rc-service traefik status
rc.d (FreeBSD)
# Enable in /etc/rc.conf
echo 'traefik_enable="YES"' >> /etc/rc.conf
# Start service
service traefik start
# Stop service
service traefik stop
# Restart service
service traefik restart
# Check status
service traefik status
launchd (macOS)
# Using Homebrew services
brew services start traefik
brew services stop traefik
brew services restart traefik
# Check status
brew services list | grep traefik
Windows Service Manager
# Start service
net start traefik
# Stop service
net stop traefik
# Using PowerShell
Start-Service traefik
Stop-Service traefik
Restart-Service traefik
# Check status
Get-Service traefik
Advanced Configuration
Advanced Traefik Configuration
See the official documentation for advanced configuration options including:
Reverse Proxy Setup
nginx Configuration
upstream traefik_backend {
server 127.0.0.1:80/443;
}
server {
listen 80;
server_name traefik.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name traefik.example.com;
ssl_certificate /etc/ssl/certs/traefik.example.com.crt;
ssl_certificate_key /etc/ssl/private/traefik.example.com.key;
location / {
proxy_pass http://traefik_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Apache Configuration
<VirtualHost *:80>
ServerName traefik.example.com
Redirect permanent / https://traefik.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName traefik.example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/traefik.example.com.crt
SSLCertificateKeyFile /etc/ssl/private/traefik.example.com.key
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:80/443/
ProxyPassReverse / http://127.0.0.1:80/443/
</VirtualHost>
HAProxy Configuration
frontend traefik_frontend
bind *:80
bind *:443 ssl crt /etc/ssl/certs/traefik.pem
redirect scheme https if !{ ssl_fc }
default_backend traefik_backend
backend traefik_backend
balance roundrobin
server traefik1 127.0.0.1:80/443 check
Security Configuration
Security Best Practices
# Set appropriate permissions
sudo chown -R traefik:traefik /etc/traefik
sudo chmod 750 /etc/traefik
# Configure firewall rules
sudo firewall-cmd --permanent --add-port=80/443/tcp
sudo firewall-cmd --reload
# Enable SELinux policies (if applicable)
sudo setsebool -P httpd_can_network_connect on
Database Setup
Not applicable
Performance Optimization
8. Performance Tuning
# System tuning for Traefik
echo 'net.core.somaxconn = 65535' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_max_syn_backlog = 65535' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
# Monitor performance
curl http://localhost:8080/api/rawdata
Monitoring
Monitoring Setup
# Basic monitoring
sudo systemctl status traefik
sudo journalctl -u traefik -f
# Set up health checks
curl -f http://localhost:80/health || exit 1
9. Backup and Restore
Backup Procedures
#!/bin/bash
# Backup script
BACKUP_DIR="/backup/traefik"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"
tar -czf /backup/traefik-$(date +%Y%m%d).tar.gz /etc/traefik
# Restore procedure
# Stop service, restore files, restart service
sudo systemctl stop traefik
# Restore backed up files
sudo systemctl start traefik
6. Troubleshooting
Common Issues
1. Service won't start:
# Check logs
sudo journalctl -u traefik -f
sudo tail -f /var/log/traefik/traefik.log
# Check configuration
traefik healthcheck
# Check permissions
ls -la /etc/traefik
2. Connection issues:
# Check if service is listening
sudo ss -tlnp | grep 80/443
# Test connectivity
telnet localhost 80/443
# Check firewall
sudo firewall-cmd --list-all
3. Performance issues:
# Check resource usage
top -p $(pgrep traefik)
# Check disk I/O
iotop -p $(pgrep traefik)
# Check network connections
ss -an | grep 80/443
Integration Examples
Example Integration
# Docker Compose example
version: '3.8'
services:
traefik:
image: traefik:latest
ports:
- "80:80"
volumes:
- ./config:/etc/traefik
- ./data:/var/lib/traefik
restart: unless-stopped
Maintenance
Update Procedures
# RHEL/CentOS/Rocky/AlmaLinux
sudo dnf update traefik
# Debian/Ubuntu
sudo apt update && sudo apt upgrade traefik
# Arch Linux
sudo pacman -Syu traefik
# Alpine Linux
apk update && apk upgrade traefik
# openSUSE
sudo zypper update traefik
# FreeBSD
pkg update && pkg upgrade traefik
# Always backup before updates
tar -czf /backup/traefik-$(date +%Y%m%d).tar.gz /etc/traefik
# Restart after updates
sudo systemctl restart traefik
Regular Maintenance Tasks
# Log rotation
sudo logrotate -f /etc/logrotate.d/traefik
# Clean old logs
find /var/log/traefik -name "*.log" -mtime +30 -delete
# Check disk usage
du -sh /var/lib/traefik
# Verify configuration
traefik healthcheck
# Test functionality
curl http://localhost:8080/api/rawdata
Additional Resources
---
Note: This guide is part of the HowToMgr collection. Always refer to official documentation for the most up-to-date information.