feat: initial project setup
This commit is contained in:
187
docs/setup/02-vps.md
Normal file
187
docs/setup/02-vps.md
Normal file
@@ -0,0 +1,187 @@
|
||||
# Setup 02 — VPS
|
||||
|
||||
## 1. Contratar el VPS
|
||||
|
||||
**Recomendado:** Hetzner CX22 (~5€/mes)
|
||||
- 2 vCPU, 4 GB RAM, 40 GB SSD
|
||||
- Suficiente para: web estática + OpenWebUI + 9 bots Docker
|
||||
|
||||
**Alternativas:**
|
||||
- DigitalOcean Droplet 2GB (~12$/mes)
|
||||
- Linode Nanode 2GB (~12$/mes)
|
||||
- Oracle Cloud Free Tier (gratuito, 4 vCPU ARM, 24 GB RAM)
|
||||
|
||||
**Durante la creación:**
|
||||
- OS: Ubuntu 24.04 LTS
|
||||
- Añade tu clave SSH pública para acceder sin contraseña
|
||||
- Anota la IP pública del VPS
|
||||
|
||||
## 2. Acceder al VPS
|
||||
|
||||
```bash
|
||||
ssh root@<IP_DEL_VPS>
|
||||
```
|
||||
|
||||
## 3. Actualizar el sistema
|
||||
|
||||
```bash
|
||||
apt-get update && apt-get upgrade -y
|
||||
apt-get install -y curl wget git ufw fail2ban
|
||||
```
|
||||
|
||||
## 4. Configurar el firewall (UFW)
|
||||
|
||||
```bash
|
||||
ufw default deny incoming
|
||||
ufw default allow outgoing
|
||||
ufw allow ssh
|
||||
ufw allow 80/tcp
|
||||
ufw allow 443/tcp
|
||||
ufw enable
|
||||
```
|
||||
|
||||
## 5. Crear el usuario `deploy`
|
||||
|
||||
El usuario `deploy` es el que GitHub Actions usará para subir la web.
|
||||
|
||||
```bash
|
||||
# Crear usuario
|
||||
useradd -m -s /bin/bash deploy
|
||||
mkdir -p /home/deploy/.ssh
|
||||
chmod 700 /home/deploy/.ssh
|
||||
|
||||
# Generar keypair para GitHub Actions
|
||||
ssh-keygen -t ed25519 -f /home/deploy/.ssh/github_actions -N "" -C "github-actions@carlospalanca.es"
|
||||
|
||||
# Autorizar la clave pública en el VPS
|
||||
cat /home/deploy/.ssh/github_actions.pub >> /home/deploy/.ssh/authorized_keys
|
||||
chmod 600 /home/deploy/.ssh/authorized_keys
|
||||
chown -R deploy:deploy /home/deploy/.ssh
|
||||
|
||||
# Ver la clave privada (cópiala como GitHub Secret VPS_SSH_PRIVATE_KEY)
|
||||
cat /home/deploy/.ssh/github_actions
|
||||
```
|
||||
|
||||
> **IMPORTANTE:** Copia el output del último comando completo (incluyendo `-----BEGIN OPENSSH PRIVATE KEY-----` y `-----END OPENSSH PRIVATE KEY-----`) y pégalo como el secret `VPS_SSH_PRIVATE_KEY` en GitHub.
|
||||
|
||||
## 6. Crear directorio de la web
|
||||
|
||||
```bash
|
||||
mkdir -p /var/www/carlospalanca.es
|
||||
chown deploy:deploy /var/www/carlospalanca.es
|
||||
```
|
||||
|
||||
## 7. Instalar nginx
|
||||
|
||||
```bash
|
||||
apt-get install -y nginx
|
||||
systemctl enable nginx
|
||||
systemctl start nginx
|
||||
```
|
||||
|
||||
## 8. Instalar Docker y Docker Compose
|
||||
|
||||
```bash
|
||||
# Instalar Docker
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
|
||||
# Añadir el usuario root y deploy al grupo docker
|
||||
usermod -aG docker root
|
||||
usermod -aG docker deploy
|
||||
|
||||
# Verificar
|
||||
docker --version
|
||||
docker compose version
|
||||
```
|
||||
|
||||
## 9. Instalar Certbot (SSL)
|
||||
|
||||
```bash
|
||||
apt-get install -y certbot python3-certbot-nginx
|
||||
```
|
||||
|
||||
## 10. Configurar DNS
|
||||
|
||||
En tu proveedor de DNS (Cloudflare, Namecheap, etc.), añade estos registros:
|
||||
|
||||
| Tipo | Nombre | Valor |
|
||||
|------|--------|-------|
|
||||
| A | `carlospalanca.es` | `<IP_DEL_VPS>` |
|
||||
| A | `www.carlospalanca.es` | `<IP_DEL_VPS>` |
|
||||
| A | `ai.carlospalanca.es` | `<IP_DEL_VPS>` |
|
||||
|
||||
> Los DNS pueden tardar hasta 24h en propagarse. Verifica con: `ping carlospalanca.es`
|
||||
|
||||
## 11. Configurar nginx
|
||||
|
||||
```bash
|
||||
# Copiar la config (desde tu máquina local)
|
||||
scp vps/nginx/carlospalanca.conf root@<IP_DEL_VPS>:/etc/nginx/sites-available/carlospalanca.es
|
||||
|
||||
# En el VPS:
|
||||
ln -sf /etc/nginx/sites-available/carlospalanca.es /etc/nginx/sites-enabled/
|
||||
# Eliminar la config por defecto
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
# Verificar sintaxis
|
||||
nginx -t
|
||||
|
||||
# Recargar
|
||||
systemctl reload nginx
|
||||
```
|
||||
|
||||
## 12. Obtener certificados SSL
|
||||
|
||||
> Espera a que el DNS haya propagado antes de este paso.
|
||||
|
||||
```bash
|
||||
certbot --nginx \
|
||||
-d carlospalanca.es \
|
||||
-d www.carlospalanca.es \
|
||||
-d ai.carlospalanca.es \
|
||||
--agree-tos \
|
||||
--email tu@email.com
|
||||
```
|
||||
|
||||
Certbot actualizará automáticamente la config de nginx con los certificados y configurará la renovación automática.
|
||||
|
||||
## 13. Verificar
|
||||
|
||||
```bash
|
||||
# Comprobar que nginx está activo
|
||||
systemctl status nginx
|
||||
|
||||
# Comprobar que el SSL funciona
|
||||
curl -I https://carlospalanca.es
|
||||
|
||||
# Ver los logs de nginx si hay error
|
||||
tail -f /var/log/nginx/error.log
|
||||
```
|
||||
|
||||
## 14. Permitir a `deploy` recargar nginx sin contraseña
|
||||
|
||||
El workflow de deploy ejecuta `sudo systemctl reload nginx`. Necesitas configurar sudoers para esto:
|
||||
|
||||
```bash
|
||||
echo "deploy ALL=(ALL) NOPASSWD: /bin/systemctl reload nginx, /usr/sbin/nginx" \
|
||||
>> /etc/sudoers.d/deploy-nginx
|
||||
chmod 440 /etc/sudoers.d/deploy-nginx
|
||||
```
|
||||
|
||||
## Checklist
|
||||
|
||||
- [ ] VPS contratado (Ubuntu 24.04)
|
||||
- [ ] Acceso SSH verificado
|
||||
- [ ] Sistema actualizado
|
||||
- [ ] Firewall UFW configurado (80, 443, 22)
|
||||
- [ ] Usuario `deploy` creado con SSH key
|
||||
- [ ] Clave privada copiada como GitHub Secret
|
||||
- [ ] Directorio `/var/www/carlospalanca.es/` creado
|
||||
- [ ] nginx instalado
|
||||
- [ ] Docker + Docker Compose instalados
|
||||
- [ ] Certbot instalado
|
||||
- [ ] DNS apuntando al VPS (carlospalanca.es, www, ai)
|
||||
- [ ] nginx configurado y recargado
|
||||
- [ ] Certificados SSL obtenidos
|
||||
- [ ] `deploy` puede recargar nginx sin contraseña (sudoers)
|
||||
- [ ] `https://carlospalanca.es` responde (aunque esté vacío)
|
||||
Reference in New Issue
Block a user