The MEAN stack pt.1: Prep

After hearing about Angular.js and learning a little more about the benefits of reduced context switching, I decided to investigate the MEAN stack. I had a little trouble getting things going, but after getting it set up, I finally feel like I have almost all of a clean miniature production environment to develop in.

There are a few parts that have come together to make this feel so great.

DNS settings on my router let me access each host on my local network automatically using a Fully Qualified Domain Name. I set the hostname on the VM, and that is all that is required for every other machine on the nework to resolve “” to that machine.

Installing the base Ubuntu 12.04.3 system works well, and I have a good script to follow to get mongo and the MEAN stack set up perfectly on a new VM so that it can join the cluster easily.

MongoDB replica sets, once set up,  provide automatic failover. I can just shut off the primary server VM and not even notice. It’s so magical that I’m not even sure which machine is the primary unless I log into the database and ask it (Which I don’t do, because it doesn’t matter, because it just works).

So, here goes a fast, simple install of the mean stack from scratch. I will go step by step through everything I do to get set up.

Router Setup:

I use DD-WRT for my router, so your router may have a different way to set things up.

Under the Services -> Services tabs I set the DHCP lan domain to “”, enable DNSmasq, and I put “local=/local/” in the additional options.


OS install:

I use Ubuntu 12.04.3 server edition running in Virtualbox. I Set my VirtualBox network to “Bridged”



When installing, I set the hostname to the FQDN ie “” for this machine, and I use apg on another machine to generate strong passwords that I then write down somewhere.

I accept almost all settings at their default values, and don’t install any software at this time.

Install OpenSSh:
To generate strong SSL keys, I have decided to delay installing OpenSSH server untill after the first boot to give /dev/random time to gather more entropy.

On the first boot, I open a junk file for editing and hit a bunch of random keys for a while. (Try to think random thoughts while you are hitting the random keys, and if possible look at some stars in the sky or leaves rustling on trees outside so your key presses will be even more random  :)

I check to make sure there are at least 2000 bits of entropy in the entropy pool. It may take a few minutes to get enough entropy, but you want a truly random SSH host key. You don’t want this to happen to you.

$ cat /proc/sys/kernel/random/entropy_avail

#pound on keys some

$ cat /proc/sys/kernel/random/entropy_avail

$ sudo apt-get update
$ sudo apt-get install openssh-server

More coming in part 2



Leave a Reply