使用PM2 启动时报错Error: connect ETIMEDOUT
来源:10-9 session连接redis
默笙轻歌
2021-03-03
在我使用npm run pm2 启动项目后 pm2的提示已经启动,下面是我的node脚本
"pm2":"cross-env NODE_ENV=pro pm2 start ./bin/www --watch"
命令执行完后项目启动:
┌─────┬────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬─────── ───┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼─────── ───┼──────────┤
│ 0 │ www │ default │ 0.0.0 │ fork │ 2876 │ 87s │ 0 │ online │ 0% │ 29.6mb │ fhtd2020 │ disabled │
└─────┴────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴─────── ───┴──────────┘
当我在前端发起请求的时候,请求被挂起,并且pm2日志中报错:
Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (C:\Server\tdzq_server\node_modules\mysql\lib\Connection.js:409:13)
at Object.onceWrapper (events.js:421:28)
at Socket.emit (events.js:315:20)
at Socket._onTimeout (net.js:482:8)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
--------------------
at Protocol._enqueue (C:\Server\tdzq_server\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Server\tdzq_server\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Server\tdzq_server\node_modules\mysql\lib\Connection.js:116:18)
at execute (C:\Server\tdzq_server\db\mysql.js:13:11)
at verifyUser (C:\Server\tdzq_server\controller\setting_system.js:7:12)
at C:\Server\tdzq_server\routes\index.js:19:27
at Layer.handle [as handle_request] (C:\Server\tdzq_server\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Server\tdzq_server\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Server\tdzq_server\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Server\tdzq_server\node_modules\express\lib\router\layer.js:95:5) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
这是我项目数据库的配置:
const env = process.env.NODE_ENV;
let MYSQL_CONF = {};
if (env === 'dev') {
MYSQL_CONF = {
host: '127.0.0.1',
user: 'root',
password: '@1q2w3e4r!',
port: '8886',
database: 'tdzq_server'
};
};
if (env === 'pro') {
MYSQL_CONF = {
host: '127.0.0.1',
user: 'root',
password: '@1q2w3e4r!',
port: '8886',
database: 'tdzq'
};
};
module.exports = {
MYSQL_CONF
};
写回答
1回答
-
看样子是 mysql 连接的错误。
你手动将 env 改成 pro ,然后试试 mysql 能否连接成功?
112021-03-03
相似问题