إعدادات متعددة المواقع باستخدام Docker

:warning: على الرغم من أن تعدد المواقع (multisite) مدعوم في تطبيق Discourse، إلا أن هذا إعداد متقدم لمسؤول النظام. إذا لم تكن تعرف ما تفعله، فلا تقم بإعداد تعدد المواقع. فريق Discourse غير قادر على تقديم دعم لإعداد تعدد المواقع.

إذا كنت ترغب في استضافة نطاقات متعددة على إعداد Docker واحد، فستحتاج إلى إعداد تعدد المواقع. فيما يلي اللبنات الأساسية لذلك.

فهم الخطافات (Hooks)

تعدد المواقع موضوع متقدم إلى حد ما. قبل محاولة بناء تعدد المواقع، اقضِ بعض الوقت في تعلمها.

تستخدم قوالب Discourse pups؛ وقواعدها بسيطة وقوية.

كل قاعدة تقوم بتشغيلها قد تُعرّف خطافًا (hook):

run:
  exec:
    cd: some/path
    hook: my_hook
    cmd:
      - echo 1

لاحقًا في الحاوية الخاصة بك، يمكنك إدراج قواعد قبل أو بعد خطاف:

hooks:
  before_my_hook:
    - exec: echo "I ran before"
  after_my_hook:
     - exec: echo "I ran after"

لذا في المثال أعلاه، سترى مخرجات مثل ما يلي:

I ran before
1
I ran after

يمكنك قراءة القوالب في /var/discourse/templates لمعرفة الخطافات المتاحة لديك.

تعديل حاوية التثبيت المستقلة لتوفير مستأجر الموقع الثاني

استبدل قسم الخطافات بأكمله بما يلي:

hooks:
  after_postgres:
     - exec: sudo -u postgres createdb b_discourse || exit 0
     - exec:
          stdin: |
            grant all privileges on database b_discourse to discourse;
          cmd: sudo -u postgres psql b_discourse
          raise_on_fail: false

     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists pg_trgm;"'

  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
  before_bundle_exec:
    - file:
        path: $home/config/multisite.yml
        contents: |
         secondsite:
           adapter: postgresql
           database: b_discourse
           pool: 25
           timeout: 5000
           db_id: 2
           host_names:
             - b.discourse.example.com

  after_bundle_exec:
    - exec: cd /var/www/discourse && sudo -H -E -u discourse bundle exec rake multisite:migrate

هناك 3 خطافات قيد الاستخدام:

  1. after_postgres يضمن أنه بعد تثبيت postgres يتم إنشاء قاعدة بيانات إضافية تسمى b_discourse مع الأذونات المناسبة.

  2. before_bundle_exec يضمن وجود docker_manager وأن ملف multisite.yml موجود (والذي يحدد مكان العثور على قواعد البيانات)

  3. after_bundle_exec يشغل مهمة ترحيل قاعدة البيانات المخصصة rake multisite:migrate وهذا يضمن تحديث جميع قواعد البيانات.

ملاحظة حول التكوين

يمكن تقسيم العينة المذكورة أعلاه إلى حاوية بيانات / حاوية تطبيق إذا لزم الأمر. فقط قم بتشغيل الخطاف after_postgres في حاوية البيانات والباقي في حاوية الويب.

يمكن توسيع العينة المذكورة أعلاه لتوفير المزيد من قواعد البيانات. للقيام بذلك، قم بتوفير المزيد من قواعد البيانات عن طريق تكرار استدعاءات إنشاء قاعدة البيانات وما إلى ذلك، وتأكد من إضافة مواقع إضافية في multisite.yml.

تأكد من تعديل عقدة host_names في multisite.yml لتتوافق مع اسم المضيف الفعلي الذي ترغب في استضافته.

أيضًا، إذا كنت تخطط لتشغيل HTTPS، فستحتاج إلى وكيل (proxy) أمام الموقع للتعامل معه لأن وظيفة letsencrypt المضمنة لن تعمل في سيناريو تعدد المواقع.

69 إعجابًا
How does multisite.yml look?
Multiple Forums in a Single Installation
How to create 1000 subcategories in a scalable way?
Multiple Discourses, multiple containers, one server
Pros and cons of multiple standalone containers vs one for multiple Discourse installs?
Success - New Multisite Install on Dedicated server using ServerPilot, Nginx and Apache
Multisite Installation
Will I need to start over with multisite configuration from standalone version?
Multiple Discourse Installs - Single Server
Starting a second Discourse forum on the same VPS
Pros and cons of a multisite installation
Installation wizard not appearing in multisite installs
Disabling/restricting user search
Sandbox and test discourse on host?
Multisite installation with seperated smtp emails
How do you set up multiple discourse forums on the same server?
Help me setup many websites on one VPS
Second discourse instance on the same server
Discourse multisite installation help with digitalocean
Need proper documentation for multisite discourse with docker
Discourse for 3 different Countrys
Micro Forums: how many could I create?
Remove sites from multisite config with Docker
How could I install another discourse on same server (docker)?
Can I log into multiple instances of discourse simultaneously?
How to setup host mapping on a multi-site discourse instance
Not receiving activation email for admin on multisite installation
Multisite viability - 2 read-only and 1 active
Install Discourse on Plesk / Ubuntu 14 without Docker
Totally Walled-Off Groups
Three sites in one setup
I want to host hundreds of instances of Discourse
Recover to one site from multisite
Publishing multisite
Multisite Config
Multiple communities on discourse?
Adding an instance to multisite without rebuilding the container
Is it possible to totally hide members
Need help with multisite configuration
Multitenat Dockerize Discourse
Installing on Kubernetes
How might we better structure #howto?
How to set redis DB ID in Docker container?
Pull request for Wikis?
How can I host more than 1 Discourse forum on 1 VPS?
Multiple discourse installation on single droplet
Integration with .NET MVC application for a SaaS platform
Setup Multisite Configuration with Let's Encrypt and no Reverse Proxy
Docker image update: Redis 6 and 25% smaller image size
Setup Multisite Configuration with Let's Encrypt and no Reverse Proxy
One server for 2 Discourse communities?
Multiple discourse instances in a single server
Pups::ExecError
Web-only - do I need a separate image for each container?
One server for 2 Discourse communities?
Multisite installation ... in subdirectories?
Stable branch assets won't compile
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column categories.search_priority does not exist
[mutlisite installation] pnpm permission error during rebuild
WP SSO + Discourse Multisite
All users are visible in @mentions autocomplete list
Migrate from VPS to a Dedicated
Are there other workarounds to not having category moderation such as multiple instances of the board?
Discourse Multisite – Nginx (Inside Docker) Only Serving Default Site
Stable branch assets won't compile
Two Discourse communities on the same VPS
How can I use different setting value for subdomain?
Will This Configuration Successfully Create a Second Discourse Instance (with Proxy)?
Pups::ExecError
Use CloudPanel to manage multiple sites with Discourse
Best approach for test and production instance of discourse
Two standalone instances on one server?
How can Admin login while Read-only mode is enabled on multisite?
Does discourse hosting use docker for all customer instances?
Tips for setting up a multi-subdomain Discourse instance with shared SSO?
Feature proposal: Customizations based on primary group membership, a.k.a. tenancy 'lite'
Using a launcher built docker image in docker-compose
Move from standalone container to separate web and data containers
Move from standalone container to separate web and data containers
Move from standalone container to separate web and data containers
Guidance on multi-site setup
Running multiple things on the same sever as my Pi (where Discourse is hosted)?
Contabo experience with Plesk, Webmin or other server-admin setup?
App.yml shared volumes for a two website setup
How extensible can I make my installation in terms of sub domains and restricting membership to them?
Discourse instance stops running in every midnight
Multisite for small collection of sites for a family?
Hosting Plan Suggestion for 500 Concurrent Online Users
Add path to cookie
Avatar, Site Logos, and Cert Errors
Database access issues after upgrade v3.5.2 -> v3.6.0.beta2
PAID Require Discourse expert for extreme customization
Move from standalone container to separate web and data containers
Can I have two domains pointing towards the same IP address without redirect?
Move from standalone container to separate web and data containers
Multiple container setup problems

كنت أتساءل ما هي وظيفة القيمة db_id: 2 في الإعداد المقترح أعلاه؟

أيضًا، ما هي الإجراءات اللازمة لإضافة موقع جديد إلى الإعداد الحالي متعدد المواقع؟ هل هو فقط:

  • تحديث ملف yaml
  • ./launcher bootstrap multisite [1]
  • ./launcher start multisite

كنت أتساءل عما إذا كانت هناك طريقة لتجنب التأثير على جميع المواقع الأخرى الموجودة عن طريق إجراء عملية bootstrap أو إعادة بناء كاملة، وبطريقة ما فقط إضافة قاعدة البيانات الإضافية المطلوبة؟


  1. حاولت أولاً ./launcher rebuild multisite، ولكن يبدو أن هذا يفشل. ↩︎

أعتقد أنه لم تعد هناك حاجة لمعرف قاعدة البيانات.

يمكنك فقط تعديل ملف multisite بالموقع الجديد وتنفيذ

sv restart unicorn

ثم ترحيل قاعدة البيانات.

إعجاب واحد (1)

أنت منقذ!\n\n[quote="Jay Pfaffman, post:177, topic:14084, username:pfaffman"]\nsv restart unicorn\n[/quote]\n\nكنت أفتقد هذا الأمر لإعادة التشغيل (حاولت أيضًا sv reload unicorn ولكن بطريقة ما لم يكن ذلك كافيًا).\n\nفيما يتعلق بإنشاء قاعدة البيانات، هل هناك بالفعل طريقة للقيام بذلك تلقائيًا؟ سيكون من الجميل أن يكون لدي rake db:create[mynewdbname]. بخلاف ذلك، يمكنني كتابة نص برمجي قصير.\n\nفي الوقت الحالي، أقوم بإنشاء يدويًا (إنشاء قاعدة بيانات وتعيين الأذونات) ثم أقوم بتشغيل RAILS_DB=newdb rake db:migrate لملئها.

وللتحقق فقط مما إذا كنت أفعل شيئًا غبيًا:

  • في الوقت الحالي، أقوم بتحرير ملف multisite داخل docker (/var/www/discourse/config/multisite.yml)
  • إنشاء قاعدة البيانات يدويًا
  • تشغيل rake db:migrate
  • sv restart unicorn
  • أحتاج أيضًا إلى تحرير ملف yaml خارج docker بحيث تتم مزامنة تكوين multisite في حالة حدوث أي إعادة بناء أو ترقيات مستقبلية.

هل أنا غبي بتحرير تكوين multisite في مكانين مختلفين بينما توجد بالفعل طريقة للتحرير في مكان واحد ودفع التغييرات؟

إعجاب واحد (1)

هل من الممكن تنظيف هذه الوثائق قليلاً وتوفير المزيد من الإرشادات فيها؟ أنا جديد جدًا على Docker في المقام الأول وعلى الرغم من أن لدي خبرة في خوادم Linux لست محترفًا فيها. أنا من المدرسة القديمة أحب مهام cron الخاصة بي والبرامج النصية shell والأشياء الغريبة التي تعرفها مثل هذه مع Apache multi site وما إلى ذلك. ولكن هذا أكثر تعقيدًا ويستخدم لغة برمجة مختلفة عما اعتدت عليه.. ربما حتى فيديو توضيحي من نوع ما؟ سيكون من الجيد لو تم جعل Discourse جاهزًا للاستخدام متعدد المواقع وبهذه الطريقة كل ما عليك فعله هو تعديل بعض الملفات وما إلى ذلك.

إعجابَين (2)

فقط الصق هذا المقطع من النص وقم بتحريره ليناسب.

ستحتاج بعد ذلك إما إلى وكيل عكسي (reverse proxy) أو اتباع إعداد Let’s Encrypt مع نطاقات متعددة / عمليات إعادة توجيه للحصول على شهادات لجميع النطاقات.

انظر أيضًا إعداد تكوين مواقع متعددة مع Let’s Encrypt وبدون وكيل عكسي. ولكن هذا يحتاج إلى تحديث ليحتوي على سطر آخر مطلوب يمكنك الحصول عليه من الرابط السابق. كنت أنوي تحديثه ولكني لم أتمكن من ذلك.

إعجاب واحد (1)

إذا كنت أقوم بإعداد مواقع متعددة، فأين يجب أن أشير بنطاقي؟ نفس عنوان IP الخاص بالخادم (الذي يستضيف منتدى آخر)؟

نعم، وجّه جميع النطاقات إلى عنوان IP الخادم نفسه.
قم بإعداد وكيل عكسي باستخدام خادم Nginx أو Caddy.
Caddy هو الأفضل لأنه يوفر شهادات SSL مجانية تلقائية لجميع نطاقاتك.

إعجاب واحد (1)

لقد اتبعت هذا الدليل لإعداد تثبيت متعدد المواقع باستخدام Docker بنجاح. واجهت مؤخرًا خطأ عند محاولة الترقية وأعتقد أن السطر:

    - exec: cd /var/www/discourse &amp;&amp; sudo -E -u discourse bundle exec rake multisite:migrate

يجب تعديله إلى:

    - exec: cd /var/www/discourse &amp;&amp; sudo -H -E -u discourse bundle exec rake multisite:migrate

هل يمكن لأي شخص تأكيد/تعديل الدليل؟

إعجاب واحد (1)

نعم. واجهت هذا أيضًا. تريد إجراء هذا التغيير وإلا سيفشل التمهيد الخاص بك.

إعجابَين (2)

أؤكد بحماس أيضًا أن هذا التصحيح إلزامي!

بالتأكيد تم التعديل، شكرًا لك!

إعجابَين (2)