gio
gio

Reputation: 891

Connecting Node VM to SQL VM on VPN Azure

I have two VM on Azure: Machine A: is the server which run a Nodejs application Machine B: is a VM which is running a mysql instance

Machine A and B are in the same VPN, either with a local address. I tested the connection from Machine A to B using ping and it works.

My problem is regarding the database connection from the nodejs app and mysql instance.

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];

ERROR on 'npm start':

Unhandled rejection Error: SequelizeConnectionRefusedError: connect ECONNREFUSED 10.0.0.4:3306 at /home/giovannimarino/api-http-revo/app.js:20:11 at tryCatcher (/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/promise.js:512:31) at Promise._settlePromise (/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/promise.js:569:18) at Promise._settlePromise0 (/home/giovannimarino/api-http-revo/node_modules/bluebird/js/release/promise.js:614:10) at 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) at 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)

The following screenshot are the firewall configuration:

Machine B: enter image description here

Machine A enter image description here

Upvotes: 0

Views: 405

Answers (1)

Chandra Eskay
Chandra Eskay

Reputation: 2203

This might be due to firewall blocking your DB connections. To confirm do a telnet on the port 3306 and if it's found to be blocking then setup an inbound rule for allowing network traffic on port 3306 on both the systems.

More information here on how to setup network traffic rules.

Upvotes: 0

Related Questions