如何关闭 S3 存储?

大家好,

如何完全关闭 AWS S3 存储,并将 S3 存储中的所有文件和备份恢复到我的 EC2 服务器上?

1 个赞

我相信这会解决问题:

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

这将把上传文件从 S3 迁移到你的 Web 服务器。之后,你可以返回 app.yml 文件,将 DISCOURSE_USE_S3: false 进行修改。然后重新构建。

9 个赞

我也会进入 Discourse 的管理后台,取消勾选所有激活 S3 模式的复选框。

2 个赞

我按照 @AntiMetaman 的建议操作了,但出现了 rake aborted 错误。首先,它提示我关闭 S3 上传。我关闭了 S3 上传后再次尝试运行 rake,随后出现了这个错误。

root@ip-172-31-7-247-app:/var/www/discourse# rake uploads:migrate_from_s3 --trace
** Invoke uploads:migrate_from_s3 (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute uploads:migrate_from_s3
Migrating uploads from S3 to local storage for 'default'...
rake aborted!
NoMethodError: undefined method `downcase' for nil:NilClass
/var/www/discourse/app/models/global_setting.rb:107:in `s3_bucket_name'
/var/www/discourse/app/models/site_setting.rb:157:in `absolute_base_url'
/var/www/discourse/lib/tasks/uploads.rake:138:in `migrate_from_s3'
/var/www/discourse/lib/tasks/uploads.rake:118:in `block in migrate_all_from_s3'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.3.0/lib/rails_multisite/connection_management.rb:68:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.3.0/lib/rails_multisite/connection_management.rb:78:in `each_connection'
/var/www/discourse/lib/tasks/uploads.rake:118:in `migrate_all_from_s3'
/var/www/discourse/lib/tasks/uploads.rake:93:in `block in <main>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:83:in `block in run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:80:in `run'
bin/rake:13:in `<top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => uploads:migrate_from_s3

就是这个,对吧?

s3

我今天看到了这个话题。如果可以的话,不妨再等等。

如果你仅在管理面板中关闭 S3,那只会禁用站点级别的 S3。你需要全局禁用它,因此必须在 app.yml 中将值从 true 改为 false,然后重新构建。

如果你已正确配置 S3,它应该可以正常工作。我刚刚尝试了 migrate_from_s3 和 migrate_to_s3,对我而言运行正常,没有遇到任何错误。我不清楚这个错误的具体含义,因此建议联系 Discourse 开发者寻求帮助:

NoMethodError: undefined method 'downcase' for nil:NilClass

奇怪,我下面的回复被删除了,所以我再次发布。

当对 nil 对象调用字符串方法时会出现该错误;在 Ruby 中,这通常发生在预期为字符串对象但实际为 nil 的情况下。

这就是该错误发生的原因。

1 个赞

已在 app.yml 中添加了 DISCOURSE_USE_S3: false,但错误依旧。请问您使用的是哪个版本的 Discourse?我使用的是最新版本。

我也是最新版本。你在重新构建时遇到任何错误了吗?如果有,能贴出来吗?

不,没有任何错误。

如果错误仅出现在执行 rake 命令之后,能否请你贴出你输入的确切命令?当初你配置好 S3 时,是不是还需要将文件迁移到 S3?

这是我的完整 app.yml 文件

这是一个独立的 Discourse Docker 容器模板,包含所有组件

修改此文件后,您必须重新构建

/var/discourse/launcher rebuild app

编辑时请非常小心!

YAML 文件对空白字符或对齐中的错误超级敏感!

根据需要访问 http://www.yamllint.com/ 验证此文件

templates:

  • “templates/postgres.template.yml”
  • “templates/redis.template.yml”
  • “templates/web.template.yml”
  • “templates/web.ratelimited.template.yml”

如果您想添加 Lets Encrypt (https),请取消注释这两行

  • “templates/web.ssl.template.yml”
  • “templates/web.letsencrypt.ssl.template.yml”

- “templates/cloudflare.template.yml”

此容器应暴露哪些 TCP/IP 端口?

如果您希望 Discourse 与另一个 Web 服务器(如 Apache 或 nginx)共享端口,

详见 Run other websites on the same machine as Discourse

expose:

  • “80:80” # http
  • “443:443” # https

params:
db_default_text_search_config: “pg_catalog.english”

将 db_shared_buffers 设置为总内存的最大 25%。

将由 bootstrap 根据检测到的 RAM 自动设置,或者您可以覆盖

db_shared_buffers: “128MB”

可以改善排序性能,但会增加每个连接的内存使用量

#db_work_mem: “40MB”

此容器应使用哪个 Git 修订版?(默认:tests-passed)

#version: tests-passed

env:
LANG: en_US.UTF-8

DISCOURSE_DEFAULT_LOCALE: en

支持多少个并发 Web 请求?取决于内存和 CPU 核心数。

将由 bootstrap 根据检测到的 CPU 自动设置,或者您可以覆盖

UNICORN_WORKERS: 2

TODO: 此 Discourse 实例将响应的域名

DISCOURSE_HOSTNAME: engineersasylum.com

如果您希望容器以与上述指定的相同的主机名(-h 选项)启动,请取消注释

(默认值为 “$hostname-$config”)

#DOCKER_USE_HOSTNAME: true

TODO: 初始注册时将设为管理员和开发人员的逗号分隔电子邮件列表

示例 ‘user1@example.com,user2@example.com’

DISCOURSE_DEVELOPER_EMAILS: ‘praveen369gen@gmail.com’

TODO: 用于验证新账户和发送通知的 SMTP 邮件服务器

DISCOURSE_SMTP_ADDRESS: email-smtp.us-east-1.amazonaws.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: AXXXXXXXXXXXXXXX
DISCOURSE_SMTP_PASSWORD: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (可选,默认为 true)

如果您添加了 Lets Encrypt 模板,请取消注释以下行以获取免费 SSL 证书

LETSENCRYPT_ACCOUNT_EMAIL: praxxxxxx@gmail.com

此 Discourse 实例的 CDN 地址(配置为拉取)

详见 Enable a CDN for your Discourse

#DISCOURSE_CDN_URL: //discourse-cdn.example.com
DISCOURSE_USE_S3: false

Docker 容器是无状态的;所有数据都存储在 /shared 中

volumes:

  • volume:
    host: /var/discourse/shared/standalone
    guest: /shared
  • volume:
    host: /var/discourse/shared/standalone/log/var-log
    guest: /var/log

插件放在这里

详见 Install plugins on a self-hosted site

hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- git clone GitHub - discourse/docker_manager: Plugin for use with discourse docker image · GitHub
- git clone GitHub - discourse/discourse-solved: Allow accepted answers on topics · GitHub
- git clone GitHub - discourse/discourse-adplugin: Official Discourse Advertising Plugin. Install & Start Serving Ads on Your Discourse Forum · GitHub
- git clone https://github.com/communiteq/discourse-sitemap.git
- git clone GitHub - discourse/discourse-whos-online: A plugin for Discourse which uses the messagebus to display a live list of active users · GitHub
- git clone GitHub - discourse/discourse-push-notifications: Plugin for integrating Chrome and FireFox push notifications · GitHub
- git clone GitHub - discourse/discourse-chat-integration · GitHub
- git clone GitHub - davidtaylorhq/discourse-telegram-notifications: A plugin for Discourse which allows users to receive their notifications by telegram message · GitHub
- git clone GitHub - discourse/discourse-docs · GitHub
- git clone GitHub - discourse/discourse-math: Official MathJax support for Discourse · GitHub

构建后运行的任何自定义命令

run:

  • exec: echo “Beginning of custom commands”

如果您想为首次注册设置“发件人”电子邮件地址,请取消注释并更改:

收到第一封注册邮件后,请重新注释该行。它只需运行一次。

#- exec: rails r “SiteSetting.notification_email=‘info@unconfigured.discourse.org’”

  • exec: echo “End of custom commands”

我不太记得确切的情况了,但我想我使用 rake uploads:migrate_to_s3 迁移到了 S3。

我完全不清楚,但这里有一个与你遇到的错误完全相同的类似帖子:

建议你与团队成员确认一下。

你好 @Pravi

侧边栏问题:

在你发布的 yml 文件中,你“写道”:

DISCOURSE_SMTP_PASSWORD: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

这是正确的吗?你的 yml 文件中的密码是否使用了双引号?

是的,它使用了双引号。自两年前添加以来,我从未修改过它。

我已经移除了双引号,然后重新构建了应用。接着再次尝试运行 rake uploads:migrate_from_s3,但依然没有成功。错误依旧。

你好 @Pravi

老实说,我是 AWS 和 S3 的反对者,所以我不使用它们。

你有没有考虑过查看 Rake 任务,逆向分析该脚本,然后一步一步地手动执行该任务?

我对 Discourse 的内部脚本了解不多,有点不敢编辑脚本,担心会搞砸一切。

你能告诉我 discourse.config 文件的位置吗?我在服务器上到处都找不到。find 命令没有返回任何结果。

root@ip-172-31-7-247:/var/discourse# find . -name "*.config"
root@ip-172-31-7-247:/var/discourse# find . -name "*.conf"
./shared/standalone/letsencrypt/engineersasylum.com/engineersasylum.com.conf
./shared/standalone/letsencrypt/engineersasylum.com/engineersasylum.com.csr.conf
./shared/standalone/letsencrypt/engineersasylum.com_ecc/engineersasylum.com.conf
./shared/standalone/letsencrypt/engineersasylum.com_ecc/engineersasylum.com.csr.conf
./shared/standalone/letsencrypt/ca/acme-v01.api.letsencrypt.org/ca.conf
./shared/standalone/letsencrypt/ca/acme-v02.api.letsencrypt.org/ca.conf
./shared/standalone/letsencrypt/account.conf
./shared/standalone/postgres_data/pg_hba.conf
./shared/standalone/postgres_data/postgresql.auto.conf
./shared/standalone/postgres_data/pg_ident.conf
./shared/standalone/postgres_data/postgresql.conf
root@ip-172-31-7-247:/var/discourse#

你好 @Pravi

抱歉让你产生了误解。

我并没有要求你编辑那个文件或任何其他文件。

在我看来,“逆向工程”一个脚本意味着研究它、了解它是如何工作的,这与编辑文件毫无关系。它指的是阅读并理解它。

通常,如果我们阅读并理解任何报错的脚本或文件,我们就能明白如何解决问题。

你似乎并没有阅读那个文件,却仍在发布来自该文件的错误信息。

希望这能有所帮助。

我理解你的意思。我会尝试去做。
你能告诉我 ‘discourse.config’ 文件的位置吗?S3 的配置存储在哪里?