cuddly-vr-85751
11/25/2025, 1:44 PMtall-airline-16756
11/25/2025, 1:44 PMtall-airline-16756
11/25/2025, 1:44 PMcuddly-vr-85751
11/25/2025, 1:45 PMtall-airline-16756
11/25/2025, 1:45 PMcuddly-vr-85751
11/25/2025, 1:46 PMtall-airline-16756
11/25/2025, 1:46 PMdocker pull livekit/generate
docker run --rm -it -v $PWD:/output livekit/generate
1. When prompted, enter your domain (e.g., livekit.example.com). The command creates an output folder containing:
◦ docker-compose.yaml
◦ livekit.yaml
◦ caddy.yaml
◦ init_script.sh (and/or cloud_init.ubuntu.yaml)
Step 2 — copy files to the VM
1. Copy the generated folder to your VM (adjust username, IP, and path):
scp -r ./livekit-output user@YOUR_VM_IP:/home/user/
1. SSH into the VM:
ssh user@YOUR_VM_IP
cd /home/user/livekit-output
Step 3 — run the init script (recommended)
1. Make the script executable and run it with sudo:
sudo chmod +x init_script.sh
sudo ./init_script.sh
The script will:
• Install Docker & Docker Compose (if missing)
• Create /opt/livekit and place the generated configs
• Start the LiveKit Docker stack (systemd service named livekit-docker)
If your provider supports cloud-init you can instead paste cloud_init.ubuntu.yaml into the provider’s user-data field when creating the VM — the VM will auto-run the same setup.
Step 4 — open required firewall ports Run these on the VM (ufw example):
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 7881/tcp
sudo ufw allow 3478/udp
sudo ufw allow 50000:60000/udp
sudo ufw enable
Step 5 — verify DNS and TLS
1. Ensure your DNS A record points to the VM IP.
2. Wait a few minutes while Caddy obtains certificates.
3. Test:
curl -v https://livekit.example.com
You should get a response from Caddy/LiveKit (replace hostname).
Step 6 — where credentials live
• The generated livekit.yaml contains keys: api_key and api_secret used to mint tokens. They’ll be placed into the Docker environment by the generated compose files. Keep api_secret safe.
• Service URL for clients: wss://livekit.example.com (or https:// for REST calls).
Step 7 — useful commands on the VM
• Check service status:
sudo systemctl status livekit-docker
• View Docker containers:
docker-compose -f /opt/livekit/docker-compose.yaml ps
• View LiveKit logs:
docker logs -f livekit
(container name may vary; docker ps to find exact name)
Step 8 — test a client connection
• Generate a token on your backend using `api_key`/`api_secret` (the generator output includes example code).
• Use the Web SDK with wss://livekit.example.com to connect to a room and publish media.
Troubleshooting quick tips
• If TLS fails, ensure ports 80 and 443 are reachable from the internet and DNS is correct.
• If WebRTC connectivity is poor, confirm UDP range 50000–60000 and 3478/UDP are open and not blocked by cloud provider.
• If containers don’t start, check /opt/livekit for config files and docker-compose output.
If you want, I can:
• Provide the exact contents of the typical generated docker-compose.yaml and livekit.yaml (replace placeholders with your domain and secrets).
• Walk through generating tokens with sample code for your backend language (Node/Python/Go).
Which would you like next?cuddly-vr-85751
11/25/2025, 1:47 PMtall-airline-16756
11/25/2025, 1:48 PMlivekit.example.com and YOUR_VM_IP with your domain and VM IP.
1) Prepare DNS
• Create an A record: livekit.example.com → YOUR_VM_IP
2) SSH to the VM
ssh user@YOUR_VM_IP
sudo -i
3) Update system and install prerequisites
apt update && apt upgrade -y
apt install -y ca-certificates curl gnupg lsb-release git
4) Install Docker Engine
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
5) Enable Docker
systemctl enable --now docker
6) Install Docker Compose v2 (if not provided by package)
curl -SL "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
(If docker compose works already, you can skip this step.)
7) Create LiveKit deploy folder
mkdir -p /opt/livekit
cd /opt/livekit
8) Generate LiveKit config locally (recommended) — run this on your local machine, not the VM:
docker pull livekit/generate
docker run --rm -it -v $PWD:/output livekit/generate
When prompted, enter your domain livekit.example.com. This creates docker-compose.yaml, livekit.yaml, caddy.yaml, and init_script.sh in your current folder.
If you prefer to create files directly on the VM, you can copy the generated files to /opt/livekit (next step).
9) Copy generated files to VM (from local machine)
scp -r ./livekit-output/* user@YOUR_VM_IP:/opt/livekit/
ssh user@YOUR_VM_IP
cd /opt/livekit
10) Or use a prepared minimal set (if you want me to paste exact file contents, I can). The generated docker-compose.yaml will run LiveKit + Caddy. Ensure livekit.yaml contains your `api_key`/`api_secret`.
11) Run the provided init script (or start services manually)
chmod +x /opt/livekit/init_script.sh
sudo /opt/livekit/init_script.sh
This installs docker components (if missing), writes configs to /opt/livekit, and starts the livekit-docker service.
If you prefer manual start:
cd /opt/livekit
docker compose up -d
12) Open firewall ports (ufw example)
apt install -y ufw
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 7881/tcp
ufw allow 3478/udp
ufw allow 50000:60000/udp
ufw --force enable
13) Verify
• Wait a few minutes for Caddy to obtain TLS.
• Test:
curl -v https://livekit.example.com
• Check services:
systemctl status livekit-docker
docker compose ps
docker logs -f livekit
14) Client connection info
• WebSocket URL: wss://livekit.example.com
• REST URL: https://livekit.example.com
• Use the api_key and api_secret from livekit.yaml to mint tokens on your backend.
If you want, I can now:
• Paste the typical contents of docker-compose.yaml, livekit.yaml, and caddy.yaml with placeholders you replace, or
• Provide a ready-to-run init_script.sh you can paste and run on the VM.
Which do you prefer?cuddly-vr-85751
11/25/2025, 3:01 PMtall-airline-16756
11/25/2025, 3:02 PMlivekit.yaml and caddy.yaml with the correct ports and domain, or
• Show a minimal TURN config snippet you can paste into /opt/livekit/livekit.yaml.
Which option do you prefer?
Sources: Deploying LiveKit | LiveKit docs | Ports and firewall | LiveKit docs | Connecting to LiveKit | LiveKit docs | Deploy to a VM | LiveKit docscuddly-vr-85751
11/25/2025, 3:10 PMtall-airline-16756
11/25/2025, 3:10 PMssh user@YOUR_VM_IP
sudo -i
Step B — Update system and install prerequisites
apt update && apt upgrade -y
apt install -y ca-certificates curl gnupg lsb-release git ufw
Step C — Install Docker Engine and Docker Compose
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable --now docker
# Install standalone docker-compose if needed
if ! command -v docker-compose >/dev/null 2>&1; then
curl -SL "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
Step D — Create deploy folder and download LiveKit generator (optional local generate) You can generate config locally (recommended) or create files directly on VM. The generator tool runs in Docker locally and creates correctly configured files. If you prefer to generate on your workstation, run the docker commands there and copy files to /opt/livekit. If you want to do everything on the VM, continue below to create sample files.
Create folder:
mkdir -p /opt/livekit
cd /opt/livekit
Step E — Create production configs (paste the following files, replacing placeholders) 1) docker-compose.yaml
version: "3.8"
services:
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- livekit_net
livekit:
image: livekit/livekit-server:latest
restart: unless-stopped
environment:
- LIVEKIT_CONFIG=/livekit/livekit.yaml
volumes:
- ./livekit.yaml:/livekit/livekit.yaml:ro
networks:
- livekit_net
ports:
- "7881:7881" # optional public TCP port for WebRTC if needed
volumes:
caddy_data:
caddy_config:
networks:
livekit_net:
driver: bridge
2) caddy/Caddyfile
# Replace livekit.example.com and turn.livekit.example.com
livekit.example.com {
reverse_proxy /ws*/* 127.0.0.1:7881
reverse_proxy /* 127.0.0.1:7880
log {
output file /data/caddy/access.log
}
}
# If you want a dedicated TURN domain for TLS-on-443 TURN
turn.livekit.example.com {
reverse_proxy 127.0.0.1:5349
}
3) livekit.yaml Replace API_KEY and API_SECRET with strong values (random). Use your domain names.
server:
rtc_port: 7881
http_port: 7880
name: livekit-server
keys:
- key: "API_KEY"
secret: "API_SECRET"
turn:
enabled: true
# Use TLS TURN on 443 if you want TURN over TLS reachable on 443.
# If using dedicated turn subdomain and Caddy fronting, set tls_port to 5349 or 443.
tls_port: 5349
domain: turn.livekit.example.com
# caddy will handle TLS, so cert paths are not needed when using Caddy
# For embedded certs (optional), set cert_file/key_file paths here.
udp_port: 3478
# UDP relay port range for media
relay_udp_min_port: 50000
relay_udp_max_port: 60000
log:
level: info
Step F — Ensure permissions and run Docker Compose
chown -R root:root /opt/livekit
cd /opt/livekit
docker compose up -d
Step G — Open firewall ports
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 7881/tcp
ufw allow 3478/udp
ufw allow 50000:60000/udp
ufw --force enable
Step H — Wait for TLS and verify
• Wait a few minutes for Caddy to obtain TLS certificates for livekit.example.com (and turn.livekit.example.com if created).
• Test:
curl -v https://livekit.example.com
• Check containers:
docker ps
docker logs -f $(docker ps --filter "ancestor=livekit/livekit-server" --format "{{.Names}}")
• Check Caddy logs in /var/lib/docker/volumes/<compose_project>_caddy_data/_data or via docker logs for the caddy container.
Step I — Token generation and client connection
• Use API_KEY and API_SECRET from livekit.yaml to mint join tokens in your backend. Client connect URL: wss://livekit.example.com (signaling over WebSocket).
• REST API base: https://livekit.example.com
TURN notes (important)
• TURN relays media when direct connections fail. For best coverage in restrictive networks:
◦ Use TURN over TLS on port 443 (set tls_port: 443 and ensure Caddy or your LB routes 443 to the TURN endpoint).
◦ Open UDP range 50000–60000 and 3478/UDP.
◦ If using the embedded TURN with Caddy fronting, ensure the turn domain points to your VM and Caddy reverse-proxies TCP/TLS to the LiveKit TURN listener.
If you want me to:
• Generate secure random API_KEY and API_SECRET and produce ready-to-paste config files personalized to your domain, or
• Provide an init_script.sh that automates all of the above so you can run one command on a fresh VM,
tell me which and I will produce it.cuddly-vr-85751
11/25/2025, 4:01 PMtall-airline-16756
11/25/2025, 4:01 PM# as your normal user:
scp init_setup.sh user@YOUR_VM_IP:/home/user/
ssh user@YOUR_VM_IP
sudo bash /home/user/init_setup.sh
3) init_setup.sh (run as root; replace placeholders before running or edit /opt/livekit/* after)
#!/usr/bin/env bash
set -e
# --- Edit these values before running or after in /opt/livekit/livekit.yaml ---
YOUR_DOMAIN="livekit.example.com" # <- replace with your domain
TURN_DOMAIN="turn.livekit.example.com" # <- replace or set same as YOUR_DOMAIN
API_KEY="API_KEY" # <- replace with a strong key
API_SECRET="API_SECRET" # <- replace with a strong secret
# ---------------------------------------------------------------------------
# Update and install prerequisites
apt update && apt upgrade -y
apt install -y ca-certificates curl gnupg lsb-release git ufw
# Install Docker
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable --now docker
# Install docker-compose binary if docker compose subcommand not available
if ! docker compose version >/dev/null 2>&1; then
curl -SL "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
# Create deploy folder
mkdir -p /opt/livekit
cd /opt/livekit
# Write docker-compose.yaml
cat > /opt/livekit/docker-compose.yaml <<'EOF'
version: "3.8"
services:
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- livekit_net
livekit:
image: livekit/livekit-server:latest
restart: unless-stopped
environment:
- LIVEKIT_CONFIG=/livekit/livekit.yaml
volumes:
- ./livekit.yaml:/livekit/livekit.yaml:ro
networks:
- livekit_net
ports:
- "7881:7881"
volumes:
caddy_data:
caddy_config:
networks:
livekit_net:
driver: bridge
EOF
# Write Caddyfile
cat > /opt/livekit/Caddyfile <<'EOF'
# Main LiveKit signaling & REST
YOUR_DOMAIN {
reverse_proxy /ws*/* 127.0.0.1:7881
reverse_proxy /* 127.0.0.1:7880
log {
output file /data/caddy/access.log
}
}
# TURN domain (optional). Caddy will obtain TLS and proxy to LiveKit TURN TLS endpoint.
TURN_DOMAIN {
reverse_proxy 127.0.0.1:5349
}
EOF
# Write livekit.yaml
cat > /opt/livekit/livekit.yaml <<'EOF'
server:
rtc_port: 7881
http_port: 7880
name: livekit-server
keys:
- key: "API_KEY"
secret: "API_SECRET"
turn:
enabled: true
# TLS port for TURN. If you want TURN over TLS on 443, set tls_port: 443 and ensure Caddy/LB routes correctly.
tls_port: 5349
domain: TURN_DOMAIN
udp_port: 3478
relay_udp_min_port: 50000
relay_udp_max_port: 60000
log:
level: info
EOF
# Replace placeholders in files with actual values
sed -i "s|YOUR_DOMAIN|${YOUR_DOMAIN}|g" /opt/livekit/Caddyfile
sed -i "s|TURN_DOMAIN|${TURN_DOMAIN}|g" /opt/livekit/Caddyfile
sed -i "s|API_KEY|${API_KEY}|g" /opt/livekit/livekit.yaml
sed -i "s|API_SECRET|${API_SECRET}|g" /opt/livekit/livekit.yaml
sed -i "s|TURN_DOMAIN|${TURN_DOMAIN}|g" /opt/livekit/livekit.yaml
# Set permissions
chown -R root:root /opt/livekit
# Open firewall ports (ufw)
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 7881/tcp
ufw allow 3478/udp
ufw allow 50000:60000/udp
ufw --force enable
# Start services
cd /opt/livekit
docker compose up -d
echo "Deployment started. Replace placeholders in /opt/livekit/* if needed."
echo "Check 'docker ps' and 'docker logs <container>' for status. Client URL: wss://${YOUR_DOMAIN}"
4) After the script runs
• Wait a few minutes for Caddy to obtain TLS certs for YOUR_DOMAIN and TURN_DOMAIN.
• Verify:
◦ curl -v https://YOUR_DOMAIN
◦ docker ps
◦ docker logs -f <caddy-container-name>
◦ docker logs -f <livekit-container-name>
5) Notes & recommended edits
• Replace API_KEY and API_SECRET with generated secure values (example: use openssl rand -hex 16).
• If you want TURN TLS on port 443 (recommended for very restrictive networks), set tls_port: 443 in livekit.yaml and ensure the TURN_DOMAIN points to the VM and Caddy proxies 443 traffic to 5349 or route accordingly. The provided Caddyfile proxies TURN_DOMAIN to 127.0.0.1:5349.
• If you prefer to generate config locally with the LiveKit generator, you can instead run the livekit/generate Docker image on your workstation and copy files into /opt/livekit.
• Keep API_SECRET safe; use it only on your backend to mint tokens.
If you want, I can:
• Generate secure API_KEY/API_SECRET values for you and paste an updated init script, or
• Produce a version that sets TURN TLS to 443 now.
Which would you like?cuddly-vr-85751
11/25/2025, 4:52 PMtall-airline-16756
11/25/2025, 4:52 PMsudo systemctl status livekit-docker.service
2) journalctl logs for the unit
sudo journalctl -xeu livekit-docker.service --no-pager
If you prefer, paste both outputs together. After I see the logs I’ll point out the error and give the exact fix (likely a config/permission/docker issue) and commands to resolve it.