egg icon indicating copy to clipboard operation
egg copied to clipboard

怎么解决sofa-node注册服务到zookeeper端口被占用问题?

Open nxg916 opened this issue 4 years ago • 0 comments

What happens?

多个服务注册到zookeeper, 经常会出现无法注册的错误

2021-02-10 05:56:16,545 ERROR 12601 nodejs.EADDRINUSEError: bind EADDRINUSE null:2505
    at listenOnMasterHandle (net.js:1385:18)
    at rr (internal/cluster/child.js:138:12)
    at Worker.<anonymous> (internal/cluster/child.js:105:7)
    at process.onInternalMessage (internal/cluster/utils.js:48:5)
    at process.emit (events.js:327:22)
    at process.emit (/Users/admin/Documents/Projects/moogrid-server-product/node_modules/source-map-support/source-map-support.js:495:21)
    at emit (internal/child_process.js:903:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
errno: -48
code: "EADDRINUSE"
syscall: "bind"
address: null
port: 2505
name: "EADDRINUSEError"
pid: 12601

有两个问题请教, 谢谢

1,出现错误的原因是端口号被占用了吗? 2,注册服务必须要指明端口号才行吗?不能自动分配端口号吗? 3,有什么更好的解决办法吗?

下面是多个服务的配置,大约有n个服务,只举例了两个,端口是自定义的,如果不写会默认走12201端口,也会出现类似上面的错误,注册不上的服务从新指定一个别的端口,比如2505改成25505就可以正常注册了

server_1的配置

config.rpc = {
    registry: {
        address: '127.0.0.1:2181', // zookeeper 服务的地址
    },
    client: {
        responseTimeout: 3000, // responseTimeout(可选): RPC 的超时时长,默认为 3 秒
    },
    server: {
        namespace: 'com.alipay.sofa.rpc.protobuf',
        port: 2505, 
        version: '1.0',
        group: 'SOFA',
    },
};

server_2的配置

config.rpc = {
    registry: {
        address: '127.0.0.1:2181',
    },
    client: {
        responseTimeout: 3000, 
    },
    server: {
        namespace: 'com.alipay.sofa.rpc.protobuf',
        port: 2501, 
        version: '1.0',
        group: 'SOFA',
    },
};

引用的库

 "sofa-node": "^1.0.1",

还有一个费解的问题,我断开的服务端口明明是25505可是下面的警告却是25506,干嘛要加一位数呢?

create connection: bolt://127.0.0.1:25506?startTime=1612907482114&pid=12369&uniqueId=&dynamic=true&appName=egg-server&timeout=3000&serialization=protobuf&weight=100&accepts=100000&language=nodejs&rpcVer=50400&protocol=&interface=com.alipay.sofa.rpc.protobuf.ProtoService&version=1.0&group=SOFA failed, caused by connect ECONNREFUSED 127.0.0.1:25506

nxg916 avatar Feb 09 '21 22:02 nxg916