【问题标题】:Unable to set up Elasticsearch for Wagtail无法为 Wagtail 设置 Elasticsearch
【发布时间】:2017-03-16 17:36:08
【问题描述】:

到目前为止,我使用了以下指南:

http://docs.wagtail.io/en/v1.9/advanced_topics/performance.html

我补充说:

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch',
        'INDEX': '{{ project_name }}',
    },
}

到我的 base.py。当我运行$ ./manage.py update_index 时,我得到以下输出:

Updating backend: default
default: Rebuilding index {{ project_name }}
Traceback (most recent call last):
  File "./manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/management/commands/update_index.py", line 120, in handle
    self.update_backend(backend_name, schema_only=options.get('schema_only', False))
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/management/commands/update_index.py", line 73, in update_backend
    index = rebuilder.start()
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 613, in start
    self.reset_index()
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 609, in reset_index
    self.index.reset()
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 598, in reset
    self.delete()
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 499, in delete
    self.es.indices.delete(self.name)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 73, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/client/indices.py", line 200, in delete
    params=params)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 318, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 123, in perform_request
    raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f3b708fa210>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f3b708fa210>: Failed to establish a new connection: [Errno 111] Connection refused)

提前致谢。

编辑更新:

看起来我的 Linode 可能没有足够的 RAM。在全局安装后尝试使用 ./bin/elasticsearch 运行 ES 时出现以下错误:

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/emtr0/elasticsearch-5.3.0/hs_err_pid24719.log

谢谢。

【问题讨论】:

  • 您的 Elasticsearch 服务器似乎没有运行。请您在docs.wagtail.io/en/v1.9/topics/search/… 尝试更详细的配置说明?
  • @gasman 我会尝试并尽快回复您。
  • @gasman 为什么您分享的页面显示的信息与我使用的指南不同?目录不同。我在任何地方都没有wagtail/wagtail/wagtailsearch/backends/elasticsearch.py。所有的设置改变,包括在哪里添加 wagtailsearch sn-p,都需要在 base.py 的末尾,对吧?
  • @gasman 我还尝试了根据您的文档链接允许端口 9200,但这也不起作用。我最近用 python 3.6 重新部署了整个东西,但是在尝试更新索引时遇到了同样的错误。 sn-p 保存没有错误,我在 requirements.txt 中有它,但 update_index 仍然产生上述错误。

标签: python linux django elasticsearch wagtail


【解决方案1】:

对于仍有问题的人,请确保您的 Elasticsearch 版本和 elasticsearch-py 版本相同。 elasticsearch 和 py 版本都需要安装。这为我解决了问题。

【讨论】:

    【解决方案2】:

    对不起,我没有足够的声誉直接在你的问题下发表评论,我希望这能帮助你解决问题:

    • 在本地安装elasticsearch,运行它,然后使用简单的curl http://localhost:9200 检查它是否正在运行(应该在端口9200 上)。如果您收到 JSON 响应,它正在运行 ?

    • 设置一个盆景 (http://bonsai.io) 实例以运行托管的弹性搜索服务器,只需将盆景的服务器 URL 复制粘贴到您的配置中,但它可能需要更多设置(SSL 等),并且是在 elasticsearch 版本方面受到更多限制

    奖励:如果您是 macOS 用户,安装/运行 Elastic Search 就像 brew install elasticsearch(尽管可以设置特定版本)一样简单,如果您不介意让它在前景。

    【讨论】:

    • 感谢您的回复。我使用 pip 在虚拟环境中安装了 elasticsearch。我使用的指南没有提到手动运行服务器。后来我在系统范围内安装了它,但仍然找不到运行它的命令。
    • 你是怎么安装的?你在什么操作系统上运行它?
    • ElasticSearch python 应用程序本身与 Elastic Search 不同。它应该作为一个独立的应用程序与您的 django 应用程序一起运行。在不同的端口上
    • 我已经在带有 Ubuntu 16.04 LTS 的 Linode 上设置了它。起初我按照docs.wagtail.io/en/v1.9/advanced_topics/performance.html 的指南进行操作,然后在您回复后,我在系统范围内安装了它以防万一。由于某种原因,没有为其创建 bin,并且它不会接受启动命令,因为服务未与之关联。
    • 用于弹性搜索的 Python 应用程序确实不同(即使全局安装)。它是弹性搜索服务器的客户端。它可以在您的本地机器上运行,也可以在外部服务器上运行。您是否按照这些说明来运行本地弹性搜索服务器? elastic.co/guide/en/elasticsearch/reference/current/… 或者如果你喜欢 docker,不妨试试这个:elastic.co/guide/en/elasticsearch/reference/current/docker.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    • 2019-05-24
    • 2012-02-26
    • 2020-01-08
    • 2021-01-07
    • 1970-01-01
    相关资源
    最近更新 更多