To setup a meteor production environment on EC2, we need to install mongoDB as the main database. To use the MUP(Meteor Up tool), it’s easier to use Ubuntu operating system.
This article is about how to setup mongoDB replication on EC2 with Ubuntu 14.02 LTS. Basically, it’s the combination of the following articles:
mongoDB Replication Doc: http://docs.mongodb.org/manual/replication/
mongoDB official doc for platform Amazon EC2: http://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
Install mongoDB on Ubuntu: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
An old article about setting up mongoDB replication on EC2: https://medium.com/cs-math/settings-up-mongodb-replica-sets-on-ec2-with-ubuntu-natty-11-04-c6f300502c5f
Configure MUP: https://github.com/arunoda/meteor-up#accessing-the-database
Oplog Observe Driver: https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver
Storage Considerations
EC2 instances can be configured with either ephemeral storage or persistent storage using the Elastic Block Store (EBS). Ephemeral storage is lost when instances are terminated, so it is generally not recommended unless you understand the data loss implications.
For almost all deployments EBS will be the better choice. For production systems we recommend using
- EBS-optimized EC2 instances
- Provisioned IOPS (PIOPS) EBS volumes
It is recommended to use individual PIOPS EBS volumes for data (1000 IOPS), journal (250 IOPS), and log (100 IOPS).
So first launch three new EC2 instance and create 3 new EBS volumes for each EC2 instances, and then associates volumes to corresponding EC2 instances.
Install mongoDB
For each EC2 instance:
1 2 3 4 |
|
After successfully installed mongoDB, check mongoDB version:
1 2 |
|
Configure EC2 Security Groups
Create a security group named mongodb
, and add a rule:
1 2 |
|
Here 172.31.0.0/16
depends on the network of all instances.
Make sure all EC2 instances can connect to each other, and the web/app server can connect the primary database server.
Associate the security group to each EC2 instance.
Configure hostnames
For each instance, give it a hostname.
1 2 3 |
|
Append the following lines to /etc/hosts
:
1 2 3 |
|
Replace the 172.16.0.x
with the real IPs. It’s better to use intranet addresses.
Reboot all instances.
Create disk partitions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
System configuartion for mongoDB production environment
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 8 9 |
|
Reboot all instances.
Configure mongoDB
Choose one instance as the primary mongoDB, say alice
.
Login alice
, start mongod
with auth
disabled.
Edit /etc/mongod.conf
. Comment out bind_ip = 127.0.0.1
line. Edit dbpath
, logpath
and replSet
.
1 2 3 4 5 |
|
1
|
|
Create administative users:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Stop mongod
1
|
|
Create the key file to be used by each member of the replica set.
1 2 3 4 |
|
Edit /etc/mongod.conf
again.
1 2 |
|
Copy mongod.conf
to all other instances.
Copy /etc/mongodb-keyfile
to all other instances.
Start mongoDB
Start mongoDB on alice
first.
1
|
|
1 2 3 4 5 6 7 8 9 |
|
Check status:
1
|
|
Adjust Priority for Replica Set Member
1 2 3 4 5 |
|
Create additional users to address operational requirements.
For example, the following creates a database administrator for the products database:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Creat oplogger user
1 2 3 |
|
Configure MUP
Edit mup.json
file. Here I use nearest
read preference and majority
write concern.
1 2 3 4 5 6 7 8 9 10 11 |
|