Nacos集群端口不能连续的原因
2023-08-13 本文已影响0人
曾经像素有点低
1.现象:
nacos2.0在搭建过程中如果端口号是连续的,则会启动失败。
2.举例说明:
| ip(地址) | port(端口号) |
|---|---|
| 192.168.08.11 | 8841 |
| 192.168.08.11 | 8842 |
| 192.168.08.11 | 8843 |
我们看到8841、8842、8843三个连续的端口,这样三个nacos是不能同时启动成功的。
如果先启动了8841,那么8842在启动的时候就会报出端口号被占用相关的错误。
3.原因:
Nacos2.0增加了gRPC通信模式,因此需要添加2个端口。新端口根据配置的主端口(server.port)以一定的偏移量生成.
意思就是:比如我们设置的端口号是:8841
实际上占用的是↓↓↓↓
- ①客户端gRPC请求服务器端口:
9841(8841+1000) - ②服务器端gRPC请求服务器端端口:
9842(8841+1001)
当我们在启动端口号为8842的nacos时候,8842所对应的的客户端gRPC端口:9842已经被 8841的 服务器端gRPC使用了。所以才会导致8842的nacos启动失败
nacos官网上有描述:
Compared with 1.X, Nacos2.0 adds gRPC communication mode,
so there are 2 ports need to be added.
The new ports are generated with
a certain offset based on the configured
main port (server.port).
| port | offset from main port | description |
|---|---|---|
| 9848 | 1000 | The client gRPC requests the server port, which is used by the client to initiate a connection and request to the server |
| 9849 | 1001 | Server-side gRPC requests server-side port, used for synchronization between services, etc. |
本来想上传截图的,但是简书一直上传图片失败。这是官网相关的链接地址大家可以去了解一下。