371 lines
7.3 KiB
Markdown
371 lines
7.3 KiB
Markdown
# 🦷 MANUAL DE INSTALAÇÃO - DENTAL SERVER v2.0
|
|
|
|
## 📋 SUMÁRIO
|
|
1. [Pré-requisitos](#pré-requisitos)
|
|
2. [Upload de Arquivos](#upload-de-arquivos)
|
|
3. [Configuração no VPS](#configuração-no-vps)
|
|
4. [Banco de Dados](#banco-de-dados)
|
|
5. [PM2 e Nginx](#pm2-e-nginx)
|
|
6. [Verificação](#verificação)
|
|
|
|
---
|
|
|
|
## ✅ PRÉ-REQUISITOS
|
|
|
|
### **No aaPanel:**
|
|
- ✅ Node.js instalado (versão 16+)
|
|
- ✅ PM2 instalado globalmente
|
|
- ✅ Nginx configurado
|
|
- ✅ SSL/HTTPS configurado (Let's Encrypt)
|
|
- ✅ Porta 3000 liberada (ou outra porta configurada)
|
|
|
|
### **No terminal do VPS:**
|
|
```bash
|
|
# Verificar Node.js
|
|
node --version
|
|
|
|
# Verificar PM2
|
|
pm2 --version
|
|
|
|
# Se não tiver PM2:
|
|
npm install -g pm2
|
|
```
|
|
|
|
---
|
|
|
|
## 📤 UPLOAD DE ARQUIVOS
|
|
|
|
### **1. Estrutura no VPS:**
|
|
Crie a pasta no seu VPS (normalmente em `/www/wwwroot/dental-server` ou similar):
|
|
|
|
```bash
|
|
mkdir -p /www/wwwroot/dental-server
|
|
cd /www/wwwroot/dental-server
|
|
```
|
|
|
|
### **2. Arquivos para upload:**
|
|
|
|
Faça upload de TODOS estes arquivos para o servidor:
|
|
|
|
```
|
|
dental-server/
|
|
├── routes/
|
|
│ └── images.js ← API de imagens
|
|
├── public/
|
|
│ ├── index.html ← Interface web
|
|
│ ├── style.css ← Estilos
|
|
│ └── app.js ← JavaScript
|
|
├── installer/
|
|
│ └── check-installation.js
|
|
├── image-processor.js ← Processamento de imagens
|
|
├── migration-v2.sql ← SQL para atualizar banco
|
|
├── package.json ← Se não tiver, criar
|
|
├── server.js ← Arquivo principal (existente)
|
|
├── database.js ← Conexão MySQL (existente)
|
|
└── INSTALACAO-DENTAL-SERVER.md
|
|
```
|
|
|
|
---
|
|
|
|
## ⚙️ CONFIGURAÇÃO NO VPS
|
|
|
|
### **1. Instalar dependências:**
|
|
|
|
```bash
|
|
cd /www/wwwroot/dental-server
|
|
|
|
# Instalar npm packages
|
|
npm install
|
|
```
|
|
|
|
Se o `package.json` não existir, crie:
|
|
|
|
```bash
|
|
npm init -y
|
|
npm install express socket.io sharp dotenv cors cookie-parser bcrypt jsonwebtoken mysql2
|
|
```
|
|
|
|
### **2. Criar arquivo `.env`:**
|
|
|
|
```bash
|
|
nano .env
|
|
```
|
|
|
|
Adicione (ajuste conforme seu setup):
|
|
|
|
```env
|
|
# Porta do servidor
|
|
PORT=3000
|
|
|
|
# Ambiente
|
|
NODE_ENV=production
|
|
|
|
# JWT Secret (mude para algo seguro!)
|
|
JWT_SECRET=sua_chave_secreta_super_segura_aqui
|
|
|
|
# Session Secret
|
|
SESSION_SECRET=outra_chave_secreta
|
|
|
|
# Banco de dados MySQL
|
|
DB_HOST=localhost
|
|
DB_PORT=3306
|
|
DB_USER=root
|
|
DB_PASSWORD=sua_senha_mysql
|
|
DB_NAME=dental_images
|
|
|
|
# Uploads
|
|
UPLOAD_DIR=/www/wwwroot/dental-server/uploads
|
|
PROCESSED_DIR=/www/wwwroot/dental-server/processed
|
|
|
|
# SSL/Domínio
|
|
ALLOWED_ORIGINS=https://seu-dominio.com
|
|
TRUST_PROXY=true
|
|
```
|
|
|
|
Salve com `Ctrl+O` e `Ctrl+X`.
|
|
|
|
### **3. Criar pastas necessárias:**
|
|
|
|
```bash
|
|
mkdir -p uploads processed logs
|
|
chmod 755 uploads processed logs
|
|
```
|
|
|
|
---
|
|
|
|
## 🗄️ BANCO DE DADOS
|
|
|
|
### **Opção A: Via Terminal MySQL:**
|
|
|
|
```bash
|
|
cd /www/wwwroot/dental-server
|
|
|
|
# Criar banco de dados (se não existir)
|
|
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS dental_images CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|
|
|
# Executar migration
|
|
mysql -u root -p dental_images < migration-simple.sql
|
|
```
|
|
|
|
### **Opção B: Via phpMyAdmin ou MySQL Workbench:**
|
|
|
|
1. Crie o banco de dados `dental_images`
|
|
2. Selecione o banco
|
|
3. Importe o arquivo `migration-simple.sql`
|
|
|
|
### **Verificar estrutura:**
|
|
|
|
```bash
|
|
mysql -u root -p dental_images -e "DESCRIBE images;"
|
|
```
|
|
|
|
Deve mostrar todas as colunas incluindo as novas:
|
|
- `enabled`, `tooth_number`, `tooth_side`, `patient_name_resumed`
|
|
- `original_image_id`, `rotation`, `flip_horizontal`, `flip_vertical`
|
|
|
|
---
|
|
|
|
## 🚀 PM2 E NGINX
|
|
|
|
### **1. Iniciar com PM2:**
|
|
|
|
```bash
|
|
cd /www/wwwroot/dental-server
|
|
|
|
# Iniciar servidor
|
|
pm2 start server.js --name dental-server
|
|
|
|
# Salvar configuração
|
|
pm2 save
|
|
|
|
# Ver status
|
|
pm2 status dental-server
|
|
|
|
# Ver logs
|
|
pm2 logs dental-server
|
|
```
|
|
|
|
### **2. Configurar Nginx (Proxy Reverso):**
|
|
|
|
No aaPanel:
|
|
1. Vá em **Website** → **Sua lista de sites** → Clique em **Configuração**
|
|
2. Vá em **Configuração** → **Painel de configuração**
|
|
|
|
Adicione este código ANTES do último `}`:
|
|
|
|
```nginx
|
|
# Dental Server Proxy
|
|
location / {
|
|
proxy_pass http://127.0.0.1:3000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
proxy_set_header Host $host;
|
|
proxy_cache_bypass $http_upgrade;
|
|
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;
|
|
}
|
|
|
|
# Socket.IO support
|
|
location /socket.io/ {
|
|
proxy_pass http://127.0.0.1:3000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
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;
|
|
}
|
|
```
|
|
|
|
Salve e teste a configuração:
|
|
|
|
```bash
|
|
nginx -t
|
|
```
|
|
|
|
Se tudo OK, recarregue:
|
|
|
|
```bash
|
|
nginx -s reload
|
|
# ou
|
|
service nginx reload
|
|
```
|
|
|
|
---
|
|
|
|
## ✅ VERIFICAÇÃO
|
|
|
|
### **1. Testar servidor:**
|
|
|
|
```bash
|
|
# Ver se está rodando
|
|
pm2 status dental-server
|
|
|
|
# Ver logs em tempo real
|
|
pm2 logs dental-server --lines 50
|
|
|
|
# Reiniciar se necessário
|
|
pm2 restart dental-server
|
|
```
|
|
|
|
### **2. Acessar no navegador:**
|
|
|
|
1. **Login:** `https://seu-dominio.com/login`
|
|
- Usuário: `rcesar` ou `rcesar@rcesar.com`
|
|
- Senha: `Rc362514`
|
|
|
|
2. **Interface:** `https://seu-dominio.com/`
|
|
- Você verá o gerenciador de imagens
|
|
|
|
3. **Installer:** `https://seu-dominio.com/install`
|
|
- Para reconfigurar ou atualizar
|
|
|
|
### **3. Testar upload do cliente:**
|
|
|
|
Configure o cliente Windows para apontar para `https://seu-dominio.com` e envie uma imagem de teste.
|
|
|
|
---
|
|
|
|
## 🔧 COMANDOS ÚTEIS
|
|
|
|
```bash
|
|
# Ver status PM2
|
|
pm2 status
|
|
|
|
# Ver logs
|
|
pm2 logs dental-server
|
|
|
|
# Reiniciar
|
|
pm2 restart dental-server
|
|
|
|
# Parar
|
|
pm2 stop dental-server
|
|
|
|
# Iniciar
|
|
pm2 start dental-server
|
|
|
|
# Deletar
|
|
pm2 delete dental-server
|
|
|
|
# Ver informações
|
|
pm2 info dental-server
|
|
|
|
# Monitoramento
|
|
pm2 monit
|
|
```
|
|
|
|
---
|
|
|
|
## 🐛 TROUBLESHOOTING
|
|
|
|
### **Erro: "Cannot find module"**
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
### **Erro: "Port already in use"**
|
|
```bash
|
|
# Ver quem está usando a porta 3000
|
|
lsof -i :3000
|
|
|
|
# Matar processo
|
|
kill -9 <PID>
|
|
|
|
# Ou mudar porta no .env
|
|
PORT=3001
|
|
```
|
|
|
|
### **Erro no banco de dados MySQL**
|
|
```bash
|
|
# Verificar conexão MySQL
|
|
mysql -u root -p -e "USE dental_images; SHOW TABLES;"
|
|
|
|
# Ver estrutura
|
|
mysql -u root -p dental_images -e "DESCRIBE images;"
|
|
|
|
# Verificar usuário e senha
|
|
mysql -u root -p -e "SELECT User, Host FROM mysql.user;"
|
|
```
|
|
|
|
### **Nginx não carrega**
|
|
```bash
|
|
# Verificar configuração
|
|
nginx -t
|
|
|
|
# Ver logs do Nginx
|
|
tail -f /var/log/nginx/error.log
|
|
```
|
|
|
|
### **Socket.IO não conecta**
|
|
Verifique se adicionou as configurações de proxy do Socket.IO no Nginx e se o `cors` está configurado no `server.js`.
|
|
|
|
---
|
|
|
|
## 📝 PRÓXIMOS PASSOS
|
|
|
|
1. ✅ Configure o cliente Windows com o IP/domínio do servidor
|
|
2. ✅ Faça upload de imagens de teste
|
|
3. ✅ Teste todas as funcionalidades:
|
|
- Transformações (rotação, flip)
|
|
- Download com nome personalizado
|
|
- Apagar versões
|
|
- Habilitar/Desabilitar
|
|
|
|
---
|
|
|
|
## 📞 SUPORTE
|
|
|
|
Para problemas:
|
|
1. Verifique os logs: `pm2 logs dental-server`
|
|
2. Verifique o banco: `mysql -u root -p dental_images -e "SELECT * FROM images LIMIT 5;"`
|
|
3. Verifique Nginx: `tail -f /var/log/nginx/error.log`
|
|
|
|
---
|
|
|
|
**Última atualização:** 2025-01-26
|
|
**Versão:** 2.0.0
|
|
**Autor:** Rcesar
|