Files
Hotwives/SETUP.md

288 lines
4.6 KiB
Markdown
Raw Normal View History

# Guia de Instalação - HotWives Platform
## Requisitos
- Ubuntu/Debian Linux
- Node.js 18+
- PostgreSQL 14+
- Nginx
- Certificado SSL (Certbot/Let's Encrypt)
## Instalação Automática
```bash
cd /var/www/hotwives
sudo chmod +x install.sh
sudo ./install.sh
```
## Instalação Manual
### 1. Instalar Dependências do Sistema
```bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl git nginx postgresql postgresql-contrib
# Instalar Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo bash -
sudo apt install -y nodejs
```
### 2. Configurar PostgreSQL
```bash
sudo -u postgres psql
# No console do PostgreSQL:
CREATE DATABASE hotwives;
CREATE USER hotwives WITH ENCRYPTED PASSWORD 'sua_senha_forte';
GRANT ALL PRIVILEGES ON DATABASE hotwives TO hotwives;
\q
```
### 3. Configurar o Projeto
```bash
cd /var/www/hotwives
# Instalar dependências raiz
npm install
# Backend
cd backend
npm install
cp .env.example .env
# Edite o .env com suas configurações
nano .env
# Gerar Prisma Client e executar migrações
npx prisma generate
npx prisma migrate deploy
# Build
npm run build
# Frontend
cd ../frontend
npm install
npm run build
```
### 4. Configurar Nginx
```bash
sudo cp /var/www/hotwives/nginx.conf /etc/nginx/sites-available/hotwives
sudo ln -s /etc/nginx/sites-available/hotwives /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
# Testar configuração
sudo nginx -t
# Reiniciar Nginx
sudo systemctl restart nginx
```
### 5. Configurar SSL com Let's Encrypt
```bash
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d hotwives.com.br -d www.hotwives.com.br
```
### 6. Instalar PM2 para Gerenciamento de Processos
```bash
sudo npm install -g pm2
# Iniciar aplicações
cd /var/www/hotwives
pm2 start ecosystem.config.js
# Salvar configuração
pm2 save
# Configurar PM2 para iniciar no boot
pm2 startup
```
## Configuração do .env (Backend)
```env
# Server
PORT=3001
NODE_ENV=production
FRONTEND_URL=https://hotwives.com.br
# Database
DATABASE_URL="postgresql://hotwives:sua_senha@localhost:5432/hotwives?schema=public"
# JWT
JWT_SECRET=gere_uma_chave_secreta_aleatoria_forte
JWT_EXPIRES_IN=7d
# Email (Gmail como exemplo)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=seu_email@gmail.com
SMTP_PASS=sua_senha_de_app
EMAIL_FROM=noreply@hotwives.com.br
# Upload
MAX_FILE_SIZE=10485760
```
## Comandos Úteis
### PM2
```bash
# Ver status
pm2 status
# Ver logs
pm2 logs
# Reiniciar
pm2 restart all
# Parar
pm2 stop all
# Recarregar (zero downtime)
pm2 reload all
```
### Prisma
```bash
cd /var/www/hotwives/backend
# Gerar client
npx prisma generate
# Executar migrações
npx prisma migrate deploy
# Abrir Prisma Studio (desenvolvimento)
npx prisma studio
```
### Nginx
```bash
# Testar configuração
sudo nginx -t
# Reiniciar
sudo systemctl restart nginx
# Ver logs
sudo tail -f /var/log/nginx/hotwives-error.log
```
## Backup do Banco de Dados
```bash
# Criar backup
pg_dump -U hotwives hotwives > backup_$(date +%Y%m%d_%H%M%S).sql
# Restaurar backup
psql -U hotwives hotwives < backup_20250101_120000.sql
```
## Atualização
```bash
cd /var/www/hotwives
# Atualizar código (Git)
git pull origin main
# Backend
cd backend
npm install
npx prisma migrate deploy
npm run build
# Frontend
cd ../frontend
npm install
npm run build
# Reiniciar aplicações
pm2 reload all
```
## Monitoramento
```bash
# Ver uso de recursos
pm2 monit
# Ver logs em tempo real
pm2 logs
# Métricas do sistema
pm2 list
```
## Troubleshooting
### Backend não inicia
```bash
cd /var/www/hotwives/backend
npm run build
pm2 restart hotwives-backend
pm2 logs hotwives-backend --lines 100
```
### Erro de conexão com banco de dados
```bash
# Verificar se PostgreSQL está rodando
sudo systemctl status postgresql
# Testar conexão
psql -U hotwives -d hotwives -h localhost
```
### Erro 502 Bad Gateway
```bash
# Verificar se as aplicações estão rodando
pm2 status
# Verificar logs do Nginx
sudo tail -f /var/log/nginx/hotwives-error.log
```
## Segurança
1. **Firewall**: Configure UFW para permitir apenas portas necessárias
```bash
sudo ufw allow 22 # SSH
sudo ufw allow 80 # HTTP
sudo ufw allow 443 # HTTPS
sudo ufw enable
```
2. **Atualizações**: Mantenha o sistema sempre atualizado
```bash
sudo apt update && sudo apt upgrade -y
```
3. **Backups**: Configure backups automáticos do banco de dados
4. **Senhas**: Use senhas fortes para PostgreSQL e JWT_SECRET
5. **SSL**: Renove certificados SSL automaticamente com Certbot
## Suporte
Para suporte, entre em contato através de:
- Email: suporte@hotwives.com.br
- Repositório: https://meurepositorio.com/sergio.correa/Hotwives.git