Domain support
This commit is contained in:
968
DEPLOYMENT.md
Normal file
968
DEPLOYMENT.md
Normal file
@@ -0,0 +1,968 @@
|
||||
# 🚀 Oltalama Panel - Sunucu Kurulum Dokümanı
|
||||
|
||||
Bu doküman, Oltalama Test Yönetim Paneli'nin production sunucusuna kurulumu için hazırlanmıştır.
|
||||
|
||||
## 📋 Gereksinimler
|
||||
|
||||
### Sistem Gereksinimleri
|
||||
- **İşletim Sistemi**: Ubuntu 20.04+ / Debian 11+ / CentOS 8+ (önerilen: Ubuntu 22.04 LTS)
|
||||
- **RAM**: Minimum 1GB, Önerilen 2GB+
|
||||
- **Disk**: Minimum 5GB boş alan
|
||||
- **CPU**: 1 core minimum, 2+ core önerilen
|
||||
|
||||
### Yazılım Gereksinimleri
|
||||
- Node.js 18.x veya üzeri
|
||||
- npm 9.x veya üzeri
|
||||
- Git
|
||||
- PM2 (process manager) veya systemd
|
||||
- SQLite3
|
||||
|
||||
### Opsiyonel
|
||||
- Nginx Proxy Manager (reverse proxy için önerilir)
|
||||
- Certbot/Let's Encrypt (SSL için)
|
||||
- fail2ban (güvenlik için)
|
||||
|
||||
## 🎯 Hızlı Kurulum (Otomatik)
|
||||
|
||||
### 1. Kurulum Scriptini İndir ve Çalıştır
|
||||
|
||||
```bash
|
||||
# Projeyi klonla
|
||||
git clone <repository-url> /opt/oltalama
|
||||
cd /opt/oltalama
|
||||
|
||||
# Kurulum scriptini çalıştırılabilir yap
|
||||
chmod +x deploy.sh
|
||||
|
||||
# Kurulumu başlat (interaktif mod)
|
||||
sudo ./deploy.sh
|
||||
```
|
||||
|
||||
Script otomatik olarak şunları yapacak:
|
||||
- ✅ Node.js kurulumu
|
||||
- ✅ Dependencies kurulumu
|
||||
- ✅ Database migration ve seed
|
||||
- ✅ PM2 ile process management kurulumu
|
||||
- ✅ Auto-restart ve startup konfigürasyonu
|
||||
- ✅ Frontend build
|
||||
- ✅ Güvenlik ayarları
|
||||
|
||||
## 🛠️ Yardımcı Scriptler
|
||||
|
||||
Kurulum sonrası kullanabileceğiniz yardımcı scriptler:
|
||||
|
||||
### Admin Kullanıcısı Oluşturma
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama
|
||||
node scripts/create-admin.js
|
||||
```
|
||||
|
||||
Bu script:
|
||||
- ✅ Yeni admin kullanıcısı oluşturur
|
||||
- ✅ Kullanıcı adı benzersizliği kontrol eder
|
||||
- ✅ Şifre güvenlik validasyonu yapar
|
||||
- ✅ Şifreyi güvenli bir şekilde hash'ler
|
||||
|
||||
### Şifre Değiştirme
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama
|
||||
node scripts/change-password.js
|
||||
```
|
||||
|
||||
Bu script:
|
||||
- ✅ Mevcut admin kullanıcısının şifresini değiştirir
|
||||
- ✅ Şifre güvenlik validasyonu yapar
|
||||
- ✅ Yeni şifreyi güvenli bir şekilde hash'ler
|
||||
|
||||
**Şifre Gereksinimleri:**
|
||||
- En az 8 karakter
|
||||
- En az 1 harf (a-z, A-Z)
|
||||
- En az 1 rakam (0-9)
|
||||
- Önerilen: Özel karakterler (!@#$%^&*)
|
||||
|
||||
## 🔧 Manuel Kurulum
|
||||
|
||||
### 1. Sistem Güncellemesi
|
||||
|
||||
```bash
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
```
|
||||
|
||||
### 2. Node.js Kurulumu
|
||||
|
||||
```bash
|
||||
# Node.js 20.x kurulumu (önerilen)
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
|
||||
# Versiyonu kontrol et
|
||||
node --version # v20.x.x olmalı
|
||||
npm --version # 10.x.x olmalı
|
||||
```
|
||||
|
||||
### 3. Proje Kurulumu
|
||||
|
||||
```bash
|
||||
# Proje dizinini oluştur
|
||||
sudo mkdir -p /opt/oltalama
|
||||
sudo chown -R $USER:$USER /opt/oltalama
|
||||
|
||||
# Projeyi klonla
|
||||
cd /opt/oltalama
|
||||
git clone <repository-url> .
|
||||
|
||||
# Backend dependencies
|
||||
cd /opt/oltalama/backend
|
||||
npm install --production
|
||||
|
||||
# Frontend dependencies ve build
|
||||
cd /opt/oltalama/frontend
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
### 4. Çevre Değişkenlerini Ayarla
|
||||
|
||||
#### Backend .env
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama/backend
|
||||
cp .env.example .env
|
||||
nano .env
|
||||
```
|
||||
|
||||
**Önemli ayarlar:**
|
||||
|
||||
```env
|
||||
# Sunucu Ayarları
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
BASE_URL=https://yourdomain.com
|
||||
|
||||
# Session Secret (güçlü bir değer oluştur)
|
||||
SESSION_SECRET=uzun-rastgele-gizli-anahtar-buraya-gelecek
|
||||
|
||||
# Gmail Ayarları (panelden de girebilirsiniz)
|
||||
GMAIL_USER=your-email@gmail.com
|
||||
GMAIL_APP_PASSWORD=your-app-password
|
||||
|
||||
# Telegram Bot (panelden de girebilirsiniz)
|
||||
TELEGRAM_BOT_TOKEN=your-bot-token
|
||||
TELEGRAM_CHAT_ID=your-chat-id
|
||||
|
||||
# Database
|
||||
DB_PATH=/opt/oltalama/backend/database/oltalama.db
|
||||
|
||||
# Log Seviyesi
|
||||
LOG_LEVEL=info
|
||||
```
|
||||
|
||||
**Session Secret oluşturma:**
|
||||
```bash
|
||||
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
|
||||
```
|
||||
|
||||
#### Frontend .env
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama/frontend
|
||||
cp .env.example .env
|
||||
nano .env
|
||||
```
|
||||
|
||||
```env
|
||||
# Backend API URL (Nginx Proxy Manager ile yönlendirme yapacaksanız domain)
|
||||
VITE_API_BASE_URL=https://yourdomain.com
|
||||
|
||||
# Veya lokal test için
|
||||
# VITE_API_BASE_URL=http://localhost:3000
|
||||
```
|
||||
|
||||
### 5. Database Kurulumu
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama/backend
|
||||
|
||||
# Migrations çalıştır
|
||||
node migrations/run-migrations.js
|
||||
|
||||
# Admin kullanıcısı oluştur
|
||||
node -e "
|
||||
const bcrypt = require('bcrypt');
|
||||
const readline = require('readline');
|
||||
const { sequelize } = require('./src/config/database');
|
||||
const AdminUser = require('./src/models/AdminUser');
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
(async () => {
|
||||
await sequelize.authenticate();
|
||||
|
||||
rl.question('Admin kullanıcı adı: ', async (username) => {
|
||||
rl.question('Admin şifresi: ', async (password) => {
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
await AdminUser.create({
|
||||
username,
|
||||
password_hash: hashedPassword,
|
||||
email: null,
|
||||
full_name: 'Administrator'
|
||||
});
|
||||
console.log('Admin kullanıcısı oluşturuldu!');
|
||||
rl.close();
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
})();
|
||||
"
|
||||
```
|
||||
|
||||
**Admin Kullanıcısı:**
|
||||
- Kurulum sırasında oluşturulacak
|
||||
- Kullanıcı adı ve şifre: İnteraktif olarak sizden istenecek
|
||||
- Şifre gereksinimleri:
|
||||
- En az 8 karakter
|
||||
- En az 1 harf ve 1 rakam içermeli
|
||||
- Güçlü şifre kullanmanız önerilir
|
||||
|
||||
### 6. PM2 ile Process Management
|
||||
|
||||
#### PM2 Kurulumu
|
||||
|
||||
```bash
|
||||
sudo npm install -g pm2
|
||||
```
|
||||
|
||||
#### PM2 Konfigürasyonu
|
||||
|
||||
`/opt/oltalama/ecosystem.config.js` dosyası:
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'oltalama-backend',
|
||||
cwd: '/opt/oltalama/backend',
|
||||
script: 'src/app.js',
|
||||
instances: 1,
|
||||
exec_mode: 'cluster',
|
||||
watch: false,
|
||||
max_memory_restart: '500M',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 3000,
|
||||
},
|
||||
error_file: '/var/log/oltalama/backend-error.log',
|
||||
out_file: '/var/log/oltalama/backend-out.log',
|
||||
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
|
||||
},
|
||||
{
|
||||
name: 'oltalama-frontend',
|
||||
cwd: '/opt/oltalama/frontend',
|
||||
script: 'npm',
|
||||
args: 'run preview',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
watch: false,
|
||||
max_memory_restart: '300M',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 4173,
|
||||
},
|
||||
error_file: '/var/log/oltalama/frontend-error.log',
|
||||
out_file: '/var/log/oltalama/frontend-out.log',
|
||||
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
#### PM2 Başlatma
|
||||
|
||||
```bash
|
||||
# Log dizini oluştur
|
||||
sudo mkdir -p /var/log/oltalama
|
||||
sudo chown -R $USER:$USER /var/log/oltalama
|
||||
|
||||
# Frontend build (eğer henüz build etmediyseniz)
|
||||
cd /opt/oltalama/frontend
|
||||
npm run build
|
||||
|
||||
# PM2 ile uygulamayı başlat
|
||||
cd /opt/oltalama
|
||||
pm2 start ecosystem.config.js
|
||||
|
||||
# Durumu kontrol et
|
||||
pm2 status
|
||||
|
||||
# Logları izle
|
||||
pm2 logs
|
||||
|
||||
# Startup script oluştur (sunucu yeniden başladığında otomatik başlasın)
|
||||
pm2 startup
|
||||
# Komutu çıktıdaki komutu çalıştırın
|
||||
|
||||
# Mevcut durumu kaydet
|
||||
pm2 save
|
||||
```
|
||||
|
||||
#### PM2 Komutları
|
||||
|
||||
```bash
|
||||
pm2 status # Durum kontrolü
|
||||
pm2 logs # Tüm loglar
|
||||
pm2 logs oltalama-backend # Backend logları
|
||||
pm2 logs oltalama-frontend # Frontend logları
|
||||
pm2 restart all # Tümünü yeniden başlat
|
||||
pm2 restart oltalama-backend # Backend'i yeniden başlat
|
||||
pm2 stop all # Tümünü durdur
|
||||
pm2 delete all # Tümünü sil
|
||||
```
|
||||
|
||||
### 7. Systemd Service Alternatifi (PM2 yerine)
|
||||
|
||||
PM2 yerine systemd kullanmak isterseniz:
|
||||
|
||||
#### Backend Service
|
||||
|
||||
`/etc/systemd/system/oltalama-backend.service`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Oltalama Backend Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=www-data
|
||||
WorkingDirectory=/opt/oltalama/backend
|
||||
Environment=NODE_ENV=production
|
||||
ExecStart=/usr/bin/node /opt/oltalama/backend/src/app.js
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=append:/var/log/oltalama/backend.log
|
||||
StandardError=append:/var/log/oltalama/backend-error.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
#### Frontend Service
|
||||
|
||||
`/etc/systemd/system/oltalama-frontend.service`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Oltalama Frontend Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=www-data
|
||||
WorkingDirectory=/opt/oltalama/frontend
|
||||
Environment=NODE_ENV=production
|
||||
ExecStart=/usr/bin/npm run preview
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=append:/var/log/oltalama/frontend.log
|
||||
StandardError=append:/var/log/oltalama/frontend-error.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
#### Servisleri Başlat
|
||||
|
||||
```bash
|
||||
# Servisleri yükle
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
# Servisleri başlat
|
||||
sudo systemctl start oltalama-backend
|
||||
sudo systemctl start oltalama-frontend
|
||||
|
||||
# Başlangıçta otomatik başlasın
|
||||
sudo systemctl enable oltalama-backend
|
||||
sudo systemctl enable oltalama-frontend
|
||||
|
||||
# Durumu kontrol et
|
||||
sudo systemctl status oltalama-backend
|
||||
sudo systemctl status oltalama-frontend
|
||||
```
|
||||
|
||||
## 🌐 Nginx Proxy Manager Kurulumu
|
||||
|
||||
### Portlar
|
||||
|
||||
- **Backend**: `http://localhost:3000`
|
||||
- **Frontend**: `http://localhost:4173`
|
||||
|
||||
### Nginx Proxy Manager Ayarları
|
||||
|
||||
1. **Nginx Proxy Manager'a giriş yapın**
|
||||
2. **Proxy Hosts** → **Add Proxy Host**
|
||||
|
||||
#### Frontend Proxy Host
|
||||
|
||||
```
|
||||
Domain Names: yourdomain.com
|
||||
Scheme: http
|
||||
Forward Hostname/IP: localhost
|
||||
Forward Port: 4173
|
||||
Cache Assets: ✓
|
||||
Block Common Exploits: ✓
|
||||
Websockets Support: ✓
|
||||
|
||||
SSL:
|
||||
- Force SSL: ✓
|
||||
- HTTP/2 Support: ✓
|
||||
- HSTS Enabled: ✓
|
||||
```
|
||||
|
||||
#### Backend API Proxy (Eğer ayrı subdomain kullanacaksanız)
|
||||
|
||||
```
|
||||
Domain Names: api.yourdomain.com
|
||||
Scheme: http
|
||||
Forward Hostname/IP: localhost
|
||||
Forward Port: 3000
|
||||
Block Common Exploits: ✓
|
||||
Websockets Support: ✓
|
||||
|
||||
SSL:
|
||||
- Force SSL: ✓
|
||||
- HTTP/2 Support: ✓
|
||||
- HSTS Enabled: ✓
|
||||
```
|
||||
|
||||
**Custom Nginx Configuration (Advanced sekmesi):**
|
||||
|
||||
```nginx
|
||||
location /api {
|
||||
proxy_pass http://localhost: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;
|
||||
}
|
||||
```
|
||||
|
||||
## 🔒 Güvenlik Önerileri
|
||||
|
||||
### 1. Firewall Ayarları
|
||||
|
||||
```bash
|
||||
# UFW kurulumu ve ayarları
|
||||
sudo apt install ufw
|
||||
|
||||
# SSH izin ver (bağlantınızı koparmayın!)
|
||||
sudo ufw allow 22/tcp
|
||||
|
||||
# Backend ve Frontend portları (sadece localhost'tan erişilebilir olmalı)
|
||||
# Nginx Proxy Manager kullanıyorsanız bu portları kapatın
|
||||
sudo ufw deny 3000/tcp
|
||||
sudo ufw deny 4173/tcp
|
||||
|
||||
# HTTP/HTTPS (Nginx Proxy Manager için)
|
||||
sudo ufw allow 80/tcp
|
||||
sudo ufw allow 443/tcp
|
||||
|
||||
# Firewall'ı aktifleştir
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
### 2. Admin Şifresini Değiştir (Gerekirse)
|
||||
|
||||
Şifrenizi değiştirmek isterseniz:
|
||||
|
||||
```bash
|
||||
# Backend dizinine git
|
||||
cd /opt/oltalama/backend
|
||||
|
||||
# Yeni şifre oluşturma scripti
|
||||
node -e "
|
||||
const bcrypt = require('bcrypt');
|
||||
const readline = require('readline');
|
||||
const { sequelize } = require('./src/config/database');
|
||||
const { AdminUser } = require('./src/models');
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
(async () => {
|
||||
await sequelize.authenticate();
|
||||
|
||||
rl.question('Admin kullanıcı adı: ', async (username) => {
|
||||
rl.question('Yeni şifre: ', async (password) => {
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
await AdminUser.update(
|
||||
{ password_hash: hashedPassword },
|
||||
{ where: { username } }
|
||||
);
|
||||
console.log('Şifre değiştirildi!');
|
||||
rl.close();
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
})();
|
||||
"
|
||||
```
|
||||
|
||||
### 3. Dosya İzinleri
|
||||
|
||||
```bash
|
||||
# Proje dizini izinleri
|
||||
sudo chown -R www-data:www-data /opt/oltalama
|
||||
sudo chmod -R 755 /opt/oltalama
|
||||
|
||||
# .env dosyalarını koru
|
||||
sudo chmod 600 /opt/oltalama/backend/.env
|
||||
sudo chmod 600 /opt/oltalama/frontend/.env
|
||||
|
||||
# Database izinleri
|
||||
sudo chmod 600 /opt/oltalama/backend/database/oltalama.db
|
||||
```
|
||||
|
||||
### 4. Fail2Ban Kurulumu (Opsiyonel)
|
||||
|
||||
```bash
|
||||
sudo apt install fail2ban
|
||||
|
||||
# /etc/fail2ban/jail.local
|
||||
sudo nano /etc/fail2ban/jail.local
|
||||
```
|
||||
|
||||
```ini
|
||||
[DEFAULT]
|
||||
bantime = 3600
|
||||
findtime = 600
|
||||
maxretry = 5
|
||||
|
||||
[sshd]
|
||||
enabled = true
|
||||
```
|
||||
|
||||
```bash
|
||||
sudo systemctl restart fail2ban
|
||||
```
|
||||
|
||||
### 5. Düzenli Güncellemeler
|
||||
|
||||
```bash
|
||||
# Sistem güncellemeleri
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# Node paketleri
|
||||
cd /opt/oltalama/backend && npm update
|
||||
cd /opt/oltalama/frontend && npm update
|
||||
|
||||
# PM2 güncelleme
|
||||
pm2 update
|
||||
```
|
||||
|
||||
## 💾 Yedekleme
|
||||
|
||||
### 1. Database Yedekleme
|
||||
|
||||
```bash
|
||||
# Manuel yedekleme
|
||||
cp /opt/oltalama/backend/database/oltalama.db \
|
||||
/opt/oltalama/backups/oltalama-$(date +%Y%m%d-%H%M%S).db
|
||||
```
|
||||
|
||||
### 2. Otomatik Yedekleme Script
|
||||
|
||||
`/opt/oltalama/backup.sh`:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
BACKUP_DIR="/opt/oltalama/backups"
|
||||
DB_PATH="/opt/oltalama/backend/database/oltalama.db"
|
||||
DATE=$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
# Backup dizini oluştur
|
||||
mkdir -p $BACKUP_DIR
|
||||
|
||||
# Database yedekle
|
||||
cp $DB_PATH "$BACKUP_DIR/oltalama-$DATE.db"
|
||||
|
||||
# 30 günden eski yedekleri sil
|
||||
find $BACKUP_DIR -name "oltalama-*.db" -mtime +30 -delete
|
||||
|
||||
echo "Backup completed: oltalama-$DATE.db"
|
||||
```
|
||||
|
||||
```bash
|
||||
chmod +x /opt/oltalama/backup.sh
|
||||
|
||||
# Crontab ekle (her gün saat 03:00'te)
|
||||
crontab -e
|
||||
# Ekle:
|
||||
0 3 * * * /opt/oltalama/backup.sh >> /var/log/oltalama/backup.log 2>&1
|
||||
```
|
||||
|
||||
### 3. Tam Sistem Yedeği
|
||||
|
||||
```bash
|
||||
# Tüm projeyi yedekle
|
||||
tar -czf /backup/oltalama-full-$(date +%Y%m%d).tar.gz \
|
||||
/opt/oltalama \
|
||||
/etc/systemd/system/oltalama-*.service \
|
||||
/var/log/oltalama
|
||||
```
|
||||
|
||||
## 🔄 Güncelleme
|
||||
|
||||
### Git ile Güncelleme
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama
|
||||
|
||||
# Değişiklikleri al
|
||||
git pull origin main
|
||||
|
||||
# Backend güncelleme
|
||||
cd backend
|
||||
npm install --production
|
||||
node migrations/run-migrations.js
|
||||
|
||||
# Frontend güncelleme
|
||||
cd ../frontend
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# Servisleri yeniden başlat
|
||||
pm2 restart all
|
||||
# veya
|
||||
sudo systemctl restart oltalama-backend
|
||||
sudo systemctl restart oltalama-frontend
|
||||
```
|
||||
|
||||
## 📊 Monitoring ve Loglar
|
||||
|
||||
### PM2 Monitoring
|
||||
|
||||
```bash
|
||||
# Dashboard
|
||||
pm2 monit
|
||||
|
||||
# Memory/CPU kullanımı
|
||||
pm2 list
|
||||
```
|
||||
|
||||
### Log Dosyaları
|
||||
|
||||
```bash
|
||||
# Backend logs
|
||||
tail -f /var/log/oltalama/backend.log
|
||||
tail -f /var/log/oltalama/backend-error.log
|
||||
|
||||
# Frontend logs
|
||||
tail -f /var/log/oltalama/frontend.log
|
||||
|
||||
# PM2 logs
|
||||
pm2 logs --lines 100
|
||||
```
|
||||
|
||||
### Log Rotation
|
||||
|
||||
`/etc/logrotate.d/oltalama`:
|
||||
|
||||
```
|
||||
/var/log/oltalama/*.log {
|
||||
daily
|
||||
rotate 30
|
||||
compress
|
||||
delaycompress
|
||||
missingok
|
||||
notifempty
|
||||
create 0640 www-data www-data
|
||||
sharedscripts
|
||||
postrotate
|
||||
pm2 reloadLogs
|
||||
endscript
|
||||
}
|
||||
```
|
||||
|
||||
## 🐛 Sorun Giderme
|
||||
|
||||
### Port Zaten Kullanımda
|
||||
|
||||
```bash
|
||||
# Port 3000'i kullanan process'i bul
|
||||
sudo lsof -i :3000
|
||||
|
||||
# Process'i öldür
|
||||
sudo kill -9 <PID>
|
||||
```
|
||||
|
||||
### Database Locked
|
||||
|
||||
```bash
|
||||
# SQLite lock'ları temizle
|
||||
fuser -k /opt/oltalama/backend/database/oltalama.db
|
||||
```
|
||||
|
||||
### PM2 Çalışmıyor
|
||||
|
||||
```bash
|
||||
# PM2'yi sıfırla
|
||||
pm2 kill
|
||||
pm2 start ecosystem.config.js
|
||||
pm2 save
|
||||
```
|
||||
|
||||
### High Memory Usage
|
||||
|
||||
```bash
|
||||
# Memory kullanımını kontrol et
|
||||
pm2 list
|
||||
|
||||
# Uygulamayı yeniden başlat
|
||||
pm2 restart oltalama-backend --update-env
|
||||
```
|
||||
|
||||
## 👥 Kullanıcı Yönetimi
|
||||
|
||||
### Yeni Admin Kullanıcısı Ekleme
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama
|
||||
node scripts/create-admin.js
|
||||
```
|
||||
|
||||
### Admin Şifresi Değiştirme
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama
|
||||
node scripts/change-password.js
|
||||
```
|
||||
|
||||
### Admin Kullanıcısını Manuel Oluşturma (SQL)
|
||||
|
||||
```bash
|
||||
# Şifre hash'i oluştur
|
||||
node -p "require('bcrypt').hashSync('YourPassword123', 10)"
|
||||
|
||||
# SQLite ile kullanıcı ekle
|
||||
cd /opt/oltalama/backend
|
||||
sqlite3 database/oltalama.db
|
||||
|
||||
INSERT INTO admin_user (username, password_hash, full_name, created_at, updated_at)
|
||||
VALUES ('newadmin', '$2b$10$...', 'New Admin', datetime('now'), datetime('now'));
|
||||
|
||||
.quit
|
||||
```
|
||||
|
||||
### Tüm Admin Kullanıcılarını Listele
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama/backend
|
||||
sqlite3 database/oltalama.db "SELECT id, username, full_name, email, created_at FROM admin_user;"
|
||||
```
|
||||
|
||||
### Admin Kullanıcısı Sil
|
||||
|
||||
```bash
|
||||
cd /opt/oltalama/backend
|
||||
sqlite3 database/oltalama.db "DELETE FROM admin_user WHERE username='oldadmin';"
|
||||
```
|
||||
|
||||
## 📝 Opsiyonel: Manuel Nginx Kurulumu
|
||||
|
||||
Nginx Proxy Manager yerine klasik Nginx kullanmak isterseniz:
|
||||
|
||||
### Nginx Kurulumu
|
||||
|
||||
```bash
|
||||
sudo apt install nginx
|
||||
```
|
||||
|
||||
### Nginx Konfigürasyonu
|
||||
|
||||
`/etc/nginx/sites-available/oltalama`:
|
||||
|
||||
```nginx
|
||||
# Upstream tanımları
|
||||
upstream backend {
|
||||
server localhost:3000;
|
||||
keepalive 64;
|
||||
}
|
||||
|
||||
upstream frontend {
|
||||
server localhost:4173;
|
||||
keepalive 64;
|
||||
}
|
||||
|
||||
# HTTP to HTTPS redirect
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name yourdomain.com;
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
# HTTPS server
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name yourdomain.com;
|
||||
|
||||
# SSL sertifikaları (Let's Encrypt ile oluşturun)
|
||||
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
|
||||
ssl_trusted_certificate /etc/letsencrypt/live/yourdomain.com/chain.pem;
|
||||
|
||||
# SSL ayarları
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# Security headers
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# Client body size
|
||||
client_max_body_size 10M;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json;
|
||||
|
||||
# Backend API
|
||||
location /api {
|
||||
proxy_pass http://backend;
|
||||
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;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# Tracking endpoint
|
||||
location /t/ {
|
||||
proxy_pass http://backend;
|
||||
proxy_http_version 1.1;
|
||||
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;
|
||||
}
|
||||
|
||||
# Frontend
|
||||
location / {
|
||||
proxy_pass http://frontend;
|
||||
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;
|
||||
}
|
||||
|
||||
# Logs
|
||||
access_log /var/log/nginx/oltalama-access.log;
|
||||
error_log /var/log/nginx/oltalama-error.log;
|
||||
}
|
||||
```
|
||||
|
||||
### Nginx'i Aktifleştir
|
||||
|
||||
```bash
|
||||
# Symlink oluştur
|
||||
sudo ln -s /etc/nginx/sites-available/oltalama /etc/nginx/sites-enabled/
|
||||
|
||||
# Konfigürasyonu test et
|
||||
sudo nginx -t
|
||||
|
||||
# Nginx'i yeniden başlat
|
||||
sudo systemctl restart nginx
|
||||
sudo systemctl enable nginx
|
||||
```
|
||||
|
||||
### SSL Sertifikası (Let's Encrypt)
|
||||
|
||||
```bash
|
||||
# Certbot kurulumu
|
||||
sudo apt install certbot python3-certbot-nginx
|
||||
|
||||
# Sertifika oluştur
|
||||
sudo certbot --nginx -d yourdomain.com
|
||||
|
||||
# Otomatik yenileme
|
||||
sudo certbot renew --dry-run
|
||||
```
|
||||
|
||||
## ✅ Kurulum Kontrolü
|
||||
|
||||
### Sistemin Çalıştığını Kontrol Et
|
||||
|
||||
```bash
|
||||
# Servis durumları
|
||||
pm2 status
|
||||
# veya
|
||||
sudo systemctl status oltalama-backend
|
||||
sudo systemctl status oltalama-frontend
|
||||
|
||||
# Port dinleme kontrolü
|
||||
sudo netstat -tulpn | grep -E ':(3000|4173)'
|
||||
|
||||
# HTTP istekleri
|
||||
curl http://localhost:3000/api/health
|
||||
curl http://localhost:4173
|
||||
|
||||
# Domain kontrolü (Nginx Proxy Manager kurulduysa)
|
||||
curl https://yourdomain.com
|
||||
```
|
||||
|
||||
### Performans Testi
|
||||
|
||||
```bash
|
||||
# Backend response time
|
||||
time curl http://localhost:3000/api/health
|
||||
|
||||
# Memory kullanımı
|
||||
free -h
|
||||
|
||||
# Disk kullanımı
|
||||
df -h
|
||||
```
|
||||
|
||||
## 📞 Destek
|
||||
|
||||
Sorun yaşarsanız:
|
||||
1. Logları kontrol edin: `pm2 logs` veya `/var/log/oltalama/`
|
||||
2. GitHub Issues'da sorun bildirin
|
||||
3. Dokümanı tekrar gözden geçirin
|
||||
|
||||
## 📚 Ek Kaynaklar
|
||||
|
||||
- [PM2 Documentation](https://pm2.keymetrics.io/)
|
||||
- [Nginx Documentation](https://nginx.org/en/docs/)
|
||||
- [Node.js Best Practices](https://github.com/goldbergyoni/nodebestpractices)
|
||||
- [SQLite Documentation](https://www.sqlite.org/docs.html)
|
||||
|
||||
---
|
||||
|
||||
**Son Güncelleme**: 2025-11-10
|
||||
**Versiyon**: 1.0.0
|
||||
|
||||
Reference in New Issue
Block a user