在VPN Azure上将节点VM连接到SQL VM

时间:2017-07-03 13:07:18

标签: mysql node.js azure azure-sql-database sequelize.js

我在Azure上有两个VM: 机器A:是运行Nodejs应用程序的服务器 机器B:是运行mysql实例的VM

计算机A和B在同一个VPN中,具有本地地址。我使用ping测试了从机器A到B的连接,它可以工作。

我的问题是关于来自nodejs app和mysql实例的数据库连接。

app.js

var express = require('express'),
  config = require('./config/config'),
  db = require('./app/models');

var app = express();

module.exports = require('./config/express')(app, config);

db.sequelize
  .sync()
  .then(function () {
    if (!module.parent) {
      app.listen(config.port, function () {
        console.log('Express server listening on port ' + config.port);
      });
    }
  }).catch(function (e) {
    throw new Error(e);
  });

config.js

var path = require('path'),
    rootPath = path.normalize(__dirname + '/..'),
    env = process.env.NODE_ENV || 'production';

var config = {
  development: {
    root: rootPath,
    app: {
      name: 'api-http-revo'
    },
    port: process.env.PORT || 3000,
    db: 'mysql://localhost/api-http-revo-development'
  },

  test: {
    root: rootPath,
    app: {
      name: 'api-http-revo'
    },
    port: process.env.PORT || 3000,
    db: 'mysql://localhost/api-http-revo-test'
  },

  production: {
    root: rootPath,
    app: {
      name: 'api-http-revo'
    },
    port: process.env.PORT || 3000,
    db: {
      host: '10.0.0.4', //Local Ip address on VPN
      user: 'myusername',
      password: 'mypassword',
      database: 'db-revo',
      port: 3306
    }
  }
};

module.exports = config[env];

错误开始' npm start':

  

未处理拒绝错误:SequelizeConnectionRefusedError:connect   ECONNREFUSED 10.0.0.4:3306       在/home/giovannimarino/api-http-revo/app.js:20:11       在tryCatcher(/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/util.js:16:23)       在Promise._settlePromiseFromHandler(/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/promise.js:512:31)       在Promise._settlePromise(/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/promise.js:569:18)       在Promise._settlePromise0(/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/promise.js:614:10)       在Promise._settlePromises(/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/promise.js:689:18)       at Async._drainQueue(/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/async.js:133:16)       at Async._drainQueues(/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/async.js:143:10)       在Immediate.Async.drainQueues [as _onImmediate](/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/async.js:17:14)       at processImmediate [as _immediateCallback](timers.js:383:17)

以下屏幕截图是防火墙配置:

机器B: enter image description here

机器A enter image description here

1 个答案:

答案 0 :(得分:0)

这可能是由于防火墙阻止了您的数据库连接。要确认在端口3306上执行telnet并且发现它是否阻塞,请设置入站规则以允许两个系统上的端口3306上的网络流量。

有关how to setup network traffic rules的更多信息。