bjori / vagrant-mongodb

Bootstrap multiple MongoDBs VMs (replicaset w/o auth, standalone w/o auth). Useful for developing locally
25 stars 9 forks source link

Vagrant plugin and puppet manifests for MongoDB

Creates (by default) 8 virtual machines based on Ubuntu Lucid (64bits).

The ReplicaSet servers will have their /etc/hosts synchronized among them.

All servers will retrieve and install the latest MongoDB from the official 10gen repository.

Several new Vagrant configurations are available in the Vagrantfile to configure a MongoDB replicaset, such as the servers priority to become primaries.

A new Vagrant comand is availalbe to initialize the replicaset based on the configuration in the Vagrantfile, and to create users for authenticated setup.

Usage

$ git clone https://github.com/bjori/vagrant-mongodb.git
$ cd vagrant-mongodb

Boot up all servers

$ vagrant up # Will bootup *all 8 servers*

Or only bootup a normal ReplicaSet

$ vagrant up primary secondary tertiary # Will bootup only one ReplicaSet

To bootup ReplicaSet with authentication enabled

$ vagrant up primaryauth secondaryauth tertiaryauth # RS with auth

Don't want ReplicaSets? This will create a standalone MongoDB server

$ vagrant up standalone # Will bootup the standalone server

And this will create a standalone MongoDB server with authentication enabled

$ vagrant up standaloneauth # Standalone with auth

Initializing ReplicaSets

To initialize the ReplicaSet for the first time, type

$ vagrant mongo primary --init-replicaset

and/or

$ vagrant mongo primaryauth --init-replicaset

To initialize the ReplicaSet for the authenticated environment.

Creating users

To create a first time admin user on a standalone server run

$ vagrant mongo standaloneauth -c -u adm -p pass --db admin

or for ReplicaSet environment

$ vagrant mongo primaryauth -c -u adm -p pass --db admin

To create more users you have to authenticate using that admin user

$ vagrant mongo standaloneauth -c -u user -p mypass --db mydb --authuser adm --authpass pass --authdb admin

/etc/hosts

The ReplicaSets are configured using the hostnames defined in the Vagrantfile. I recommend you add all these hosts to your local /etc/hosts (the servers themselves already have).

By default the following hostnames and IPs are used

172.16.1.10 primaryauth.rs.local primaryauth
172.16.1.11 secondaryauth.rs.local secondaryauth
172.16.1.12 tertiaryauth.rs.local tertiaryauth
172.16.2.10 standaloneauth.local standaloneauth

172.16.3.10 primary.rs.local primary
172.16.3.11 secondary.rs.local secondary
172.16.3.12 tertiary.rs.local tertiary
172.16.4.10 standalone.local standalone

Thats it folks!

And there we go! Now you have a full MongoDB replicaset running in its own virtualized network, and all of the servers are running on the default ports. To connect to MongoDB, just fire up your favorite driver and connect :)

Fixing my mess?

This is the first time I have ever created a puppet module, puppet manifest, vagrant plugin or written Ruby code at all. There is very likely something could have been done better or prettier. I would love it if you forked this repo and applied your skillz cleaning things up.

Everything should work out of the box though :)

TODO