BackBlaze S3とBunnyCDNをセットアップ

これらすべてをどう行うかを見つけるのに永遠がかかったので、他の人にもっと簡単にできるようにこのガイドを作成しました。この方法で画像を提供することで、Web サイトの読み込みが速くなるとされています。私の Discourse 設定は、DigitalOcean のドロペット、BackBlaze B2 S3、BunnyCDN、そして無料版の Cloudflare を組み合わせています。

信頼性、価格、ベンチマークについて少し調査した後、これらのサービスを選びました。私にとって最適な選択肢に見えました。Cloudflare はセキュリティに役立ちますが、私の理解ではサイトが少し遅くなる可能性もあるため、それについても調べてみてください。Backblaze は Cloudflare と Bunny との提携により、無料のデータ転送を可能にしています。

Cloudflare は CDN と呼ばれていますが、通常の CDN のように機能するわけではなく、おそらく S3 と Discourse の設定には単独では機能しないでしょう。別の CDN プロバイダーが必要になる可能性があります。私には BunnyCDN がよく機能しています。もし誰かが Cloudflare だけで成功させたことがあれば、教えてください :stuck_out_tongue:

S3 へのアップロード設定方法:
まず、Backblaze に登録し、バケットを作成してから、Discourse の設定に詳細を入力する必要があります。

次に、BunnyCDN に登録して、このガイドに従ってください。

https://bunnycdn.com/?ref=qcp86164sq(紹介リンクです。私の請求書に 20 ドルのクレジットが適用されます)

BunnyCDN のプルゾーンを作成したら、Discourse の管理バックエンド設定にある「s3 cdn url」に挿入する正しい URL を取得する必要があります。BunnyCDN ダッシュボードへ → プルゾーン → プルゾーンの管理 → ゾーンをクリック → 「ホスト名」の横にある URL をコピーします。

URL は例:example.b-cdn.net のようになりますが、その前に https:// を付けて https://example.b-cdn.net のようにする必要があります。

Discourse の管理設定エリアで変更を保存します。

Discourse サイトのブラウザで Ctrl+F5 を 2 回押します。

Discourse テキストコンポーザーで画像をアップロードしてテストします。テスト画像の要素を検査するか、画像のソースを表示して、正常に動作したか確認します。URL は通常のドメインとは異なり、example.b-cdn.net / ファイル名 のような形式になるはずです。

これで、誰かが画像をアップロードするたびに、その画像は Backblaze バケットに保存され、DigitalOcean ドロペットの容量を占有しなくなります :stuck_out_tongue:

S3 へのアップロードのバックアップ
Discourse のバックアップを Backblaze バケットに保存したい場合は、以下の手順を行ってください。

このスレッドの上部に投稿したガイドでは、2 つの別のバケットが必要であることが説明されています。1 つ目のバケットはパブリックで、ユーザーがフォーラムに画像をアップロードするためのアップロード用バケットです。もう 1 つのバケットはプライベートで、バックアップ用バケットです。何か問題が起きた場合に備えて、Discourse の自動バックアップを作成することが重要です。そうすれば、バックアップをロードして修正できます。

BunnyCDN ダッシュボードで、2 番目のプルゾーンを作成してください。最初のプルゾーンはアップロード用でしたが、新しいプルゾーンはバックアップ用になります。

bunnycdn ダッシュボード → プルゾーン → プルゾーンの追加

以前リンクしたガイド「BunnyCDN で Backblaze B2 ファイル配信を高速化する方法」に従ってください。ただし、今回は新しいプルゾーンをアップロード用バケットではなく、バックアップ用バケットにリンクします。

BunnyCDN のプルゾーン作成ページでは、「高ボリュームティア 5$/TB」の使用をお勧めします。バックアップには、アップロード用バケットで私が使用した高価で高速な「スタンダードティア 10$/TB」は必要ないと思います。

Discourse の管理設定エリアでバックアップ設定を行います。「backup location」は S3 に設定し、「s3 endpoint」は Backblaze で設定したもの(例:s3.us-west-002.backblazeb2.com)を指すようにします。

Web サイトで CTRL+F5 を 2 回押してキャッシュをクリアします。

バックアップを開始し、完了するまで待ちます。その後、5 分待って Backblaze のバックアップフォルダを確認してください。新しいバックアップが表示されるはずです。

古い画像の移行:
この手順は必須ではありませんが、サーバーのストレージが不足している場合は特に推奨されます。新しい画像のアップロード設定は完了しましたが、古い画像もバケットに転送できます。このプロセスを機能させるには、以下の手順に従ってください。

Cloudflare CDN の設定
この手順は必須ではありません。Backblaze の提携により、Bunny へのデータ転送が無料になっているためです。ただし、追加のセキュリティやその他の機能のために、データをまず Cloudflare を経由させ、その後 Bunny が Cloudflare からデータをプルするように設定することもできます。

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

「いいね!」 8

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

You can migrate old files using the rake task.

「いいね!」 1

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

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

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

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

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?