在群集模式下,ElasticSearch不适用于基本身份验证

3pmvbmvn  于 2022-12-22  发布在  ElasticSearch
关注(0)|答案(1)|浏览(222)

我们有一个ElasticSearch服务在两个节点上作为集群运行。没有身份验证,它工作正常。指向单个节点也工作正常。但是,当我们使用ConnectionPool运行时,它抛出以下错误。尝试使用SniffingConnectionPoolStaticConnectionPool。两者都没有帮助。我们使用Elasticsearch.NetNest版本7.0。

# FailureReason: MaxRetriesReached while attempting PUT on http://ely-es-2-perf.westindia.cloudapp.azure.com:9200/user_profile/_doc/2e18d331-9734-4915-b7cd-4893a270b52c
# Audit trail of this API call:
# Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response:
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Inner Exception: One or more errors occurred. (Failed to ping the specified node.) (Failed to ping the specified node.)
System.AggregateException: One or more errors occurred. (Failed to ping the specified node.) (Failed to ping the specified node.)
 ---> Elasticsearch.Net.PipelineException: Failed to ping the specified node.
 ---> Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node.
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)
   --- End of inner exception stack trace ---
 ---> (Inner Exception #1) Elasticsearch.Net.PipelineException: Failed to ping the specified node.
 ---> Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node.
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)<---

# Exception:
Elasticsearch.Net.ElasticsearchClientException: Maximum number of retries reached, failed over to all the known alive nodes before failing. Call: Status code 504 from: HEAD /
 ---> System.AggregateException: One or more errors occurred. (Failed to ping the specified node.) (Failed to ping the specified node.)
 ---> Elasticsearch.Net.PipelineException: Failed to ping the specified node.
 ---> Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node.
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)
   --- End of inner exception stack trace ---
 ---> (Inner Exception #1) Elasticsearch.Net.PipelineException: Failed to ping the specified node.
 ---> Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node.
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Elasticsearch.Net.RequestPipeline.PingAsync(Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.PingAsync(IRequestPipeline pipeline, Node node, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)<---

   --- End of inner exception stack trace ---

我方代码

var uris = new[]
{
    new Uri(_configuration["ElasticAPI1"]),
    new Uri(_configuration["ElasticAPI2"])
};
var connectionPool = new SniffingConnectionPool(uris);
ConnectionSettings settings = new ConnectionSettings(connectionPool).BasicAuthentication(_configuration["ES.Name"], _configuration["ES.Password"]);
ElasticClient client = new ElasticClient(settings);
settings.DefaultIndex(indexname);

//Add data
var response = await client.IndexAsync<Model>(model, null).ConfigureAwait(false);

**编辑:**以前没有设置身份验证时,相同的代码可以工作。在SniffingConnectionPool中工作正常。

uz75evzq

uz75evzq1#

当客户端尝试使用最简单的请求“ping”节点以检查其是否可用时,会发生此问题。因此,受身份验证保护的节点将响应401,然后您将在您的一端遇到问题。
我通过在ConnectionSettings中添加.DisablePing()来解决这个问题。
在此之后,您将需要在节点关闭但请求已发送到它的情况下处理错误。
我还发现您正在使用的用户应该具有cluster:monitor权限
更多信息-〉https://github.com/elastic/elasticsearch-net/issues/3870

相关问题