User Tools

Site Tools


aufsetzen_raspberry_lokal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
aufsetzen_raspberry_lokal [2026/06/11 20:20] nininaufsetzen_raspberry_lokal [2026/06/12 21:52] (current) ninin
Line 1: Line 1:
-1. Betriebssystem auf SD-Karte flashen+====1. Betriebssystem auf SD-Karte flashen====
  
-2. Hochfahren, Locale, Netzwerk und SSH einrichten+====2. Hochfahren, Locale, Netzwerk und SSH einrichten====
  
-3. Git installieren+====3. Git installieren====
   sudo apt update   sudo apt update
   sudo apt upgrade   sudo apt upgrade
Line 9: Line 9:
   git --version   git --version
      
-4. Git einrichten (ssh)+====4. Git einrichten (ssh)====
   git config --global user.name [NAME]   git config --global user.name [NAME]
   git config --global user.email [EMAIL]   git config --global user.email [EMAIL]
Line 16: Line 16:
 Schlüssel kopieren und bei Codeberg unter Profilbild -> Settings -> SSH- / GPG-Keys -> Add Key Schlüssel kopieren und bei Codeberg unter Profilbild -> Settings -> SSH- / GPG-Keys -> Add Key
  
-5. Projektverzeichnis erstellen:+====5. Projektverzeichnis erstellen:====
  
   mkdir sese_project   mkdir sese_project
  
-6. Klonen Git-Repository:+====6. Klonen Git-Repository:====
  
   git clone ssh://git@codeberg.org/faeunin/serious-seeds.git   git clone ssh://git@codeberg.org/faeunin/serious-seeds.git
  
-5. Virtuelle Umgebung+====7. Virtuelle Umgebung====
  
   cd sese_project/serious-seeds   cd sese_project/serious-seeds
Line 30: Line 30:
   source env/bin/activate   source env/bin/activate
  
-6. Requirements installieren+====8. Requirements installieren====
  
   pip install -r app/requirements.txt   pip install -r app/requirements.txt
  
-7Umgebungsvariablen setzen - .env-file? +====9. .env-file für Umgebungsvariablen anlegen==== 
-  export DJANGO_ENV=production +  nano .env 
-  export POSTGRES_DB=<db> +   
-  export POSTGRES_USER=<user> +mit folgendem Inhalt: 
-  export POSTGRES_PASSWORD=<pw>+   
 +  DJANGO_ENV=production 
 +   
 +  SECRET_KEY=[KEY] 
 +   
 +  DEBUG=False 
 +   
 +  POSTGRES_DB=[DB_NAME] 
 +  POSTGRES_USER=[DB_USER] 
 +  POSTGRES_PASSWORD=[DB_PW] 
 +  POSTGRES_HOST=localhost 
 +  POSTGRES_PORT=5432
  
-8Datenbank erstellen+====10Postgres installieren==== 
 +  sudo apt install postgresql postgresql-contrib libpq-dev -y
  
-9Superuser erstellen+====11Datenbank erstellen==== 
 +  sudo -i -u postgres psql
  
-10. Dump laden+  CREATE DATABASE [DB_NAME]; 
 +   
 +  CREATE USER [DB_USER] WITH PASSWORD '[DB_PW]'; 
 +   
 +  ALTER ROLE [DB_USER] SET client_encoding TO 'utf8'; 
 +  ALTER ROLE [DB_USER] SET default_transaction_isolation TO 'read committed'; 
 +  ALTER ROLE [DB_USER] SET timezone TO 'UTC'; 
 +   
 +  GRANT ALL PRIVILEGES ON DATABASE [DB_NAME] TO [DB_USER]; 
 +   
 +  ALTER DATABASE [DB_NAME] OWNER TO [DB_USER]; 
 +   
 +  \q
  
-11Testenlässt sich der dev-server starten? +====12DB-Backup auf Raspberry kopieren==== 
-  python3 manage.py runserver 0.0.0.0:8000+ 
 +  scp /pfad/zur/datei/auf/dem/laptop/dump.sql benutzername@IP_DES_PI:/pfad/auf/dem/pi/ 
 + 
 +====13. Dump laden==== 
 +  pg_restore -h localhost -p 5432 -U [DB_USER] -d [DB_NAME] --no-owner --no-acl /path/to/dump.sql 
 + 
 +====14. Hinzufügen IP zu ALLOWED_HOSTS in settings.py==== 
 + 
 +====15. Static Files==== 
 +  python manage.py collectstatic 
 + 
 +Rechte für Nginx auf das staticfiles-Verzeichnis vergeben: 
 +  sudo chown -R :www-data [...]/sese_project/serious-seeds/app/staticfiles/ 
 +  sudo chmod -R 755 [...]/sese_project/serious-seeds/app/staticfiles/ 
 +  sudo chmod o+x /home/[SYSTEMUSER] 
 +   
 +====16. Nginx==== 
 + 
 +  sudo apt install nginx -y 
 +   
 +  sudo nano /etc/nginx/sites-available/seriousseeds 
 +   
 +with following content: 
 + 
 +  server { 
 +      listen 80; 
 +      server_name <Raspberry_Pi_IP>; 
 +   
 +      location / { 
 +          proxy_pass http://unix:/run/gunicorn/gunicorn.sock:/; 
 +          proxy_set_header Host $host; 
 +          proxy_set_header X-Real-IP $remote_addr; 
 +          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
 +      } 
 +   
 +      location /static/ { 
 +          alias </path/to/staticfiles/>; 
 +      } 
 +  } 
 + 
 +Next, enable the configuration: 
 +  sudo ln -s /etc/nginx/sites-available/seriousseeds /etc/nginx/sites-enabled/ 
 +  sudo nginx -t 
 +  sudo systemctl restart nginx 
 + 
 +Check: 
 +  sudo nginx -T | sed -n '1,200p' | grep -n 'proxy_pass\|upstream' 
 + 
 +====17. Gunicorn==== 
 +   
 + 
 +  sudo nano /etc/systemd/system/gunicorn.service 
 + 
 +content: 
 +  [Unit] 
 +   
 +  Description=gunicorn daemon for Django 
 +  After=network.target 
 +   
 +  [Service] 
 +  User=[SYSTEMUSER] 
 +  Group=www-data 
 +  RuntimeDirectory=gunicorn 
 +  WorkingDirectory=[...]/sese_project/serious-seeds/app 
 +  ExecStart=[...]/sese_project/serious-seeds/env/bin/gunicorn --workers 5 --threads 2 --timeout 60 --max-requests 1000 --max-requests-jitter 100 --bind unix:/run/gunicorn/gunicorn.sock seriousseeds.wsgi:application 
 +   
 +  [Install] 
 +  WantedBy=multi-user.target
  
-12. +Start and enable the service: 
 +  sudo systemctl start gunicorn 
 +  sudo systemctl enable gunicorn
aufsetzen_raspberry_lokal.1781209216.txt.gz · Last modified: by ninin