Monday, 14 November 2016

Connecting to a mongod instance from a different VM

I've got two CentOS installations running within Virtual Box. I want to run mongodb on one which will be optimised for this purpose, the other for developing and running my node apps.

VM1. CentOS full desktop install as documented here

This is the environment that I'm doing my development, running node etc.

VM2. CentOS minimal install, command line only

I've followed the instructions as documented in my other post to install mongod here.

Connect

Now I want to connect from VM1 to the mongod service running in VM2.

First change the network adapter of VM2 away from 'NAT' (the default) to 'Bridged Adapter' this will make this VM a full citizen of the network, it will get its own IP address and can be accessed on it from any other machine on the network.
Next amend the mongod.conf file in /ect/ by adding in the new IP address.

$ ip addr show
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:5c:41:9c brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.10/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 85748sec preferred_lft 85748sec
    inet6 fe80::a00:27ff:fe5c:419c/64 scope link
       valid_lft forever preferred_lft forever

 
$ su -c 'vi /etc/mongod.conf'
 
# Listen to local and LAN interface.
bind_ip = 127.0.0.1,192.168.0.10


This will allow remote access to the service as documented here

once this is done restart the mongod service on VM1 and connect from the remote VM thus:
$ mongo 192.168.0.10

No comments:

Post a Comment