1951980
问题的起因是,在阿里云的ECS上尝试部署Egg的项目的,但是一直报
ERROR 449 nodejs.SequelizeAccessDeniedError: Access denied for user 'root'@'localhost' (using password: YES)
[egg-scripts] at Utils.Promise.tap.then.catch.err (/home/egg/hc_user/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:141:19)
[egg-scripts] at tryCatcher (/home/egg/hc_user/node_modules/bluebird/js/release/util.js:16:23)
[egg-scripts] at Promise._settlePromiseFromHandler (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:512:31)
[egg-scripts] at Promise._settlePromise (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:569:18)
[egg-scripts] at Promise._settlePromise0 (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:614:10)
[egg-scripts] at Promise._settlePromises (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:690:18)
[egg-scripts] at _drainQueueStep (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:138:12)
[egg-scripts] at _drainQueue (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:131:9)
[egg-scripts] at Async._drainQueues (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:147:5)
[egg-scripts] at Immediate.Async.drainQueues [as _onImmediate] (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:17:14)
[egg-scripts] at runCallback (timers.js:693:18)
[egg-scripts] at tryOnImmediate (timers.js:664:5)
[egg-scripts] at processImmediate (timers.js:646:5)
[egg-scripts] name: "SequelizeAccessDeniedError"
[egg-scripts] parent: {"code":"ER_ACCESS_DENIED_ERROR","errno":1045,"sqlState":"28000","sqlMessage":"Access denied for user 'root'@'localhost' (using password: YES)"}
[egg-scripts] original: {"code":"ER_ACCESS_DENIED_ERROR","errno":1045,"sqlState":"28000","sqlMessage":"Access denied for user 'root'@'localhost' (using password: YES)"}
数据库是阿里云的RDS Mysql,已开白名单,在ECS上尝试过ping RDS 的链接,可以ping通。 尝试过在RDS多加一个testuser的用户,配置上testuser的账号密码后,还是报一样的错误。如果 user 改变了 'root'@'localhost' 这里应该会变成'testuser'@'localhost' 的吧? config.prod.js 的配置如下
'use strict';
module.exports = () => {
const config = exports = {};
// change to your own sequelize configurations
config.sequelize = {
dialect: 'mysql',
port: 3306,
hostname: '2123123123123123.mysql.rds.aliyuncs.com',
database: 'test',
user: 'testuser',
password: '12123123123',
define: {
underscored: false,
},
};
return config;
};
config.default.js 中没有sequelize 的配置,config.local.js 中的sequelize 配置也改成和config.prod.js 问题一样。 数据库的账号密码也在dms-rds.aliyun.com/main.do 上试过登陆,是没有问题的。 因为这个ECS 是用来测试的,所以内部也安装了一个mysql。 目前不清楚到底项目是按那个配置在运行,链接的mysql是那个,用那个账号密码来链接。 ECS上部署的项目 是用
egg-scripts start --daemon
来运行的,同样也有试过
EGG_SERVER_ENV=prod egg-scripts start --daemon
// 或者
export NODE_ENV=production && egg-scripts start --daemon
问题一样。
为了了解项目的目前情况,加了一个app.js 的文件
'use strict';
class AppBootHook {
constructor(app) {
console.log('\x1B[31m%s\x1b[0m:', `constructor... app: ${JSON.stringify(app)}`);
app.beforeStart(() => {
app.logger.info('\x1B[31m%s\x1b[0m:', `constructor beforeStart app.config.env: ${app.config.env}, process.env.NODE_ENV: ${process.env.NODE_ENV}`);
});
app.ready((...a) => {
app.logger.info('\x1B[31m%s\x1b[0m:', `constructor ready... a: ${JSON.stringify(a)}`);
});
app.beforeClose((...a) => {
app.logger.info('\x1B[31m%s\x1b[0m:', `constructor beforeClose... a: ${JSON.stringify(a)}`);
});
app.once('server', server => {
// websocket
app.logger.info('\x1B[31m%s\x1b[0m:', `constructor once('server')... server: ${JSON.stringify(server)}`);
});
app.on('error', (err, ctx) => {
// report error
app.logger.info('\x1B[31m%s\x1b[0m:', `constructor on('error')... ctx: ${JSON.stringify(ctx)} , err: ${JSON.stringify(err)}`);
});
app.on('request', ctx => {
// log receive request
app.logger.info('\x1B[31m%s\x1b[0m:', `constructor on('request')... ctx: ${JSON.stringify(ctx)}`);
});
app.on('response', ctx => {
// ctx.starttime is set by framework
const used = Date.now() - ctx.starttime;
app.logger.info('\x1B[31m%s\x1b[0m:', `constructor on('response')... ctx: ${JSON.stringify(ctx)}, used: ${used}`);
// log total cost
});
}
async beforeStart(...a) {
console.log('\x1B[31m%s\x1b[0m:', `beforeStart... a: ${JSON.stringify(a)}`);
}
async ready(...a) {
console.log('\x1B[31m%s\x1b[0m:', `ready... a: ${JSON.stringify(a)}`);
}
configDidLoad(...a) {
// Config,plugin files have did load.
console.log('\x1B[31m%s\x1b[0m:', `configDidLoad... a: ${JSON.stringify(a)}`);
}
async didLoad(...a) {
// All files have did load, start plugin here.
console.log('\x1B[31m%s\x1b[0m:', `didLoad... a: ${JSON.stringify(a)}`);
}
async willReady(...a) {
// All plugins have started, can do some thing before app ready
console.log('\x1B[31m%s\x1b[0m:', `willReady... a: ${JSON.stringify(a)}`);
}
async didReady(...a) {
// Worker is ready, can do some things
// don't need to block the app boot.
console.log('\x1B[31m%s\x1b[0m:', `didReady... a: ${JSON.stringify(a)}`);
}
async serverDidReady(...a) {
// Server is listening.
console.log('\x1B[31m%s\x1b[0m:', `serverDidReady... a: ${JSON.stringify(a)}`);
}
async beforeClose(...a) {
// Do some thing before app close.
console.log('\x1B[31m%s\x1b[0m:', `beforeClose... a: ${JSON.stringify(a)}`);
}
}
module.exports = AppBootHook;
在本地 egg-bin dev 的时候输出的是
在ECS上 运行 egg-scripts start --daemon 的时候
> egg-scripts start --daemon
[egg-scripts] Starting egg application at /home/egg/hc_user
[egg-scripts] Run node /home/egg/hc_user/node_modules/egg-scripts/lib/start-cluster {"title":"egg-server-hc_user","framework":"/home/egg/hc_user/node_modules/egg","baseDir":"/home/egg/hc_user"} --title=egg-server-hc_user
[egg-scripts] Save log file to /root/logs
[egg-scripts] Wait Start: 1...
[egg-scripts] Wait Start: 2...
[egg-scripts] tail -n 100 /root/logs/master-stderr.log
[egg-scripts] Got error when startup:
[egg-scripts] 2018-10-12 10:38:39,134 ERROR 449 nodejs.SequelizeAccessDeniedError: Access denied for user 'root'@'localhost' (using password: YES)
[egg-scripts] at Utils.Promise.tap.then.catch.err (/home/egg/hc_user/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:141:19)
[egg-scripts] at tryCatcher (/home/egg/hc_user/node_modules/bluebird/js/release/util.js:16:23)
[egg-scripts] at Promise._settlePromiseFromHandler (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:512:31)
[egg-scripts] at Promise._settlePromise (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:569:18)
[egg-scripts] at Promise._settlePromise0 (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:614:10)
[egg-scripts] at Promise._settlePromises (/home/egg/hc_user/node_modules/bluebird/js/release/promise.js:690:18)
[egg-scripts] at _drainQueueStep (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:138:12)
[egg-scripts] at _drainQueue (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:131:9)
[egg-scripts] at Async._drainQueues (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:147:5)
[egg-scripts] at Immediate.Async.drainQueues [as _onImmediate] (/home/egg/hc_user/node_modules/bluebird/js/release/async.js:17:14)
[egg-scripts] at runCallback (timers.js:693:18)
[egg-scripts] at tryOnImmediate (timers.js:664:5)
[egg-scripts] at processImmediate (timers.js:646:5)
[egg-scripts] name: "SequelizeAccessDeniedError"
[egg-scripts] parent: {"code":"ER_ACCESS_DENIED_ERROR","errno":1045,"sqlState":"28000","sqlMessage":"Access denied for user 'root'@'localhost' (using password: YES)"}
[egg-scripts] original: {"code":"ER_ACCESS_DENIED_ERROR","errno":1045,"sqlState":"28000","sqlMessage":"Access denied for user 'root'@'localhost' (using password: YES)"}
还没有加载到app.js 的感觉。 请问,要怎样去解决这个问题? egg.js 的生命周期方法,有在egg-sequelize测试数据库链接前的方法吗?