ElasticSearch:Https在容器内不起作用

时间:2019-07-08 02:56:12

标签: docker elasticsearch docker-compose asp.net-core-2.0

我已经为我的一个应用程序(Net core 2.1)实现了ElasticSearch。

从本地或部署到任何普通服务器(在我们公司内部),一切正常。日志已成功记录。

当我在Docker容器中部署应用程序时,问题就开始了。它引发异常。根据我的发现,这是因为ElasticSearch Url是https并带有证书。

Docker文件:

FROM mcr.microsoft.com/dotnet/core/runtime:2.1
WORKDIR /app
ADD test/bin/Release/netcoreapp2.1/linux-x64/* /app/
ENTRYPOINT ["dotnet", "test.dll", "--console"]

撰写文件:

services: 

  app: # service definition: Mandatory - PRINCIPLE # 2

    # Mandatory - PRINCIPLE # 9 - images in DTR to use the assigned org name for the project context.
    # project org name is 'om-cockpit'
    image: __IMAGE__


    # Mandatory - PRINCIPLE # 5
    deploy:
        replicas: 1
        restart_policy:
            condition: on-failure

        # Mandatory - PRINCIPLE # 3
        resources:
            limits:
                #cpus: "0.1" # Not supported on Windows platforms
                memory: 256M

        # Mandatory - PRINCIPLE # 4
        placement:
            constraints:
                - node.role == worker
                - node.labels.test== true

        # Mandatory - PRINCIPLE # 11
        labels:
            com.docker.ucp.access.label: /Shared/test/ops

    environment:
    # We'll use the entrypoint and a command param to specify which ports the app should to listen on
    #    ASPNETCORE_URLS: http://+:8080 # This env var is overridden by hosting.json, so use the --urls cmd param
        ASPNETCORE_ENVIRONMENT: Dev
        ASPNETCORE_URLS: http://+:8110

    # Override/define the entrypoint for the image
    entrypoint: /app/O.WP.Work --console --urls=http://*:8110 --environment=Dev


    # Defines port mapping on the host to the container port
    # Service ports should be exposed only if it's necessary to reach the application from external resource
    # PRINCIPLE # 7
    ports:
        #   - "8050:8050"
        - target: 8110 #container
          published: 12111 #public port
          protocol: tcp

我收到此异常

Elastic Search : 2019-07-07T08:02:32.3113052Z Caught exception while preforming bulk operation to Elasticsearch: Elasticsearch.Net.ElasticsearchClientException: The SSL connection could not be established, see inner exception. ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)

   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)

--- End of stack trace from previous location where exception was thrown ---

   at System.Net.Security.SslState.ThrowIfExceptional()

   at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)

   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)

   at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)

   at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__47_1(IAsyncResult iar)

   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

--- End of stack trace from previous location where exception was thrown ---

   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)

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

   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)

   at System.Threading.Tasks.ValueTask`1.get_Result()

   at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)

   at System.Threading.Tasks.ValueTask`1.get_Result()

   at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)

   at System.Threading.Tasks.ValueTask`1.get_Result()

   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)

   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)

   at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData) in c:\Projects\elastic\net-master\src\Elasticsearch.Net\Connection\HttpConnection-CoreFx.cs:line 73

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

   at Elasticsearch.Net.Transport`1.HandleElasticsearchClientException(RequestData data, Exception clientException, IElasticsearchResponse response) in c:\Projects\elastic\net-master\src\Elasticsearch.Net\Transport\Transport.cs:line 196

   at Elasticsearch.Net.Transport`1.FinalizeResponse[TResponse](RequestData requestData, IRequestPipeline pipeline, List`1 seenExceptions, TResponse response) in c:\Projects\elastic\net-master\src\Elasticsearch.Net\Transport\Transport.cs:line 180

   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters) in c:\Projects\elastic\net-master\src\Elasticsearch.Net\Transport\Transport.cs:line 97

   at Serilog.Sinks.Elasticsearch.ElasticsearchSink.EmitBatchChecked[T](IEnumerable`1 events)

   at Serilog.Sinks.Elasticsearch.ElasticsearchSink.EmitBatch(IEnumerable`1 events)

0 个答案:

没有答案