# 🐧 Ubuntu VPS TelepĂ­tĂ©si ÚtmutatĂł - Claude Agent KönyvtĂĄr ## 🌐 Production Deployment: agent.nb-studio.net Komplett ĂștmutatĂł Ubuntu VPS-re törtĂ©nƑ telepĂ­tĂ©shez production környezetben. --- ## 📋 VPS KövetelmĂ©nyek **MinimĂĄlis specifikĂĄciĂł:** - **OS:** Ubuntu 22.04 LTS (vagy Ășjabb) - **RAM:** 2GB minimum (4GB ajĂĄnlott) - **CPU:** 2 cores minimum - **Storage:** 20GB minimum (50GB ajĂĄnlott) - **Domain:** agent.nb-studio.net (DNS beĂĄllĂ­tva) **AjĂĄnlott VPS szolgĂĄltatĂłk:** - DigitalOcean (Droplet) - Linode - Vultr - Hetzner Cloud - AWS EC2 - Google Cloud Compute Engine --- ## 🚀 Gyors TelepĂ­tĂ©s (Automatikus Script) ### 1. Csatlakozz a VPS-hez ```bash ssh root@YOUR_VPS_IP # vagy ssh ubuntu@YOUR_VPS_IP ``` ### 2. Töltsd le Ă©s futtasd az automatikus telepĂ­tƑt ```bash # LetöltĂ©s wget https://raw.githubusercontent.com/nbartus21/Claude-agentek/main/setup-vps.sh # FuttathatĂłvĂĄ tĂ©tel chmod +x setup-vps.sh # FuttatĂĄs sudo ./setup-vps.sh ``` **A script mindent telepĂ­t automatikusan!** ✅ --- ## 📝 ManuĂĄlis TelepĂ­tĂ©s (LĂ©pĂ©srƑl-lĂ©pĂ©sre) ### 1ïžâƒŁ Rendszer frissĂ­tĂ©se ```bash # Jelentkezz be root-kĂ©nt vagy hasznĂĄlj sudo-t sudo apt update && sudo apt upgrade -y # Hasznos csomagok telepĂ­tĂ©se sudo apt install -y \ curl \ wget \ git \ build-essential \ software-properties-common \ apt-transport-https \ ca-certificates \ gnupg \ lsb-release \ ufw \ fail2ban ``` ### 2ïžâƒŁ Node.js telepĂ­tĂ©se ```bash # Node.js 20.x LTS telepĂ­tĂ©se curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs # EllenƑrzĂ©s node --version # v20.x npm --version # 10.x # Yarn telepĂ­tĂ©se (opcionĂĄlis) sudo npm install -g yarn # PM2 telepĂ­tĂ©se (process manager) sudo npm install -g pm2 ``` ### 3ïžâƒŁ Python telepĂ­tĂ©se ```bash # Python 3.11 telepĂ­tĂ©se sudo add-apt-repository ppa:deadsnakes/ppa -y sudo apt update sudo apt install -y \ python3.11 \ python3.11-venv \ python3.11-dev \ python3-pip # Python 3.11 alapĂ©rtelmezettĂ© tĂ©tele sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 # EllenƑrzĂ©s python3 --version # Python 3.11.x pip3 --version ``` ### 4ïžâƒŁ PostgreSQL telepĂ­tĂ©se ```bash # PostgreSQL 15 telepĂ­tĂ©se sudo apt install -y postgresql postgresql-contrib # PostgreSQL indĂ­tĂĄsa sudo systemctl start postgresql sudo systemctl enable postgresql # Database Ă©s user lĂ©trehozĂĄsa sudo -u postgres psql << EOF CREATE DATABASE agent_db; CREATE USER agent_user WITH ENCRYPTED PASSWORD 'your_secure_password'; GRANT ALL PRIVILEGES ON DATABASE agent_db TO agent_user; \q EOF # Kapcsolat tesztelĂ©se psql -h localhost -U agent_user -d agent_db ``` ### 5ïžâƒŁ Redis telepĂ­tĂ©se ```bash # Redis telepĂ­tĂ©se sudo apt install -y redis-server # Redis konfigurĂĄlĂĄsa sudo nano /etc/redis/redis.conf # MĂłdosĂ­tsd: supervised systemd # Redis indĂ­tĂĄsa sudo systemctl restart redis-server sudo systemctl enable redis-server # TesztelĂ©s redis-cli ping # PONG ``` ### 6ïžâƒŁ Nginx telepĂ­tĂ©se ```bash # Nginx telepĂ­tĂ©se sudo apt install -y nginx # Nginx indĂ­tĂĄsa sudo systemctl start nginx sudo systemctl enable nginx # TƱzfal beĂĄllĂ­tĂĄs sudo ufw allow 'Nginx Full' sudo ufw allow OpenSSH sudo ufw enable ``` ### 7ïžâƒŁ Repository klĂłnozĂĄsa ```bash # Hozz lĂ©tre deployment user-t sudo adduser deploy sudo usermod -aG sudo deploy # VĂĄltĂĄs deploy user-re su - deploy # Home directory-ba navigĂĄlĂĄs cd ~ # Repository klĂłnozĂĄsa git clone https://github.com/nbartus21/Claude-agentek.git cd Claude-agentek ``` ### 8ïžâƒŁ Python környezet beĂĄllĂ­tĂĄsa ```bash # Virtual environment lĂ©trehozĂĄsa python3 -m venv venv # AktivĂĄlĂĄs source venv/bin/activate # Csomagok telepĂ­tĂ©se pip install --upgrade pip pip install -r requirements.txt # Django/FastAPI specifikus (ha hasznĂĄlod) pip install gunicorn uvicorn[standard] ``` ### 9ïžâƒŁ Node.js környezet beĂĄllĂ­tĂĄsa ```bash # Ha van React app vagy Next.js cd ~/Claude-agentek/frontend # vagy a megfelelƑ mappa # Dependencies telepĂ­tĂ©se npm install # Production build npm run build # PM2-vel indĂ­tĂĄs (Next.js pĂ©lda) pm2 start npm --name "agent-frontend" -- start pm2 save pm2 startup ``` ### 🔟 Környezeti vĂĄltozĂłk beĂĄllĂ­tĂĄsa ```bash # .env fĂĄjl lĂ©trehozĂĄsa cd ~/Claude-agentek nano .env ``` ```env # === Database === DATABASE_URL=postgresql://agent_user:your_secure_password@localhost:5432/agent_db # === Redis === REDIS_URL=redis://localhost:6379 # === Supabase === SUPABASE_URL=https://your-project.supabase.co SUPABASE_ANON_KEY=your-anon-key SUPABASE_SERVICE_ROLE_KEY=your-service-role-key # === OpenAI === OPENAI_API_KEY=sk-your-key # === Anthropic === ANTHROPIC_API_KEY=sk-ant-your-key # === Clerk === NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_ CLERK_SECRET_KEY=sk_live_ # === Domain === NEXT_PUBLIC_APP_URL=https://agent.nb-studio.net # === Node === NODE_ENV=production PORT=3000 ``` --- ## 🌐 Nginx KonfigurĂĄciĂł (agent.nb-studio.net) ### 1ïžâƒŁ Nginx config fĂĄjl lĂ©trehozĂĄsa ```bash sudo nano /etc/nginx/sites-available/agent.nb-studio.net ``` ```nginx # HTTP -> HTTPS redirect server { listen 80; listen [::]:80; server_name agent.nb-studio.net; # Let's Encrypt challenge location /.well-known/acme-challenge/ { root /var/www/html; } # Redirect minden mĂĄst HTTPS-re location / { return 301 https://$server_name$request_uri; } } # HTTPS - Main application server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name agent.nb-studio.net; # SSL certificates (Let's Encrypt) ssl_certificate /etc/letsencrypt/live/agent.nb-studio.net/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/agent.nb-studio.net/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/agent.nb-studio.net/chain.pem; # SSL settings 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; # Logging access_log /var/log/nginx/agent.nb-studio.net.access.log; error_log /var/log/nginx/agent.nb-studio.net.error.log; # Client upload size client_max_body_size 50M; # 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 application/javascript; # Next.js / Node.js backend location / { 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_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; } # API routes (FastAPI/Django - ha hasznĂĄlod) location /api/ { proxy_pass http://localhost:8000; 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; } # Static files (ha van) location /static/ { alias /home/deploy/Claude-agentek/static/; expires 30d; add_header Cache-Control "public, immutable"; } location /media/ { alias /home/deploy/Claude-agentek/media/; expires 7d; } } ``` ### 2ïžâƒŁ Site engedĂ©lyezĂ©se ```bash # Symlink lĂ©trehozĂĄsa sudo ln -s /etc/nginx/sites-available/agent.nb-studio.net /etc/nginx/sites-enabled/ # Default site törlĂ©se (opcionĂĄlis) sudo rm /etc/nginx/sites-enabled/default # Nginx konfig tesztelĂ©se sudo nginx -t # Nginx ĂșjraindĂ­tĂĄsa sudo systemctl reload nginx ``` --- ## 🔒 SSL Certificate (Let's Encrypt) ### 1ïžâƒŁ Certbot telepĂ­tĂ©se ```bash # Certbot telepĂ­tĂ©se sudo apt install -y certbot python3-certbot-nginx ``` ### 2ïžâƒŁ SSL Certificate beszerzĂ©se ```bash # ⚠ ElƑtte bizonyosodj meg, hogy a DNS beĂĄllĂ­tĂĄsok rendben vannak! # agent.nb-studio.net A record -> VPS IP # Certificate kĂ©rĂ©se sudo certbot --nginx -d agent.nb-studio.net # KĂ©rdĂ©sek: # Email: your-email@example.com # Terms of Service: (A)gree # Share email: (Y)es or (N)o # No redirect / Redirect: 2 (Redirect to HTTPS) ``` ### 3ïžâƒŁ Auto-renewal beĂĄllĂ­tĂĄsa ```bash # Certbot timer ellenƑrzĂ©se sudo systemctl status certbot.timer # ManuĂĄlis renewal teszt sudo certbot renew --dry-run # Auto-renewal mƱködik automatikusan! ``` --- ## 🔄 Systemd Service (Backend API - opcionĂĄlis) Ha van Python backend (FastAPI/Django): ```bash # Service fĂĄjl lĂ©trehozĂĄsa sudo nano /etc/systemd/system/agent-api.service ``` ```ini [Unit] Description=Claude Agent API (FastAPI/Django) After=network.target postgresql.service redis.service [Service] Type=notify User=deploy Group=deploy WorkingDirectory=/home/deploy/Claude-agentek Environment="PATH=/home/deploy/Claude-agentek/venv/bin" Environment="DATABASE_URL=postgresql://agent_user:password@localhost:5432/agent_db" ExecStart=/home/deploy/Claude-agentek/venv/bin/gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:8000 # Or for Django: # ExecStart=/home/deploy/Claude-agentek/venv/bin/gunicorn --workers 3 --bind 0.0.0.0:8000 myproject.wsgi:application Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ``` ```bash # Service engedĂ©lyezĂ©se sudo systemctl daemon-reload sudo systemctl start agent-api sudo systemctl enable agent-api # Status ellenƑrzĂ©se sudo systemctl status agent-api # Logs sudo journalctl -u agent-api -f ``` --- ## 🐳 Docker AlternatĂ­va (OpcionĂĄlis) ### Docker & Docker Compose telepĂ­tĂ©se ```bash # Docker telepĂ­tĂ©se curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh # Docker Compose telepĂ­tĂ©se sudo apt install -y docker-compose # User hozzĂĄadĂĄsa docker group-hoz sudo usermod -aG docker $USER # Logout & login Ășjra ``` ### docker-compose.yml pĂ©lda ```yaml version: '3.8' services: postgres: image: postgres:15-alpine environment: POSTGRES_DB: agent_db POSTGRES_USER: agent_user POSTGRES_PASSWORD: your_secure_password volumes: - postgres_data:/var/lib/postgresql/data ports: - "5432:5432" restart: unless-stopped redis: image: redis:7-alpine ports: - "6379:6379" volumes: - redis_data:/data restart: unless-stopped app: build: . environment: - NODE_ENV=production - DATABASE_URL=postgresql://agent_user:your_secure_password@postgres:5432/agent_db - REDIS_URL=redis://redis:6379 ports: - "3000:3000" depends_on: - postgres - redis restart: unless-stopped volumes: postgres_data: redis_data: ``` ```bash # IndĂ­tĂĄs docker-compose up -d # Logs docker-compose logs -f # LeĂĄllĂ­tĂĄs docker-compose down ``` --- ## 🔐 BiztonsĂĄg & Hardening ### 1ïžâƒŁ Firewall (UFW) ```bash # UFW engedĂ©lyezĂ©se sudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' sudo ufw enable # Status ellenƑrzĂ©se sudo ufw status ``` ### 2ïžâƒŁ Fail2Ban (Brute force vĂ©delem) ```bash # Fail2ban telepĂ­tĂ©se sudo apt install -y fail2ban # KonfigurĂĄciĂł sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local sudo nano /etc/fail2ban/jail.local # Fail2ban indĂ­tĂĄsa sudo systemctl start fail2ban sudo systemctl enable fail2ban ``` ### 3ïžâƒŁ SSH hardening ```bash # SSH konfig sudo nano /etc/ssh/sshd_config ``` ``` # MĂłdosĂ­tsd: PermitRootLogin no PasswordAuthentication no # Ha van SSH key Port 2222 # OpcionĂĄlis: port mĂłdosĂ­tĂĄs ``` ```bash # SSH ĂșjraindĂ­tĂĄsa sudo systemctl restart sshd # Ha port-ot mĂłdosĂ­tottĂĄl: sudo ufw allow 2222/tcp ``` --- ## 📊 Monitoring & Logs ### PM2 Monitoring (Node.js apps) ```bash # PM2 status pm2 status # Logs pm2 logs # Monitoring dashboard pm2 monit # Process info pm2 info agent-frontend ``` ### Nginx Logs ```bash # Access log sudo tail -f /var/log/nginx/agent.nb-studio.net.access.log # Error log sudo tail -f /var/log/nginx/agent.nb-studio.net.error.log ``` ### Systemd Service Logs ```bash # Service logs sudo journalctl -u agent-api -f # Összes systemd log sudo journalctl -xe ``` --- ## 🚀 Deployment Workflow ### ElsƑ telepĂ­tĂ©s utĂĄn frissĂ­tĂ©sek: ```bash # 1. SSH a VPS-re ssh deploy@agent.nb-studio.net # 2. NavigĂĄlĂĄs a projekthez cd ~/Claude-agentek # 3. Git pull git pull origin main # 4. Dependencies frissĂ­tĂ©se (ha kell) source venv/bin/activate pip install -r requirements.txt # Frontend cd frontend npm install # 5. Build (ha kell) npm run build # 6. Restart services pm2 restart agent-frontend sudo systemctl restart agent-api # Ha van sudo systemctl reload nginx ``` --- ## ✅ EllenƑrzƑ Lista - [ ] VPS lĂ©trehozva Ă©s elĂ©rhetƑ - [ ] Ubuntu frissĂ­tve - [ ] Node.js telepĂ­tve - [ ] Python telepĂ­tve - [ ] PostgreSQL telepĂ­tve Ă©s konfigurĂĄlva - [ ] Redis telepĂ­tve - [ ] Nginx telepĂ­tve - [ ] Repository klĂłnozva - [ ] Környezeti vĂĄltozĂłk beĂĄllĂ­tva (.env) - [ ] DNS beĂĄllĂ­tva (agent.nb-studio.net -> VPS IP) - [ ] SSL certificate telepĂ­tve (Let's Encrypt) - [ ] Nginx konfig beĂĄllĂ­tva Ă©s mƱködik - [ ] Application fut (PM2 vagy systemd) - [ ] Firewall konfigurĂĄlva (UFW) - [ ] Fail2Ban beĂĄllĂ­tva - [ ] Monitoring mƱködik - [ ] Backup stratĂ©gia (opcionĂĄlis) --- ## 🆘 HibaelhĂĄrĂ­tĂĄs **502 Bad Gateway** ```bash # EllenƑrizd, hogy a backend fut-e pm2 status sudo systemctl status agent-api # Nginx error log sudo tail -f /var/log/nginx/agent.nb-studio.net.error.log ``` **SSL hibĂĄk** ```bash # Certificate megĂșjĂ­tĂĄsa sudo certbot renew # Nginx reload sudo systemctl reload nginx ``` **Database connection error** ```bash # PostgreSQL fut? sudo systemctl status postgresql # Kapcsolat teszt psql -h localhost -U agent_user -d agent_db ``` --- **✅ Production környezet kĂ©sz! agent.nb-studio.net mƱködik! 🎉**