Update readme.md
This commit is contained in:
parent
adf144ab30
commit
32a13476f5
1 changed files with 121 additions and 104 deletions
225
readme.md
225
readme.md
|
|
@ -1,16 +1,17 @@
|
|||
# Umfassende Anleitung: Moodle auf STACKIT Cloud Foundry
|
||||
|
||||
Diese Anleitung dokumentiert den gesamten Prozess, um eine Moodle-Instanz auf STACKIT Cloud Foundry zu deployen. Sie umfasst die Ersteinrichtung der CF-Umgebung, die Vorbereitung der Moodle-Anwendung inklusive aller notwendigen Anpassungen für den Proxy- und CDN-Betrieb sowie die Konfiguration für eine externe Datenbank, S3-Dateispeicher, Redis-Caching und Autoskalierung.
|
||||
Diese Anleitung dokumentiert den gesamten Prozess, um eine Moodle-Instanz auf STACKIT Cloud Foundry zu deployen. Sie ist als allgemeingültige Vorlage konzipiert und verwendet Platzhalter, die an Ihre Umgebung angepasst werden müssen.
|
||||
|
||||
## Architektur
|
||||
|
||||
Die folgende Abbildung zeigt die Architektur der Moodle-Umgebung auf STACKIT als Mermaid-Diagramm.
|
||||
Die folgende Abbildung zeigt die Architektur der Moodle-Umgebung. CDN und Redis sind als optionale, aber für den Produktivbetrieb empfohlene Komponenten dargestellt.
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
A[Anwender] --> B(STACKIT DNS);
|
||||
B --> C(STACKIT CDN);
|
||||
C --> D{Cloud Foundry Router};
|
||||
B --> C(STACKIT CDN<br/>(Optional));
|
||||
C -.-> D{Cloud Foundry Router};
|
||||
B --> D;
|
||||
|
||||
subgraph Cloud Foundry Plattform
|
||||
D --> E1[Moodle Instanz 1];
|
||||
|
|
@ -19,16 +20,16 @@ graph TD
|
|||
|
||||
subgraph Backing Services
|
||||
F[(MariaDB<br/>Datenbank)];
|
||||
G[(Redis<br/>Sessions & Locks)];
|
||||
G[(Redis<br/>Sessions & Locks<br/>(Optional))];
|
||||
H[(S3 Object Storage<br/>Dateien)];
|
||||
end
|
||||
|
||||
E1 --> F;
|
||||
E1 --> G;
|
||||
E1 -.-> G;
|
||||
E1 --> H;
|
||||
|
||||
E2 --> F;
|
||||
E2 --> G;
|
||||
E2 -.-> G;
|
||||
E2 --> H;
|
||||
````
|
||||
|
||||
|
|
@ -36,20 +37,16 @@ graph TD
|
|||
|
||||
### 1.1. CLIs installieren
|
||||
|
||||
Für diese Anleitung werden zwei Command Line Interfaces (CLIs) benötigt:
|
||||
|
||||
* **Cloud Foundry CLI:** Das primäre Werkzeug zur Interaktion mit der Cloud Foundry Plattform.
|
||||
|
||||
* **Download:** [github.com/cloudfoundry/cli/releases](https://github.com/cloudfoundry/cli/releases)
|
||||
* **Download:** `https://github.com/cloudfoundry/cli/releases`
|
||||
|
||||
* **STACKIT CLI:** Wird benötigt, um STACKIT-spezifische Services wie Object Storage zu verwalten.
|
||||
* **STACKIT CLI:** Wird benötigt, um STACKIT-spezifische Services wie DNS, Object Storage und CDN zu verwalten.
|
||||
|
||||
* **Installationsanleitung:** Befolgen Sie die offizielle Anleitung unter [docs.stackit.cloud](https://docs.stackit.cloud/stackit/en/service-plans-redis-75142939.html).
|
||||
* **Installationsanleitung:** `https://docs.stackit.cloud/stackit/de/automatisieren/cli/cli-installieren-200720436.html`
|
||||
|
||||
### 1.2. Bei STACKIT Cloud Foundry anmelden
|
||||
|
||||
Nach der Installation des CF CLI müssen Sie sich bei der STACKIT Cloud Foundry API anmelden.
|
||||
|
||||
* **API-Endpunkt:** `https://api.cf.eu01.stackit.cloud`
|
||||
|
||||
* **Login-Befehl:**
|
||||
|
|
@ -60,25 +57,11 @@ Nach der Installation des CF CLI müssen Sie sich bei der STACKIT Cloud Foundry
|
|||
|
||||
### 1.3. Organisation und Space erstellen
|
||||
|
||||
Eine "Organisation" ist der höchste Mandant, ein "Space" eine Umgebung (z.B. Entwicklung, Produktion).
|
||||
|
||||
1. **Organisation erstellen:**
|
||||
|
||||
```bash
|
||||
cf create-org DEINE_ORGANISATION
|
||||
```
|
||||
|
||||
2. **Space erstellen:**
|
||||
|
||||
```bash
|
||||
cf create-space produktion -o DEINE_ORGANISATION
|
||||
```
|
||||
|
||||
3. **Ziel festlegen:**
|
||||
|
||||
```bash
|
||||
cf target -o DEINE_ORGANISATION -s produktion
|
||||
```
|
||||
```bash
|
||||
cf create-org <DEINE_ORGANISATION>
|
||||
cf create-space <DEIN_SPACE> -o <DEINE_ORGANISATION>
|
||||
cf target -o <DEINE_ORGANISATION> -s <DEIN_SPACE>
|
||||
```
|
||||
|
||||
## 2\. Moodle-Projekt lokal vorbereiten
|
||||
|
||||
|
|
@ -89,9 +72,9 @@ Eine "Organisation" ist der höchste Mandant, ein "Space" eine Umgebung (z.B. En
|
|||
wget https://packaging.moodle.org/stable500/moodle-5.0.1.tgz
|
||||
tar -xzf moodle-5.0.1.tgz
|
||||
|
||||
# Redis-Plugin für Moodle installieren
|
||||
wget https://moodle.org/plugins/download.php/29037/cachestore_redis_moodle41_2022112800.zip
|
||||
unzip cachestore_redis_moodle41_2022112800.zip
|
||||
# Redis-Plugin für Moodle installieren (Version passend zu Moodle 5.x)
|
||||
wget https://moodle.org/plugins/download.php/30019/cachestore_redis_moodle44_2024051300.zip
|
||||
unzip cachestore_redis_moodle44_2024051300.zip
|
||||
mv redis moodle/cache/stores/
|
||||
|
||||
# S3 Object File System Plugin installieren
|
||||
|
|
@ -102,8 +85,6 @@ cd ..
|
|||
|
||||
### 2.2. Buildpack- & System-Workarounds einrichten
|
||||
|
||||
Diese Schritte sind für das `cloudfoundry/php-buildpack` notwendig.
|
||||
|
||||
```bash
|
||||
# Web-Verzeichnis festlegen und PHP-Version auf 8.2 erzwingen
|
||||
echo '{"WEBDIR": ".", "PHP_VERSION": "{PHP_82_LATEST}"}' > moodle/.bp-config/options.json
|
||||
|
|
@ -128,42 +109,105 @@ ln -s /tmp/php-fpm.pid moodle/php/var/run/php-fpm.pid
|
|||
|
||||
#### 3.1. Object Storage Bucket erstellen (STACKIT CLI)
|
||||
|
||||
Verwenden Sie das STACKIT CLI, um einen Bucket zu erstellen.
|
||||
|
||||
```bash
|
||||
# Erstellt einen neuen Bucket
|
||||
stackit object-storage bucket create --name <BUCKET_NAME>
|
||||
stackit object-storage bucket create --name <DEIN_S3_BUCKET_NAME>
|
||||
```
|
||||
|
||||
Anschließend benötigen Sie Zugangsdaten, um auf den Bucket zugreifen zu können.
|
||||
|
||||
```bash
|
||||
# Erstellt neue Zugangsdaten für Ihr Projekt
|
||||
# Sie müssen Ihre STACKIT Projekt-ID angeben.
|
||||
stackit object-storage credential create --project-id <DEINE_PROJEKT_ID>
|
||||
```
|
||||
|
||||
**Notieren Sie sich den ausgegebenen `accessKey` und `secretAccessKey`.** Sie werden im nächsten Schritt benötigt.
|
||||
**Notieren Sie sich den ausgegebenen `accessKey` und `secretAccessKey`.**
|
||||
|
||||
#### 3.2. Cloud Foundry Services erstellen (CF CLI)
|
||||
#### 3.2. CDN-Distribution erstellen (STACKIT CLI, Optional)
|
||||
|
||||
Diese Befehle legen die für Moodle notwendigen CF-Services an.
|
||||
1. **CDN-Distribution erstellen:**
|
||||
|
||||
```bash
|
||||
# Ersetzen Sie <DEINE_PROJEKT_ID>, <DEINE_INTERNE_CF_ROUTE> und <DEINE_MOODLE_DOMAIN>.
|
||||
stackit curl -X POST --body '{
|
||||
"name": "<DEIN_CDN_DISTRIBUTION_NAME>",
|
||||
"origin": {
|
||||
"path": "/",
|
||||
"hostname": "<DEINE_INTERNE_CF_ROUTE>",
|
||||
"port": 443
|
||||
},
|
||||
"originRequestHeaders": [
|
||||
{
|
||||
"name": "Host",
|
||||
"values": [
|
||||
"<DEINE_MOODLE_DOMAIN>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Cache-Control",
|
||||
"values": [
|
||||
"no-cache, no-store, must-revalidate"
|
||||
]
|
||||
}
|
||||
],
|
||||
"enabled": true
|
||||
}' /cdn/v1beta/projects/<DEINE_PROJEKT_ID>/distributions
|
||||
```
|
||||
|
||||
**Notieren Sie sich die `id` der Distribution aus der Antwort.**
|
||||
|
||||
2. **CDN-Standard-Domain auslesen:**
|
||||
|
||||
```bash
|
||||
# Ersetzen Sie <DEINE_PROJEKT_ID> und <DISTRIBUTION_ID>.
|
||||
stackit curl -X GET /cdn/v1beta/projects/<DEINE_PROJEKT_ID>/distributions/<DISTRIBUTION_ID>
|
||||
```
|
||||
|
||||
**Notieren Sie sich den Wert des `domain`-Feldes aus der Antwort. Dies ist Ihr CNAME-Ziel.**
|
||||
|
||||
3. **Benutzerdefinierte Domain hinzufügen:**
|
||||
|
||||
```bash
|
||||
# Ersetzen Sie <DEINE_PROJEKT_ID> und <DISTRIBUTION_ID>.
|
||||
stackit curl -X POST --body '{
|
||||
"domain": "<DEINE_MOODLE_DOMAIN>"
|
||||
}' /cdn/v1beta/projects/<DEINE_PROJEKT_ID>/distributions/<DISTRIBUTION_ID>/domains
|
||||
```
|
||||
|
||||
#### 3.3. DNS-Einträge konfigurieren (STACKIT CLI)
|
||||
|
||||
1. **Zone-ID ermitteln:**
|
||||
|
||||
```bash
|
||||
stackit dns zone list
|
||||
```
|
||||
|
||||
Notieren Sie sich die `ID` Ihrer Domain-Zone.
|
||||
|
||||
2. **CNAME-Eintrag erstellen:**
|
||||
|
||||
```bash
|
||||
# Für den Betrieb MIT CDN
|
||||
# <DEIN_CDN_ENDPOINT> ist die Standard-Domain, die Sie in Schritt 3.2 ausgelesen haben.
|
||||
stackit dns record-set create --zone-id <DEINE_ZONE_ID> --name <DEINE_MOODLE_DOMAIN> --type CNAME --ttl 300 --records "<DEIN_CDN_ENDPOINT>."
|
||||
|
||||
# Für den Betrieb OHNE CDN (falls benötigt)
|
||||
stackit dns record-set create --zone-id <DEINE_ZONE_ID> --name <DEINE_INTERNE_CF_ROUTE> --type CNAME --ttl 300 --records "console.apps.01.cf.eu01.stackit.cloud."
|
||||
```
|
||||
|
||||
#### 3.4. Cloud Foundry Services erstellen (CF CLI)
|
||||
|
||||
```bash
|
||||
# Datenbank-Service
|
||||
cf create-service <dein-mariadb-service> <plan> moodle-demo-mariadb
|
||||
cf create-service <dein-mariadb-service> <plan> <DEINE_MARIADB_INSTANZ>
|
||||
|
||||
# Redis-Service (Optional)
|
||||
cf create-service appcloud-redis7 redis-4.16.100-replica moodle-redis
|
||||
cf create-service appcloud-redis7 redis-4.16.100-replica <DEINE_REDIS_INSTANZ>
|
||||
|
||||
# Autoscaler-Service
|
||||
cf create-service autoscaler autoscaler-free-plan moodle-autoscaler
|
||||
cf create-service autoscaler autoscaler-free-plan <DEIN_AUTOSCALER_INSTANZ>
|
||||
|
||||
# User-Provided Service für die S3-Credentials aus dem vorherigen Schritt
|
||||
cf create-user-provided-service moodle-s3-credentials -p '{
|
||||
"access_key": "DEIN_ZUVOR_GENERIERTER_ACCESS_KEY",
|
||||
"secret_key": "DEIN_ZUVOR_GENERIERTER_SECRET_KEY",
|
||||
"bucket": "DEIN_ZUVOR_GENERIERTES_BUCKET",
|
||||
# User-Provided Service für die S3-Credentials
|
||||
cf create-user-provided-service <DEINE_S3_CUPS_INSTANZ> -p '{
|
||||
"access_key": "<DEIN_ZUVOR_GENERIERTER_ACCESS_KEY>",
|
||||
"secret_key": "<DEIN_ZUVOR_GENERIERTER_SECRET_KEY>",
|
||||
"bucket": "<DEIN_S3_BUCKET_NAME>",
|
||||
"endpoint": "https://object.storage.eu01.onstackit.cloud/"
|
||||
}'
|
||||
```
|
||||
|
|
@ -172,8 +216,6 @@ cf create-user-provided-service moodle-s3-credentials -p '{
|
|||
|
||||
#### a) Manifest-Dateien
|
||||
|
||||
Erstellen Sie zwei Manifest-Dateien, um einfach zwischen dem Betrieb mit und ohne CDN wechseln zu können.
|
||||
|
||||
**`manifest-cdn.yml` (Produktion):**
|
||||
|
||||
```yaml
|
||||
|
|
@ -185,17 +227,17 @@ applications:
|
|||
buildpack: https://github.com/cloudfoundry/php-buildpack.git
|
||||
path: moodle
|
||||
routes:
|
||||
- route: moodle.cf.demo.stackit.rocks
|
||||
- route: moodle.demo.stackit.rocks
|
||||
- route: <DEINE_INTERNE_CF_ROUTE>
|
||||
- route: <DEINE_MOODLE_DOMAIN>
|
||||
env:
|
||||
USE_CDN: 'true'
|
||||
WWW_ROOT: "https://moodle.demo.stackit.rocks"
|
||||
WWW_ROOT: "https://<DEINE_MOODLE_DOMAIN>"
|
||||
BP_PHP_LOG_LEVEL: WARNING
|
||||
services:
|
||||
- moodle-demo-mariadb
|
||||
- moodle-redis
|
||||
- moodle-autoscaler
|
||||
- moodle-s3-credentials
|
||||
- <DEINE_MARIADB_INSTANZ>
|
||||
- <DEINE_REDIS_INSTANZ>
|
||||
- <DEIN_AUTOSCALER_INSTANZ>
|
||||
- <DEINE_S3_CUPS_INSTANZ>
|
||||
autoscaling:
|
||||
min_instances: 2
|
||||
max_instances: 4
|
||||
|
|
@ -225,16 +267,16 @@ applications:
|
|||
buildpack: https://github.com/cloudfoundry/php-buildpack.git
|
||||
path: moodle
|
||||
routes:
|
||||
- route: moodle.cf.demo.stackit.rocks
|
||||
- route: <DEINE_INTERNE_CF_ROUTE>
|
||||
env:
|
||||
USE_CDN: 'false'
|
||||
WWW_ROOT: "https://moodle.cf.demo.stackit.rocks"
|
||||
WWW_ROOT: "https://<DEINE_INTERNE_CF_ROUTE>"
|
||||
BP_PHP_LOG_LEVEL: WARNING
|
||||
services:
|
||||
- moodle-demo-mariadb
|
||||
- moodle-redis
|
||||
- moodle-autoscaler
|
||||
- moodle-s3-credentials
|
||||
- <DEINE_MARIADB_INSTANZ>
|
||||
- <DEINE_REDIS_INSTANZ>
|
||||
- <DEIN_AUTOSCALER_INSTANZ>
|
||||
- <DEINE_S3_CUPS_INSTANZ>
|
||||
autoscaling:
|
||||
min_instances: 1
|
||||
max_instances: 4
|
||||
|
|
@ -243,14 +285,11 @@ applications:
|
|||
|
||||
#### b) Dynamische `config.php`
|
||||
|
||||
Kopieren Sie `moodle/config-dist.php` zu `moodle/config.php` und ersetzen Sie den gesamten Inhalt mit dieser finalen, dynamischen Vorlage.
|
||||
Kopieren Sie `moodle/config-dist.php` zu `moodle/config.php` und ersetzen Sie den Inhalt mit dieser Vorlage.
|
||||
|
||||
```php
|
||||
<?php // Moodle configuration file
|
||||
|
||||
// =========================================================================
|
||||
// UMWELTSPEZIFISCHE KONFIGURATION
|
||||
// =========================================================================
|
||||
$useCdn = (getenv('USE_CDN') === 'true');
|
||||
$wwwRoot = getenv('WWW_ROOT');
|
||||
|
||||
|
|
@ -258,38 +297,28 @@ unset($CFG);
|
|||
global $CFG;
|
||||
$CFG = new stdClass();
|
||||
|
||||
//=========================================================================
|
||||
// 1. WEBSEITE, VERZEICHNISSE & PROXY EINSTELLUNGEN
|
||||
//=========================================================================
|
||||
$CFG->wwwroot = $wwwRoot;
|
||||
$CFG->dirroot = __DIR__;
|
||||
$CFG->dataroot = '/tmp/moodledata';
|
||||
$CFG->admin = 'admin';
|
||||
$CFG->directorypermissions = 0777;
|
||||
|
||||
// --- Proxy-Einstellungen ---
|
||||
$CFG->sslproxy = 1;
|
||||
$CFG->slasharguments = false;
|
||||
if ($useCdn) {
|
||||
// Diese Einstellungen sind NUR für den CDN-Betrieb notwendig, um den "reverseproxyabused"-Fehler zu vermeiden.
|
||||
$CFG->reverseproxy = 1;
|
||||
$CFG->trustedproxies = '127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 185.124.192.185';
|
||||
$CFG->trustedproxies = '127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, <IP_DES_CDN_KNOTENS>';
|
||||
}
|
||||
|
||||
// --- Workaround: Manuelles Erstellen des dataroot-Verzeichnisses ---
|
||||
if (!file_exists($CFG->dataroot)) {
|
||||
@mkdir($CFG->dataroot, $CFG->directorypermissions, true);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// 2. DATENBANK-SETUP
|
||||
//=========================================================================
|
||||
$CFG->dbtype = 'mariadb';
|
||||
$CFG->dblibrary = 'native';
|
||||
$CFG->prefix = 'mdl_';
|
||||
$CFG->dboptions = array ('dbpersist' => 0, 'dbcollation' => 'utf8mb4_unicode_ci');
|
||||
|
||||
// --- Lese Service-Konfigurationen aus VCAP_SERVICES ---
|
||||
$vcap_services_json = getenv('VCAP_SERVICES');
|
||||
if ($vcap_services_json) {
|
||||
$vcap_services = json_decode($vcap_services_json, true);
|
||||
|
|
@ -310,9 +339,9 @@ if ($vcap_services_json) {
|
|||
}
|
||||
}
|
||||
|
||||
// Redis (Optional, für bessere Performance)
|
||||
// Redis
|
||||
$redis_service_key = null;
|
||||
if (isset($vcap_services['appcloud-redis60'])) { $redis_service_key = 'appcloud-redis60'; }
|
||||
if (isset($vcap_services['appcloud-redis7'])) { $redis_service_key = 'appcloud-redis7'; }
|
||||
if ($redis_service_key && isset($vcap_services[$redis_service_key][0]['credentials'])) {
|
||||
$redis_creds = $vcap_services[$redis_service_key][0]['credentials'];
|
||||
$CFG->session_handler_class = '\cachestore_redis\session_handler';
|
||||
|
|
@ -325,7 +354,7 @@ if ($vcap_services_json) {
|
|||
// S3
|
||||
if (isset($vcap_services['user-provided'])) {
|
||||
foreach ($vcap_services['user-provided'] as $service) {
|
||||
if ($service['name'] === 'moodle-s3-credentials') {
|
||||
if ($service['name'] === '<DEINE_S3_CUPS_INSTANZ>') {
|
||||
$s3_creds = $service['credentials'];
|
||||
$CFG->objectfs_s3_key = $s3_creds['access_key'];
|
||||
$CFG->objectfs_s3_secret = $s3_creds['secret_key'];
|
||||
|
|
@ -336,24 +365,17 @@ if ($vcap_services_json) {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Fallback auf Datenbank-Sessions, falls Redis nicht konfiguriert ist
|
||||
if (empty($CFG->session_handler_class)) {
|
||||
$CFG->session_handler_class = '\core\session\database';
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// SESSION COOKIE HANDLING (bedingt durch CDN)
|
||||
//=========================================================================
|
||||
if ($useCdn) {
|
||||
$CFG->cookiepath = '/';
|
||||
$CFG->cookiedomain = 'moodle.demo.stackit.rocks';
|
||||
$CFG->cookiedomain = '<DEINE_MOODLE_DOMAIN>';
|
||||
$CFG->cookiesecure = 1;
|
||||
$CFG->cookiehttponly = 1;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// DO NOT ADD ANYTHING BELOW THIS LINE
|
||||
//=========================================================================
|
||||
require_once(__DIR__ . '/lib/setup.php');
|
||||
```
|
||||
|
||||
|
|
@ -367,15 +389,10 @@ Wählen Sie das gewünschte Manifest für Ihr Deployment aus.
|
|||
cf push -f manifest-cdn.yml
|
||||
```
|
||||
|
||||
**Hinweis:** Der CDN-Fall hat sich als problematisch erwiesen. Wenn Fehler auftreten, liegt es wahrscheinlich an den Caching- oder Header-Einstellungen im CDN selbst, die hier nicht behandelt werden können.
|
||||
|
||||
**Ohne CDN (Test / Direkter Zugriff):**
|
||||
|
||||
```bash
|
||||
cf push -f manifest-no-cdn.yml
|
||||
```
|
||||
|
||||
Nach Abschluss des Deployments und dem Durchlaufen der Moodle-Web-Installation ist Ihre Instanz einsatzbereit.
|
||||
|
||||
```
|
||||
```
|
||||
Nach Abschluss des Deployments und dem Durchlaufen der Moodle-Web-Installation ist Ihre Instanz einsatzbereit.
|
||||
Loading…
Reference in a new issue