我想這是我的第一個代碼,我得到錯誤開始學習節點羣集收到錯誤
const cluster = require('cluster');
const http = require('http');
const numCPUs = 4;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('online', function(worker) {
console.log('Worker ' + worker.process.pid + ' is online');
});
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
// Workers can share any TCP connection
// In this case it is an HTTP server
http.createServer((req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(8000);
}
這是我收到的錯誤: -
工人11056在線 工人11057 is online Worker 11058 is online Worker 11059 is online events.js:141 throw er; //未處理 '錯誤' 事件 ^
錯誤:綁定EADDRINUSE空:8000 在Object.exports._errnoException(util.js中:870:11) 在exports._exceptionWithHostPort(util.js中:893:20) at工作人員處的rr(cluster.js:594:14) 處的cb(net.js:1302:16) 。 (cluster.js:564:9) 正在處理。 (cluster.js:714:8) at processingTem(events.js:92:20) at process.emit(events.js:172:7) at handleMessage(internal/child_process.js:689:10) 在Pipe.channel.onread(internal/child_process.js:440:11) events.js:141 throw er; //未處理 '錯誤' 事件 ^
錯誤:綁定EADDRINUSE空:8000 在Object.exports._errnoException(util.js中:870:11) 在exports._exceptionWithHostPort(util.js中:893:20) at工作人員處的rr(cluster.js:594:14) 處的cb(net.js:1302:16) 。 (cluster.js:564:9) 正在處理。 (cluster.js:714:8) at processingTem(events.js:92:20) at process.emit(events.js:172:7) at handleMessage(internal/child_process.js:689:10) 在Pipe.channel.onread(internal/child_process.js:440:11) events.js:141 throw er; //未處理 '錯誤' 事件 ^
錯誤:綁定EADDRINUSE空:8000 在Object.exports._errnoException(util.js中:870:11) 在exports._exceptionWithHostPort(util.js中:893:20) at工作人員處的rr(cluster.js:594:14) 處的cb(net.js:1302:16) 。 (cluster.js:564:9) 正在處理。 (cluster.js:714:8) at processingTem(events.js:92:20) at process.emit(events.js:172:7) at handleMessage(internal/child_process.js:689:10) 在Pipe.channel.onread(internal/child_process.js:440:11) 工人11056死亡 工人11057死亡 工人11058死亡 events.js:141 throw er; //未處理 '錯誤' 事件 ^
錯誤:綁定EADDRINUSE空:8000 在Object.exports._errnoException(util.js中:870:11) 在exports._exceptionWithHostPort(util.js中:893:20) at工作人員處的rr(cluster.js:594:14) 處的cb(net.js:1302:16) 。 (cluster.js:564:9) 正在處理。 (cluster.js:714:8) at processingTem(events.js:92:20) at process.emit(events.js:172:7) at handleMessage(internal/child_process.js:689:10) 在Pipe.channel。onread(internal/child_process.js:440:11) worker 11059 died
可以請你建議我怎麼???一些鏈接或例子? –
我已經用建議更新了我的答案。 (我的第一個回答基本上是錯誤的,對此抱歉,我已經刪除了不正確的信息,代碼中沒有錯誤,我的錯誤) – Trott
沒有其他進程使用此端口8000.我試過更改港口,現在它正在工作 –