إعداد BackBlaze S3 مع BunnyCDN

استغرق مني وقتًا طويلًا جدًا لفهم كيفية القيام بكل هذا، لذا أردت إعداد هذا الدليل لتسهيل الأمر على الآخرين. يُفترض أن خدمة الصور بهذه الطريقة تجعل موقعك الإلكتروني يعمل بسرعة أكبر. إعدادي لـ Discourse يجمع بين DigitalOcean droplet و BackBlaze B2 S3 و BunnyCDN والإصدار المجاني من Cloudflare.

اخترت هذه الخدمات بعد إجراء بعض الأبحاث حول الموثوقية والأسعار والمعايير. بدا أنها الخيارات الأفضل بالنسبة لي. تساعد Cloudflare في الأمان، لكنها قد تبطئ الموقع قليلاً حسب فهمي، لذا يجب عليك البحث في ذلك. لدى Backblaze شراكات مع كل من Cloudflare و Bunny تسمح بنقل البيانات مجانًا.

على الرغم من أن Cloudflare تُسمى CDN، إلا أنها لا تعمل مثل شبكات CDN العادية، وعلى الأرجح لن تعمل بمفردها لإعداد S3 مع Discourse. قد تحتاج إلى مزود CDN آخر، و Bunnycdn يعمل بشكل جيد معي. إذا نجح شخص ما في ذلك باستخدام Cloudflare فقط، فأخبرني كيف :stuck_out_tongue:

كيفية تعيين الرفع إلى S3:
أولاً، يجب عليك التسجيل في Backblaze، ثم إنشاء buckets، وإدخال التفاصيل في إعدادات Discourse:

ثم قم بالتسجيل في BunnyCDN واتبع هذا الدليل:

bunny.net - The Global Edge Platform that truly Hops (رابط إحالة، أحصل على رصيد بقيمة 20 دولارًا في فواتيري)

بعد إنشاء منطقة السحب (pull zone) الخاصة بك في BunnyCDN، تحتاج إلى الحصول على عنوان URL الصحيح لإدخاله في إعدادات لوحة تحكم Discourse الإدارية لـ “s3 cdn url”. اذهب إلى لوحة تحكم bunnycdn > مناطق السحب > إدارة مناطق السحب > انقر على منطقتك > انسخ عنوان URL بجانب “اسم المضيف”.

يجب أن يشبه عنوان URL شيئًا مثل: example.b-cdn.net، لكن يجب أن تتأكد من وضع https:// في المقدمة مثل هذا: https://example.b-cdn.net

احفظ التغييرات في منطقة إعدادات لوحة تحكم Discourse.

اضغط على ctrl+f5 مرتين في متصفحك على موقع Discourse.

قم بإجراء اختبار عن طريق رفع صورة في محرر النصوص في Discourse. افحص عنصر الصورة الاختبارية أو عرض مصدر الصورة للتأكد من نجاح العملية. يجب أن يبدو عنوان URL مختلفًا عن نطاقك العادي، ويجب أن يكون شيئًا مثل example.b-cdn.net / اسم الملف.

الآن، في كل مرة يرفع فيها شخص ما صورة، ستكون في bucket Backblaze ولن تشغل مساحة على DigitalOcean droplet :stuck_out_tongue:

نسخ احتياطي للرفع إلى S3
إذا كنت ترغب في إعداد نسخ احتياطية لـ Discourse لتذهب إلى bucket Backblaze، فعليك القيام بما يلي:

في الدليل الذي نشرته سابقًا في هذا الموضوع، انتبه إلى كيفية شرحه أنك تحتاج إلى bucketين منفصلين. bucket واحد عام، وهو bucket الرفع الخاص بك لرفع المستخدمين للصور على منتداك. والـ bucket الآخر خاص، وهو bucket النسخ الاحتياطي الخاص بك. من المهم عمل نسخ احتياطية آلية لـ Discourse في حالة حدوث أي خلل، ثم يمكنك تحميل النسخ الاحتياطي وإصلاحه.

في لوحة تحكم BunnyCDN، يجب إنشاء منطقة سحب (pull zone) ثانية. كانت منطقة السحب الأولى للرفع، وهذه المنطقة الجديدة ستكون للنسخ الاحتياطي.

لوحة تحكم bunnycdn > مناطق السحب > إضافة منطقة سحب

اتبع نفس الدليل الذي ربطت به سابقًا، “كيفية تسريع تسليم ملفات Backblaze B2 باستخدام BunnyCDN”، ولكن هذه المرة ستربط منطقة السحب الجديدة بـ bucket النسخ الاحتياطي بدلاً من bucket الرفع.

أوصي باستخدام “الطبقة عالية الحجم 5$/TB” في صفحة إنشاء منطقة السحب في BunnyCDN، أعتقد أن النسخ الاحتياطي لا يحتاج إلى الطبقة الأغلى/الأسرع “الطبقة القياسية 10$/TB” التي استخدمتها لـ bucket الرفع.

اضبط إعدادات النسخ الاحتياطي في منطقة إعدادات لوحة تحكم Discourse. يجب أن تكون “موقع النسخ الاحتياطي” مضبوطة على S3، ويجب أن يشير “نقطة نهاية S3” إلى ما لديك في Backblaze، مثل هذا:
s3.us-west-002.backblazeb2.com

اضغط على CTRL+F5 مرتين على موقعك الإلكتروني لمسح الذاكرة المؤقتة.

ابدأ نسخة احتياطية، ودعها تكتمل. ثم انتظر 5 دقائق وتحقق من مجلد النسخ الاحتياطي في Backblaze، يجب أن ترى النسخة الاحتياطية الجديدة هناك.

ترحيل الصور الأقدم:
هذه الخطوة اختيارية ولكنها موصى بها، خاصة إذا كانت مساحة التخزين على خادمك منخفضة. إذن لقد قمت بإعداد كل شيء للرفع الجديد للصور، ولكن يمكن أيضًا نقل الصور الأقدم إلى buckets الخاصة بك. لجعل هذه العملية تعمل، يجب عليك اتباع ما يلي:

إعداد 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?