Einrichtung von BackBlaze S3 mit BunnyCDN

Es hat ewig gedauert, bis ich herausgefunden habe, wie man all das umsetzt, daher wollte ich diese Anleitung erstellen, um es anderen Leuten zu erleichtern. Das Ausliefern deiner Bilder auf diese Weise soll deine Website schneller laden lassen. Meine Discourse-Installation kombiniert einen DigitalOcean Droplet, BackBlaze B2 S3, BunnyCDN und die kostenlose Version von Cloudflare.

Ich habe mich nach etwas Recherche zu Zuverlässigkeit, Preisen und Benchmarks für diese Dienste entschieden. Sie schienen die besten Optionen für mich zu sein. Cloudflare hilft bei der Sicherheit, kann die Seite jedoch leicht verlangsamen, soweit ich das verstanden habe – du solltest das also selbst prüfen. Backblaze hat Partnerschaften sowohl mit Cloudflare als auch mit Bunny, die einen kostenlosen Datentransfer ermöglichen.

Obwohl Cloudflare als CDN bezeichnet wird, funktioniert es nicht wie ein herkömmliches CDN und wird wahrscheinlich nicht allein ausreichen, um S3 mit Discourse einzurichten. Du wirst möglicherweise einen weiteren CDN-Anbieter benötigen; BunnyCDN funktioniert bei mir gut. Falls jemand es erfolgreich nur mit Cloudflare geschafft hat, lass es mich bitte wissen :stuck_out_tongue:

So richtest du Uploads auf S3 ein:
Zuerst musst du dich bei Backblaze anmelden, dann Buckets erstellen und die Details in die Discourse-Einstellungen eingeben:

Anschließend meldest du dich bei BunnyCDN an und befolgst diese Anleitung:

bunny.net - The Global Edge Platform that truly Hops (Empfehlungslink, ich erhalte 20 $ Gutschrift auf meiner Rechnung)

Nachdem du deine BunnyCDN-Pull-Zone erstellt hast, musst du die korrekte URL ermitteln, die du in die Discourse-Admin-Backend-Einstellung für „s3 cdn url" eingibst. Gehe zu deinem BunnyCDN-Dashboard > Pull Zones > Manage Pull Zones > klicke auf deine Zone > kopiere die URL neben „host name".

Die URL sollte ungefähr so aussehen: example.b-cdn.net, aber du musst sicherstellen, dass du https:// davor setzt, also: https://example.b-cdn.net

Speichere die Änderungen im Bereich der Discourse-Admin-Einstellungen.

Drücke in deinem Browser auf deiner Discourse-Website zweimal Strg+F5.

Führe einen Test durch, indem du ein Bild im Discourse-Text-Composer hochlädst. Untersuche das Testbild-Element oder sieh dir die Bildquelle an, um sicherzustellen, dass es funktioniert hat. Die URL sollte sich von deiner normalen Domain unterscheiden und etwa so aussehen: example.b-cdn.net / Dateiname

Ab jetzt wird jedes hochgeladene Bild in deinem Backblaze-Bucket gespeichert und belegt keinen Speicherplatz auf deinem DigitalOcean-Droplet :stuck_out_tongue:

Uploads auf S3 sichern
Wenn du deine Discourse-Backups in deinem Backblaze-Bucket speichern möchtest, musst du Folgendes tun:

In der Anleitung, die ich weiter oben in diesem Thread verlinkt habe, beachte, wie erklärt wird, dass du zwei separate Buckets benötigst. Ein Bucket ist öffentlich; dies ist dein Upload-Bucket, in dem Benutzer Bilder auf deinem Forum hochladen können. Der andere Bucket ist privat; dies ist dein Backup-Bucket. Es ist wichtig, automatisierte Backups von Discourse zu erstellen, falls etwas kaputtgeht. Dann kannst du dein Backup laden und es reparieren.

Auf deinem BunnyCDN-Dashboard solltest du eine zweite Pull-Zone erstellen. Deine erste Pull-Zone war für Uploads, diese neue Pull-Zone ist für Backups.

bunnycdn dashboard > pull zones > add pull zone

Befolge dieselbe Anleitung, die ich früher verlinkt habe: „How to Speed up your Backblaze B2 file delivery with BunnyCDN" von BunnyCDN, verknüpfe diesmal jedoch die neue Pull-Zone mit deinem Backup-Bucket statt mit deinem Upload-Bucket.

Ich empfehle, auf der Seite zur Erstellung einer BunnyCDN-Pull-Zone das „High Volume Tier 5 /TB" zu verwenden. Ich denke, für Backups ist das teurere/schnellere „Standard Tier 10 /TB", das ich für meinen Upload-Bucket genutzt habe, nicht notwendig.

Richte deine Backup-Einstellungen im Bereich der Discourse-Admin-Einstellungen ein. „Backup location" sollte auf S3 gesetzt sein und „s3 endpoint" sollte auf deinen Backblaze-Endpunkt zeigen, etwas wie:
s3.us-west-002.backblazeb2.com

Drücke zweimal Strg+F5 auf deiner Website, um den Cache zu leeren.

Starte ein Backup und warte, bis es abgeschlossen ist. Warte dann 5 Minuten und prüfe deinen Backblaze-Backup-Ordner; du solltest das neue Backup dort sehen.

Ältere Bilder migrieren:
Dieser Schritt ist optional, aber empfehlenswert, besonders wenn dein Server wenig Speicherplatz hat. Du hast also alles für neue Bild-Uploads eingerichtet, aber ältere Bilder können ebenfalls in deine Buckets übertragen werden. Damit dieser Prozess funktioniert, musst du Folgendes befolgen:

Einrichten von Cloudflare CDN
Dieser Schritt ist optional, da Backblaze eine Partnerschaft eingegangen ist, die den Datentransfer zu Bunny ebenfalls kostenlos macht. Für zusätzliche Sicherheit und weitere Funktionen kannst du den Datenverkehr jedoch zunächst über Cloudflare leiten und dann Bunny das Abrufen der Daten von dem Ort lassen, an dem Cloudflare sie hinterlegt.

https://help.backblaze.com/hc/en-us/articles/217666928-Using-Backblaze-B2-with-the-Cloudflare-CDN

8 „Gefällt mir“

Just wanted to say I have done what Bill did, and confirm it works! The only catch is that it works for new files and not the old ones. The cool thing about Bill’s method is that it didn’t even need a rebuild. However, I hope that someone figures out how to get the old files to work with S3 too.

Backups don’t work either btw. At least not for me and I did the same exact thing as Bill.

5 „Gefällt mir“

You can migrate old files using the rake task.

1 „Gefällt mir“

If you mean this command, I already tried it and it didn’t upload the old assets:

sudo -E -u discourse bundle exec rake s3:upload_assets

I rebaked my posts too, but no dice.

The task is:

cd /var/discourse
./launcher enter app
rails c
rake uploads:migrate_to_s3
cd /var/discourse
./launcher enter app
rails c
rake uploads:migrate_from_s3

Does this work for you @AntiMetaman ?
I will add it to the guide if so.

I will try to figure out how to get backups to work correctly, and update the guide with that as well. I know for sure I need to make a second pull zone.

I have backups working fine with backblaze … What issue are you facing?

1 „Gefällt mir“

My backups are working fine with this method as well. You must have something set wrong. I will update the guide right now on how I set up backups. @AntiMetaman

I’m sorry, I don’t follow this? How come I have something working fine when you are suggesting that I have something set wrong?

He’s talking to me @itsbhanusharma. My backups aren’t working. My configuration is the same as Bill’s. I didn’t use a separate pull zone for the backup bucket though so maybe that’s why. I just have the name of the backup bucket in the env variables.

I’ll try Bhanu’s suggestion to migrate the s3 assets later.

I created two pull zones, one for each of the buckets (upload and backup). I started a backup from my admin panel but it failed. The only thing that Discourse knows is the name of the backup bucket.

DISCOURSE_S3_CDN_URL: https://duelistsunite.b-cdn.net
DISCOURSE_S3_BUCKET: s3omega
DISCOURSE_S3_BACKUP_BUCKET: s3omegabackup
DISCOURSE_BACKUP_LOCATION: s3

Not sure what I’m missing here. Is there a S3_CDN_BACKUP_URL ? given that the url is different for the backup.

@itsbhanusharma Also, I tried your method, but migrate_from_S3 is undefined.

Also, I wasn’t sure if you meant migrate_to_s3 so I tried that too, but that was also undefined.

I’m sorry for the confusion, I meant rake uploads:migrate_to_s3

1 „Gefällt mir“

It aborts the rake it seems because it adds the amazonaws.com to the url when in fact, that is incorrect. This is the problem. If you use a S3 that’s not amazon, then the rake won’t work since it’s hardcoded to change the url.

1 „Gefällt mir“

Can you confirm/deny if you added settings to the app.yml env section or did you add the settings to admin > settings page?

I have my backups working with S3 as well. So I have old and new uploads working with S3. I am using Cloudflare for SSL, DDoS, BunnyCDN for the upload and backup pull zones, and BackBlaze for the S3 storage. I’m all good now!

Note that it’s better to define the env variables in the app.yml as shown here: Using Object Storage for Uploads (S3 Clones)

Then rebuild so that the S3 configuration is globally defined and not just in admin panel. This way, when you migrate old files to s3, you can do it easier with 3 commands:

./launcher enter app
rake uploads:migrate_to_s3
rake posts:rebake

3 „Gefällt mir“

Not sure what I’m missing here. Is there a S3_CDN_BACKUP_URL ? given that the url is different for the backup.

Did you resolve this question? I’m also not clear where to put the url for the pull zone that points to the backup bucket.

Edit: Am I correct in realizing that the CDN is only needed for the uploads bucket? The guide on this topic suggests a second CDN pull zone should be created for the backup bucket. If that’s wrong, perhaps the guide should be updated @Bill

Apparently it only needs the backup bucket name. From the name it can get the backup S3 url since it will be the same as the upload except for the name difference. This is why you don’t have to define a separate S3 backup url. This is of course assuming that both buckets are in the same S3 service.

But if the backup bucket is private, how would the CDN access it? I’m new to CDN’s and may be missing something, but I suspect that Discourse doesn’t use the CDN at all to back up.

They do. I went to my backup bucket and I see the backup uploaded there. It’s private but discourse can access it. You can setup permissions if the url is there. You can make it so only your site can access the bucket too or any https source.

Can you verify that the backup went through the CDN, vs directly from your Discourse install to BackBlaze B2?