# 使用有效key下载maxmind db失败，但可以在容器内下载DB

**URL:** https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590
**Category:** Bug
**Tags:** maxmind
**Created:** [2024年三月22日 21:10 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590 "2024-03-22T21:10:47Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024年三月22日 21:10 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/1 "2024-03-22T21:10:47Z")

</div>

构建失败是由于这个原因。我删除了 ENV 变量并在没有它的情况下重新构建。然后进入容器内部进行调试。在那里，我将密钥添加到了 `discourse.conf`，但仍然失败。

（谢天谢地，我在告诉客户他们给了我一个无效密钥之前就做了这件事！）

我向 rake 任务添加了一个 `puts` 来打印它尝试下载数据库的 URL，如下所示：

```plaintext
    url =
      "https://download.maxmind.com/app/geoip_download?license_key=#{GlobalSetting.maxmind_license_key}&edition_id=#{name}&suffix=tar.gz"

    gz_file =
      FileHelper.download(
        url,
        max_file_size: 100.megabytes,
        tmp_file_name: "#{name}.gz",
        validate_uri: false,
        follow_redirect: false,
      )

    if gz_file.nil?
      puts "no gzfile"
    end
    puts "Got file #{gz_file} for #{url}"
    filename = File.basename(gz_file.path)

```

现在我得到这个：

```plaintext
root@web-only:/var/www/discourse# rake maxminddb:get
插件名称是 'discourse-topic-voting'，但插件目录名为 'discourse-voting'
正在下载 MaxMindDb 的 GeoLite2-City...
no gzfile
Got file for https://download.maxmind.com/app/geoip_download?license_key=VALID_KEY_IS_HERE&edition_id=GeoLite2-City&suffix=tar.gz
rake aborted!
NoMethodError: undefined method `path' for nil:NilClass (NoMethodError)

    filename = File.basename(gz_file.path)
                                    ^^^^^
/var/www/discourse/lib/discourse_ip_info.rb:52:in `mmdb_download'
/var/www/discourse/lib/tasks/maxminddb.rake:9:in `block (2 levels) in <main>'
/var/www/discourse/lib/tasks/maxminddb.rake:7:in `each'
/var/www/discourse/lib/tasks/maxminddb.rake:7:in `block in <main>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Tasks: TOP => maxminddb:get
(通过运行任务并添加 --trace 来查看完整跟踪)

```

有另一个主题，问题是站点被 Maxmind 阻止了，所以我尝试了，并且成功地从服务器上的容器内使用 `wget` 下载了该 URL。

在我看来，`FileHelper.download` 并不是一个真正的 `Helper`，而是默默地返回 `nil` 而不是文件。文件只有 44MB，所以不是这个问题。当我使用 wget 检查完整的标头时，我没有看到重定向。

有什么关于这可能是什么原因的想法吗？

有没有理由不捕获此错误并允许构建使用无效密钥完成？也许只是打印一个警告？

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年三月23日 13:10 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/2 "2024-03-23T13:10:11Z")

</div>

> [@pfaffman](#):
>
> `follow_redirect: false,`

`follow_redirect: true` 是否效果更好？

根据最近的更改，MaxMind 更改了下载 URL，但只要您允许重定向，就可以保留原始 URL。

> [@Maxmind R2 presigned URLs](https://meta.discourse.org/t/maxmind-r2-presigned-urls/298941):
>
> Just got an email from Maxmind: As of Wednesday, May 1, 2024, we will use R2 presigned URLs for all database downloads in order to increase the security and reliability of our services. Does anyone know whether this affects Discourse’s Maxmind usage?

---

<div class="post-metadata">

### Author: ![mcdanlj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcdanlj/32/131829_2.png) [@mcdanlj](https://meta.discourse.org/u/mcdanlj)
#### Post date: [2024年三月23日 13:31 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/3 "2024-03-23T13:31:48Z")

</div>

我想知道是否有什么误会，这个并非真的从5月1日开始。🤔

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024年三月23日 13:36 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/4 "2024-03-23T13:36:03Z")

</div>

> [@Arkshine](#):
>
> `follow_redirect: true` 能让它工作得更好吗？

我的天哪。是的。我不知道为什么我没有直接更改它，并且认为它没有重定向。

> <https://github.com/discourse/discourse/pull/26333>
>
> Per https://dev.maxmind.com/geoip/release-notes/2024#presigned-urls-for-database…-downloads 
> 
> MaxMind users who download databases should make sure that their HTTP client follows redirects and there are no proxy or firewall settings that would block requests to the host we are redirecting to.
> 
> See https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-containerr/300590/4 and https://meta.discourse.org/t/maxmind-r2-presigned-urls/298941/2

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2024年三月25日 22:39 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/5 "2024-03-25T22:39:26Z")

</div>

好的，已合并，请告知进展！

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [2024年三月25日 23:49 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/6 "2024-03-25T23:49:26Z")

</div>

尝试将论坛的 maxmind 密钥重新投入使用，但我们在尝试重建时仍然收到原始错误。

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年三月26日 01:28 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/7 "2024-03-26T01:28:48Z")

</div>

您能检查一下您是否使用了最新版本的 Discourse 吗？它对 Jay 有效；我看不出有什么理由它对您无效，尤其是当它遵循 MaxMind 的建议时。🤔

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [2024年三月26日 01:33 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/8 "2024-03-26T01:33:47Z")

</div>

> [@Arkshine](#):
>
> 您能检查一下您是否在使用最新的 Discourse 版本吗？

不确定在重建应用程序时如何不使用最新版本

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年三月26日 01:44 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/9 "2024-03-26T01:44:45Z")

</div>

你说得对。不过，你永远不知道。😄 显示的哈希版本是什么？至少我们可以快速检查一下。

我重新阅读了 MaxMind 的公告，但除了更改 URL 或允许重定向之外，我没有看到任何其他内容。🤔

---

<div class="post-metadata">

### Author: ![mcdanlj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcdanlj/32/131829_2.png) [@mcdanlj](https://meta.discourse.org/u/mcdanlj)
#### Post date: [2024年三月26日 01:57 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/10 "2024-03-26T01:57:30Z")

</div>

> [@Firepup650](#):
>
> 不确定在重建应用程序时如何不会

您是在运行 `tests-passed` 还是 `latest-release`？

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [2024年三月26日 02:01 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/11 "2024-03-26T02:01:19Z")

</div>

我们已进入 `tests-passed` 状态，至少据我所知是这样。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024年三月26日 13:52 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/12 "2024-03-26T13:52:26Z")

</div>

查看源代码时，URL 是什么，或者如何获取提交。

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [2024年三月26日 14:03 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/13 "2024-03-26T14:03:00Z")

</div>

崩溃的构建日志结束：

```plaintext
正在下载 MaxMindDB...
正在压缩 Javascript 并生成 Source Maps
I, [2024-03-26T13:27:38.305597 #1] INFO -- : 正在终止异步进程
I, [2024-03-26T13:27:38.307312 #1] INFO -- : 正在向 HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main pid: 42 发送 INT
I, [2024-03-26T13:27:38.307891 #1] INFO -- : 正在向 exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 111 发送 TERM
111:signal-handler (1711459658) 收到 SIGTERM，正在调度关闭...
2024-03-26 13:27:38.307 UTC [42] LOG: 收到快速关机请求
2024-03-26 13:27:38.314 UTC [42] LOG: 正在中止任何活动事务
2024-03-26 13:27:38.321 UTC [42] LOG: 后台工作进程“逻辑复制启动器”(PID 51) 已退出，退出代码为 1
2024-03-26 13:27:38.322 UTC [46] LOG: 正在关闭
111:M 26 Mar 2024 13:27:38.353 # 用户请求关机...
111:M 26 Mar 2024 13:27:38.353 * 正在退出前保存最终 RDB 快照。
2024-03-26 13:27:38.415 UTC [42] LOG: 数据库系统已关闭
111:M 26 Mar 2024 13:27:39.896 * DB 已保存到磁盘
111:M 26 Mar 2024 13:27:39.896 # Redis 现在可以退出了，再见...
失败
--------------------
Pups::ExecError: cd /var/www/discourse &amp;&amp; su discourse -c 'bundle exec rake themes:update assets:precompile' 失败，返回 #&lt;Process::Status: pid 3889 exit 1&gt;
失败位置：/usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
使用参数 {"cd"=>"$home", "hook"=>"assets_precompile", "cmd"=>["su discourse -c 'bundle exec rake themes:update assets:precompile'"]} 执行失败
引导失败，退出代码为 1
**引导失败** 请向上滚动查找更早的错误消息，可能不止一个。
./discourse-doctor 可能会帮助诊断问题。
fe4eec7726fdbe08aaa2691e806bb17423a8f4eaedb8414397e3097d725e04c7

```

提交：\<[Commits · discourse/discourse · GitHub](https://github.com/discourse/discourse/commits/f350cea5d2&gt);

事后补充说明，我没有链接到发生此问题的网站，因为其中一名工作人员[正在测试一个内核 bug](https://amcforum.wiki/t/why-was-amc-down/4940) 在同一服务器上的另一个容器中，并意外导致整个服务器崩溃，因此链接到网站根本无济于事。

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年四月24日 23:42 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/14 "2024-04-24T23:42:23Z")

</div>

@Firepup650 还会发生这种情况吗？

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [2024年四月24日 23:47 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/15 "2024-04-24T23:47:38Z")

</div>

我一直想重建一段时间了，所以我会运行一个看看。

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [2024年四月25日 00:27 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/16 "2024-04-25T00:27:54Z")

</div>

我确认，问题不再出现。我们的论坛现在可以正常重建。

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2024年四月26日 07:00 UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/17 "2024-04-26T07:00:34Z")

</div>

该主题在 26 小时后自动关闭。不再允许回复。
