nginx配置nacos的grpc连接

报错信息:
java.util.concurrent.TimeoutException: Waited 3000 milliseconds (plus 501200 nanoseconds delay) for com.alibaba.nacos.shaded.io.grpc.stub.ClientCallsKaTeX parse error: Expected '}', got 'EOF' at end of input: ….ProtoLiteUtilsMessageMarshaller@5981f4a6, responseMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils M e s s a g e M a r s h a l l e r @ 63 d f a d a 0 , s c h e m a D e s c r i p t o r = c o m . a l i b a b a . n a c o s . a p i . g r p c . a u t o . R e q u e s t G r p c MessageMarshaller@63dfada0, schemaDescriptor=com.alibaba.nacos.api.grpc.auto.RequestGrpc MessageMarshaller@63dfada0,schemaDescriptor=com.alibaba.nacos.api.grpc.auto.RequestGrpcRequestMethodDescriptorSupplier@6f231ced}}}}}]]
at com.alibaba.nacos.shaded.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:508) ~[nacos-client-2.0.4.jar:na]
java.util.concurrent.ExecutionException: com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
at com.alibaba.nacos.shaded.com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:566) ~[nacos-client-2.0.4.jar:na]
at com.alibaba.nacos.shaded.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:445) ~[nacos-client-2.0.4.jar:na]

解决方案:

1、暴露 nacos 集群的端口偏移1000

例如:nacos默认端口8848,需要把9848(8848+1000)也暴露出来

注意:如果是docker集群部署还需要把 7848 端口也一起暴露出来。(7848 端口则用于节点选举来确定集群领袖 Leader

在这里插入图片描述

2、修改 nginx.conf 的文件

http {
	# 负载均衡配置
	upstream lb-nocos{
		server 127.0.0.1:8845 weight=1;
		server 127.0.0.1:8847 weight=1;
		server 127.0.0.1:8849 weight=1;
	}
	# nacos服务配置
	server {
        listen       8848;
        server_name  localhost;
		location / {
			# 反向代理
			proxy_pass http://lb-nocos;
        }
	}
}

# nacos的grpc协议配置
stream {
       # 负载均衡配置(TCP长连接配置)
       upstream lb-nocos-tcp{
         server 127.0.0.1:9845 weight=1;
         server 127.0.0.1:9847 weight=1;
         server 127.0.0.1:9849 weight=1;
       }

        server {
          listen 9848;
          proxy_pass lb-nocos-tcp;
        }
}

集群部署参考:https://blog.csdn.net/weixin_51311218/article/details/122617027

GitHub 加速计划 / na / nacos
29.83 K
12.75 K
下载
Nacos是由阿里巴巴开源的服务治理中间件,集成了动态服务发现、配置管理和服务元数据管理功能,广泛应用于微服务架构中,简化服务治理过程。
最近提交(Master分支:3 个月前 )
4334cd16 * Support custom client configuration timeout.(#12748) * Add UT.(#12748) 19 天前
b04d2266 23 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐