elasticsearch exceptions ConnectionError

fslejnso  于 2023-06-21  发布在  ElasticSearch
关注(0)|答案(4)|浏览(149)

我在做一个Django应用。它使用Haystack和elasticsearch作为后端。
当我跑的时候

./manage.py rebuild_index

我得到这个错误:
aborted.',error(61,'Connection refused '))),原因是:ProtocolError(('Connection aborted.',error(61,'Connection refused')))
是什么造成的?
日志:

./manage.py rebuild_index
No handlers could be found for logger "django_facebook.models"

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
Failed to clear Elasticsearch index: ConnectionError(('Connection aborted.', error(61, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(61, 'Connection refused')))
All documents removed.
Indexing 4 restos
ERROR:root:Error updating litchee using default 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 184, in update
    bulk_index(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 145, in bulk
    for ok, item in streaming_bulk(client, actions, **kwargs):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 104, in streaming_bulk
    resp = client.bulk(bulk_actions, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 646, in bulk
    params=params, body=self._bulk_body(body))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/transport.py", line 284, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 51, in perform_request
    raise ConnectionError('N/A', str(e), e)
ConnectionError: ConnectionError(('Connection aborted.', error(61, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(61, 'Connection refused')))
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/rebuild_index.py", line 16, in handle
    call_command('update_index', **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 159, in call_command
    return klass.execute(*args, **defaults)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 195, in handle
    return super(Command, self).handle(*items, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 385, in handle
    label_output = self.handle_label(label, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 184, in update
    bulk_index(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 145, in bulk
    for ok, item in streaming_bulk(client, actions, **kwargs):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 104, in streaming_bulk
    resp = client.bulk(bulk_actions, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 646, in bulk
    params=params, body=self._bulk_body(body))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/transport.py", line 284, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 51, in perform_request
    raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', error(61, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(61, 'Connection refused')))

运行bin/elasticsearch得到:

[2014-08-25 17:53:38,901][INFO ][node                     ] [Arize] version[1.3.1], pid[1781], build[2de6dc5/2014-07-28T14:45:15Z]
[2014-08-25 17:53:38,902][INFO ][node                     ] [Arize] initializing ...
[2014-08-25 17:53:38,976][INFO ][plugins                  ] [Arize] loaded [], sites []
[2014-08-25 17:53:54,722][INFO ][node                     ] [Arize] initialized
[2014-08-25 17:53:54,734][INFO ][node                     ] [Arize] starting ...
[2014-08-25 17:53:56,131][INFO ][transport                ] [Arize] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/192.168.1.83:9300]}
[2014-08-25 17:53:57,168][INFO ][discovery                ] [Arize] elasticsearch/uWwljr09R0-hZ1-5eH4NlQ
[2014-08-25 17:54:00,714][INFO ][cluster.service          ] [Arize] new_master [Arize][uWwljr09R0-hZ1-5eH4NlQ][deeptis-mbp.local.lan][inet[/192.168.1.83:9300]], reason: zen-disco-join (elected_as_master)
[2014-08-25 17:54:00,987][INFO ][http                     ] [Arize] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/192.168.1.83:9200]}
[2014-08-25 17:54:00,988][INFO ][node                     ] [Arize] started
[2014-08-25 17:54:01,337][INFO ][gateway                  ] [Arize] recovered [0] indices into cluster_state

但是在运行ps时-一个elasticsearch不会显示为一个正在运行的进程。
我做错了什么?

wz8daaqr

wz8daaqr1#

Connection refused仅仅意味着到Elasticsearch HTTP服务的TCP连接被拒绝。原因可能有很多,例如您为HTTP端点使用了错误的主机或端口,或者由于某种原因elasticsearch节点没有运行。
在尝试使用Haystack之前,通过发出直接的HTTP请求来测试elasticsearch的工作情况,如下所示:

curl -X GET http://192.168.77.88:9200/_cat/indices

其中192.168.77.88是elasticsearch节点的IP地址,9200是TCP端口。成功后,检查并仔细检查您在Haystack配置中是否具有相同的URL配置。

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://192.168.77.88:9200/',
        'INDEX_NAME': 'haystack',
    },
}
3zwtqj6y

3zwtqj6y2#

我也有同样的问题。刚刚通过在端口9200上运行Elasticsearch解决了这个问题。如果你是在windows上,后藤Elasticsearch安装的bin目录,然后运行你正在使用的任何Elasticsearch版本的批处理文件。

fkaflof6

fkaflof63#

anton评论救了我!
我来到这里是因为我试图运行elasticsearch-curator,我得到了以下错误(即使没有防火墙或其他连接拦截器):

user@host:/opt/elasticsearch-curator$ curator_cli show-indices | more
2021-11-20 16:33:11,396 INFO      Instantiating client object
2021-11-20 16:33:11,397 INFO      Testing client connectivity
2021-11-20 16:33:11,403 ERROR     HTTP N/A error: HTTPConnectionPool(host='127.0.0.1', port=9200): Max retries exceeded with url: / (Cause
d by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5ca8ba7d60>: Failed to establish a new connection: [Errno 111] C
onnection refused'))
2021-11-20 16:33:11,403 CRITICAL  Curator cannot proceed. Exiting.

由于我实验室中的许多其他特殊性,我在我的/etc/elasticsearch/elasticsearch.yml中有一行network.hosts: 10.0.0.134,这意味着该VM的私有IP在配置中是固定的,因此我的elasticsearch没有绑定到所有地址,因为在大多数情况下它应该绑定到所有地址。解决方案是在文件/etc/elasticsearch/elasticsearch. yml中添加一行network.bind_host: 0.0.0.0。这样,我的/etc/elasticsearch/elasticsearch.yml的网络会话如下:

# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 10.0.0.134
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
network.bind_host: 0.0.0.0
#
# For more information, consult the network module documentation.
#

现在我的elasticsearch-curator工作得很好:

shaka@virgo:/opt/elasticsearch-curator$ sudo curator_cli show-indices | more
2021-11-20 17:30:02,294 INFO      Instantiating client object
2021-11-20 17:30:02,295 INFO      Testing client connectivity
/opt/python/3.9.4/lib/python3.9/site-packages/elasticsearch/connection/base.py:200: ElasticsearchWarning: Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.15/security-minimal-setup.html to enable security.
2021-11-20 17:30:02,301 INFO      Successfully created Elasticsearch client object with provided settings
/opt/python/3.9.4/lib/python3.9/site-packages/elasticsearch/connection/base.py:200: ElasticsearchWarning: this request accesses system indices: [.apm-agent-configuration, .apm-custom-link, .async-search, .kibana_7.14.0_001, .kibana_7.14.1_001, .kibana_7.15.0_001, .kibana_7.15.1_001, .kibana_7.15.2_001, .kibana_task_manager_7.14.0_001, .kibana_task_manager_7.14.1_001, .kibana_task_manager_7.15.0_001, .kibana_task_manager_7.15.1_001, .kibana_task_manager_7.15.2_001, .tasks], but in a future major version, direct access to system indices will be prevented by default
.apm-agent-configuration
.apm-custom-link
.async-search
.kibana-event-log-7.14.0-000001

我希望它能帮助那些面临同样问题的人。

2nbm6dog

2nbm6dog4#

I make it  sudo nano /etc/elasticsearch/elasticsearch.yml
network.host: 45.#.#.#
transport.host: localhost

对我很有效

相关问题