为反向IP查询配置MAXMIND

What is MAXMIND and why would I want it?

Discourse uses MAXMIND to provide geographical information for reverse IP lookups.

location

Without Maxmind’s database you’ll see something like this:
nolocation

Or perhaps you’ve noticed this message fly by when you rebuild your container:

MaxMind IP database download requires an account ID and a license key
Please set DISCOURSE_MAXMIND_ACCOUNT_ID and DISCOURSE_MAXMIND_LICENSE_KEY. See https://meta.discourse.org/t/configure-maxmind-for-reverse-ip-lookups/173941 for more details.

Why would I care?

It’s often useful for moderators to see where someone is logging in from to determine if the person is who (and where) they say they are or to diagnose problems with your site. (“Oh, we frequently see problems with Special-ISP”.)

Also, as of 2.2.0.beta4, Discourse also uses this information to notify admins if a login is seen from a new location. Without the Maxmind database, Discourse cannot provide this notification.

What if I don’t setup a MaxMind account and generate a license key

You won’t be able to do reverse lookups. If the issues above do not concern you, then it is a good bet that nothing bad will happen if you just ignore this.

How do I setup a MaxMind account and obtain an Account ID and a license key?

See Maxmind’s https://support.maxmind.com/hc/en-us/articles/4407111582235-Generate-a-License-Key page for up-to-date instructions, but you need to

  • Visit the GeoLite2 Sign Up page.
  • generate a license key on the Manage License Keys tab in the left navigation bar once you’ve logged in. Generate a new key, and copy the account ID and the license key. If you lose it, you’ll need to generate a new one.

You then add that key to the ENV section of your app.yml with a line like this:

  DISCOURSE_MAXMIND_ACCOUNT_ID: your-account-id-here
  DISCOURSE_MAXMIND_LICENSE_KEY: your-key-here

Or via discourse-setup when prompted.

Notes for IPv6 users

The Standard install doesn’t fully support IPv6 out of the box. If you have a server with IPv6 configured and need Maxmind information for IPv6 addresses, you’ll need to make sure that the user’s actual IP address is what is getting to Discourse, normally by using an external proxy that passes the remote IP address to Discourse. This requires more systems administration expertise than the standard install.

31 个赞

@pfaffman,‘我的许可证密钥’的 URL 包含您在 MaxMind 的账户 ID,因此除了您自己以外,其他人无法使用 :wink:

3 个赞

对我来说没问题!:winking_face_with_tongue:

不过有趣的是,三年来没有人抱怨过!这是一个维基,所以你可以自己修复。如果我记得的话,我会尝试在有电脑时更新。

2 个赞

显示有多少人真正阅读了这类页面 :grin:

我已经编辑了该页面 :nerd_face:

3 个赞

是吧!?我花了很多时间来创建它。不知道我怎么会忽略了链接只对我有效,但我想登录就足以让我和其他很多人分心了。

2 个赞

只是一个好奇的问题 @evert,您是故意留下括号的吗?如果是这样,它是否看起来像一个按钮会更好?

按钮示例

管理许可证密钥

<kbd>管理许可证密钥</kbd>
3 个赞

当然可以? :+1:t2:

2 个赞

据我所知,我一切正常

image

但所有用户的地点都显示为“未知”

任何帮助都将不胜感激。

您需要删除前面的#字符并重新构建。#字符使整行成为YAML文件中的注释。

5 个赞

谢谢,只需写出来然后退出或重建吗?

你必须重新构建。否则,Discourse 将无法识别 app.yml 的更改。

4 个赞

谢谢,已完成并正常工作 :hugs:

2 个赞

对于在座的大多数人来说,这可能不言而喻,但使用 VPN 的人可能会比其他人产生更多的警报。这只是对管理员的一个提醒,并不一定表示用户有恶意。

2 个赞

太好了!感谢这个教程。

1 个赞

请问,
当 Discourse 为管理面板执行 IP 查询(反向 IP 查询)时,它是依赖于离线 GeoIP 数据库还是每次都查询外部 API

谢谢!!

1 个赞

就上下文而言,我更倾向于通过将 Discourse 指向一个本地的 GeoLite2-City.mmdb 文件来离线处理 IP 查询,而不是调用外部 API。

还不支持 IPv6 吗?也许是时候把这些流量重定向到 IPv4 了 ):

我遇到了问题。我认为我的设置是正确的,但在下载 MaxMind 数据库时收到了 401 错误。

我使用的是标准安装,自托管且为最新版本。
我在 MaxMind 创建了一个账户,并添加了一个新的许可证密钥。

我编辑了 app.yml 的 ENV 部分,如下所示:

  ## MaxMind 地理位置 IP 地址密钥,用于 IP 地址查找
  ## 详情请参见 https://meta.discourse.org/t/-/137387/23
  DISCOURSE_MAXMIND_ACCOUNT_ID: [我的账户 ID]
  DISCOURSE_MAXMIND_LICENSE_KEY: [我的许可证密钥]

然后运行了 ./launcher rebuild app

在重建过程中,日志中记录了这些“401 未授权”错误:

MaxMind 数据库 GeoLite2-City 下载失败。: OpenURI::HTTPError : 401 错误
MaxMind 数据库 GeoLite2-ASN 下载失败。: OpenURI::HTTPError : 401 错误

(当然,我的 /var/www/discourse/vendor/data 目录中也没有任何数据库文件)

根据这个建议,我使用了MaxMind 开发人员门户上找到的命令——使用相同的凭据——直接下载了一个数据库:

curl -O -J -L -u [我的账户 ID]:[我的许可证密钥] \
'https://download.maxmind.com/geoip/databases/GeoLite2-City/download?suffix=tar.gz'

……这运行正常。

那么,从 Discourse 连接时导致 401 错误,我可能遗漏了什么?