簡體   English   中英

NodeJS Express JS-MongoError:無法連接到服務器

[英]NodeJS Express JS - MongoError: failed to connect to server

這個錯誤是什么意思?

$ pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/home/tealou/.pm2/pm2.log last 15 lines:
PM2        | 2017-03-29 07:25:45: App [www] with id [0] and pid [29444], exited with code [1] via signal [SIGINT]
PM2        | 2017-03-29 07:25:45: Starting execution sequence in -fork mode- for app name:www id:0
PM2        | 2017-03-29 07:25:45: App name:www id:0 online
PM2        | 2017-03-29 07:25:46: App [www] with id [0] and pid [29460], exited with code [1] via signal [SIGINT]
PM2        | 2017-03-29 07:25:46: Starting execution sequence in -fork mode- for app name:www id:0
PM2        | 2017-03-29 07:25:46: App name:www id:0 online
PM2        | 2017-03-29 07:25:47: App [www] with id [0] and pid [29477], exited with code [1] via signal [SIGINT]
PM2        | 2017-03-29 07:25:47: Starting execution sequence in -fork mode- for app name:www id:0
PM2        | 2017-03-29 07:25:47: App name:www id:0 online
PM2        | 2017-03-29 07:25:48: App [www] with id [0] and pid [29487], exited with code [1] via signal [SIGINT]
PM2        | 2017-03-29 07:25:48: Starting execution sequence in -fork mode- for app name:www id:0
PM2        | 2017-03-29 07:25:48: App name:www id:0 online
PM2        | 2017-03-29 07:25:49: App [www] with id [0] and pid [29497], exited with code [1] via signal [SIGINT]
PM2        | 2017-03-29 07:25:49: Starting execution sequence in -fork mode- for app name:www id:0
PM2        | 2017-03-29 07:25:49: App name:www id:0 online

/home/tealou/.pm2/logs/www-out-0.log last 15 lines:
0|www      | POST /input/XnCuYLP72jGwMt25bPVuuM81uq2 200 233.304 ms - 9
0|www      | Successfully connected to mongodb
0|www      | POST /input/2psLUE6VB7tEdC0sACCl8Yn1oC6 200 133.400 ms - 9
0|www      | Successfully connected to mongodb
0|www      | POST /input/2IcNjH69dLyMhrCSi0voaM5OLW8 200 87.776 ms - 9
0|www      | Successfully connected to mongodb
0|www      | POST /input/lJOVksaP8LMhgOl8XOCofV6ZeZZ 200 117.275 ms - 9
0|www      | POST /input/YbJriPtV1FZWUDwgZq46zFqL7BC 200 147.066 ms - 9
0|www      | Successfully connected to mongodb
0|www      | POST /input/lb8BbtOobixWcfI4dItIaS0U2KZ 200 196.825 ms - 9
0|www      | POST /input/97PWLQquQIFxTgpSLZa4rgvXSLR 200 42.662 ms - 9
0|www      | POST /input/G4ZrX1Wz88Kx1gcDBN8bw4exi3M 200 127.855 ms - 9
0|www      | Successfully connected to mongodb
0|www      | POST /input/D2wBHNc4BX19tDkGqXfD8ClY6E0 200 126.571 ms - 9
0|www      | Successfully connected to mongodb

/home/tealou/.pm2/logs/www-error-0.log last 15 lines:
0|www      | MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/topologies/server.js:327:35)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at emit (events.js:188:7)
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/pool.js:274:12)
0|www      |     at g (events.js:286:16)
0|www      |     at emitTwo (events.js:106:13)
0|www      |     at emit (events.js:191:7)
0|www      |     at Socket.<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/connection.js:177:49)
0|www      |     at Socket.g (events.js:286:16)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at Socket.emit (events.js:188:7)
0|www      |     at emitErrorNT (net.js:1272:8)
0|www      |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
0|www      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)

[STREAMING] Now streaming realtime logs for [all] processes
0|www      | MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/topologies/server.js:327:35)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at emit (events.js:188:7)
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/pool.js:274:12)
0|www      |     at g (events.js:286:16)
0|www      |     at emitTwo (events.js:106:13)
0|www      |     at emit (events.js:191:7)
0|www      |     at Socket.<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/connection.js:177:49)
0|www      |     at Socket.g (events.js:286:16)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at Socket.emit (events.js:188:7)
0|www      |     at emitErrorNT (net.js:1272:8)
0|www      |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
0|www      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)
PM2        | App [www] with id [0] and pid [29513], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:www id:0
PM2        | App name:www id:0 online
0|www      | MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/topologies/server.js:327:35)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at emit (events.js:188:7)
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/pool.js:274:12)
0|www      |     at g (events.js:286:16)
0|www      |     at emitTwo (events.js:106:13)
0|www      |     at emit (events.js:191:7)
0|www      |     at Socket.<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/connection.js:177:49)
0|www      |     at Socket.g (events.js:286:16)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at Socket.emit (events.js:188:7)
0|www      |     at emitErrorNT (net.js:1272:8)
0|www      |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
0|www      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)
PM2        | App [www] with id [0] and pid [29527], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:www id:0
PM2        | App name:www id:0 online
0|www      | MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/topologies/server.js:327:35)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at emit (events.js:188:7)
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/pool.js:274:12)
0|www      |     at g (events.js:286:16)
0|www      |     at emitTwo (events.js:106:13)
0|www      |     at emit (events.js:191:7)
0|www      |     at Socket.<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/connection.js:177:49)
0|www      |     at Socket.g (events.js:286:16)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at Socket.emit (events.js:188:7)
0|www      |     at emitErrorNT (net.js:1272:8)
0|www      |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
0|www      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)
PM2        | App [www] with id [0] and pid [29544], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:www id:0
PM2        | App name:www id:0 online
0|www      | MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/topologies/server.js:327:35)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at emit (events.js:188:7)
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/pool.js:274:12)
0|www      |     at g (events.js:286:16)
0|www      |     at emitTwo (events.js:106:13)
0|www      |     at emit (events.js:191:7)
0|www      |     at Socket.<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/connection.js:177:49)
0|www      |     at Socket.g (events.js:286:16)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at Socket.emit (events.js:188:7)
0|www      |     at emitErrorNT (net.js:1272:8)
0|www      |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
0|www      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)
PM2        | App [www] with id [0] and pid [29554], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:www id:0
PM2        | App name:www id:0 online
0|www      | MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/topologies/server.js:327:35)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at emit (events.js:188:7)
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/pool.js:274:12)
0|www      |     at g (events.js:286:16)
0|www      |     at emitTwo (events.js:106:13)
0|www      |     at emit (events.js:191:7)
0|www      |     at Socket.<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/connection.js:177:49)
0|www      |     at Socket.g (events.js:286:16)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at Socket.emit (events.js:188:7)
0|www      |     at emitErrorNT (net.js:1272:8)
0|www      |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
0|www      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)
PM2        | App [www] with id [0] and pid [29564], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:www id:0
PM2        | App name:www id:0 online

在我的本地主機上可以,但是在生產服務器上會中斷。

有任何想法嗎?

編輯:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        23G   23G   43M 100% /
devtmpfs        7.9G     0  7.9G   0% /dev
tmpfs           7.EDIT:9G     0  7.9G   0% /dev/shm
tmpfs           7.9G  1.5M  7.9G   1% /run
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs           1.6G     0  1.6G   0% /run/user/1002

編輯2:

$ mongo
MongoDB shell version: 3.2.6
connecting to: test
2017-03-29T07:21:59.231+0100 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-03-29T07:21:59.237+0100 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

編輯3:

$ pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/home/tealou/.pm2/pm2.log last 15 lines:
PM2        | 2017-03-29 07:29:48: Time                 : Wed Mar 29 2017 07:29:48 GMT+0100 (BST)
PM2        | 2017-03-29 07:29:48: PM2 version          : 2.4.2
PM2        | 2017-03-29 07:29:48: Node.js version      : 6.2.2
PM2        | 2017-03-29 07:29:48: Current arch         : x64
PM2        | 2017-03-29 07:29:48: PM2 home             : /home/citizensense/.pm2
PM2        | 2017-03-29 07:29:48: PM2 PID file         : /home/tealou/.pm2/pm2.pid
PM2        | 2017-03-29 07:29:48: RPC socket file      : /home/tealou/.pm2/rpc.sock
PM2        | 2017-03-29 07:29:48: BUS socket file      : /home/tealou/.pm2/pub.sock
PM2        | 2017-03-29 07:29:48: Application log path : /home/tealou/.pm2/logs
PM2        | 2017-03-29 07:29:48: Process dump file    : /home/tealou/.pm2/dump.pm2
PM2        | 2017-03-29 07:29:48: Concurrent actions   : 2
PM2        | 2017-03-29 07:29:48: SIGTERM timeout      : 1600
PM2        | 2017-03-29 07:29:48: ===============================================================================
PM2        | 2017-03-29 07:29:49: Starting execution sequence in -fork mode- for app name:www id:0
PM2        | 2017-03-29 07:29:49: App name:www id:0 online

/home/tealou/.pm2/logs/www-error-0.log last 15 lines:
0|www      | MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/topologies/server.js:327:35)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at emit (events.js:188:7)
0|www      |     at .<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/pool.js:274:12)
0|www      |     at g (events.js:286:16)
0|www      |     at emitTwo (events.js:106:13)
0|www      |     at emit (events.js:191:7)
0|www      |     at Socket.<anonymous> (/usr/local/chroot/project-1/node_modules/mongodb-core/lib/connection/connection.js:177:49)
0|www      |     at Socket.g (events.js:286:16)
0|www      |     at emitOne (events.js:96:13)
0|www      |     at Socket.emit (events.js:188:7)
0|www      |     at emitErrorNT (net.js:1272:8)
0|www      |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
0|www      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)

編輯4:

$ pm2 logs
[PM2] Spawning PM2 daemon with pm2_home=/home/tealou/.pm2

這是什么!??

僅根據端口號(27017)(這是MongoDB的默認端口)來判斷,似乎無法連接到服務器上的MongoDB。 嘗試安裝它 ,並確保它在端口27017上運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM