After the microservice project is deployed, it cannot connect to the Nacos service and reports an error Server check fail

Project scenario:

When using docker to deploy a microservice to start, it was found that nacos could not be connected, and the microservice could not read nacos and reported an error, which caused the startup to fail.


Problem Description

c.a.n.c.remote.client.grpc.GrpcClient    : Server check fail, please check server XXX.X.XXX.XXX ,port XXX is available , error ={}

java.util.concurrent.TimeoutException: Waited 3000 milliseconds (plus 259427 nanoseconds delay) for com.alibaba.nacos.shaded.io.grpc.stub.ClientCalls$GrpcFuture@442675e1[status=PENDING, info=[GrpcFuture{clientCall={delegate={delegate=ClientCallImpl{method=MethodDescriptor{fullMethodName=Request/request, type=UNARY, idempotent=false, safe=false, sampledToLocalTracing=true, requestMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller@6166e06f, responseMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller@49e202ad, schemaDescriptor=com.alibaba.nacos.api.grpc.auto.RequestGrpc$RequestMethodDescriptorSupplier@1c72da34}}}}}]]


Cause Analysis:

When the microservice starts, the service information will be registered on Nacos. However, when the IP for Nacos service registration is selected, it is selected to be registered as an internal network IP, so it cannot communicate with the public IP port exposed by the host, and cannot connect and register to nacos. , causing the service to fail to start.


solution:

1. Declare that the service instance is a public IP

spring:
  cloud:
    nacos:
      discovery:
        #你的服务器公网IP
        ip: XXX.X.X.XXX 

2. Adopt Host mode

Add --net=host to the startup command to use the host's ip address.

docker run --name XXXX --net=host 

Guess you like

Origin blog.csdn.net/weixin_40579395/article/details/127009240