Slide 1

Slide 1 text

Sandeep  Parikh   Technical  Product  Manager   [email protected]   @crcsmnky   MongoDB     and     Amazon  Web  Services  

Slide 2

Slide 2 text

Agenda   •  MongoDB  basics   – Components   – Deployment  types   – Storage   •  Deploying  a  Replica  Set   •  AWS  Marketplace   •  CloudFormaDon  

Slide 3

Slide 3 text

MongoDB  Components   mongod   Core   database   server   process   mongos   Request   router  for   sharded   deployments   config   Metadata   server  for   sharded   deployments  

Slide 4

Slide 4 text

Amazon  EC2  Components   •  mongod   –  Standard:  L,  XL     –  Hi-­‐Memory:  XL,  XXL  or  4XL   –  Cluster:  increased  capacity   and  bandwidth   •  mongos   –  Deploy  onto  your  app  server   •  config   –  Standard  instances  sufficient  

Slide 5

Slide 5 text

DEPLOYMENT  CONFIGURATIONS  

Slide 6

Slide 6 text

Single  Node   mongod   RAID  10  

Slide 7

Slide 7 text

Replica  Set   mongod   primary   RAID  10   mongod   secondary   RAID  10   mongod   secondary   RAID  10  

Slide 8

Slide 8 text

Replica  Set  –  MulDple  Zones   app   Zone 1 Zone 3 mongod   primary   RAID  10   mongod   secondary   RAID  10   mongod   secondary   RAID  10   Zone 2

Slide 9

Slide 9 text

Replica  Set  –  MulDple  Regions   app   Region 1 Region 2 mongod   primary   RAID  10   mongod   secondary   RAID  10   mongod   secondary   RAID  10  

Slide 10

Slide 10 text

Replica  Set  –  Security  Groups   mongod   primary   RAID  10   mongod   secondary   RAID  10   mongod   secondary   RAID  10   app   “application” “database”

Slide 11

Slide 11 text

Sharded  Deployment   Shard  1   Shard  2   Shard  3   config   config   config   app  server   mongos   app  server   mongos   app  server   mongos  

Slide 12

Slide 12 text

CONFIGURING  DEPLOYMENT  

Slide 13

Slide 13 text

Storage  ConsideraDons   •  Instance  vs.  EBS   –  Ephemeral  vs.  persistent   •  RAID  10   –  “striped  mirrors”   •  4-­‐8  EBS  volumes  for   best  performance   http://en.wikipedia.org/wiki/Nested_RAID_levels#RAID_1_.2B_0

Slide 14

Slide 14 text

Deployment  Tips   •  Know  your  deployment   –  Security  groups   –  Instance  sizes   –  Storage  needed  now  and  later   •  Configure  filesystem  as  ext4  or  XFS   •  Reduce  I/O  overhead   •  Raise  file  descriptor  limits   •  Set  read-­‐ahead  

Slide 15

Slide 15 text

REPLICA  SET  DEPLOYMENT  STEPS  

Slide 16

Slide 16 text

Single  Node   •  We’ll  use  this  as  a   starDng  point   •  Single  EC2  instance   •  4  EBS  volumes   •  RAID10   –  Example:   •  100  GiB  total   •  50  GiB  usable     mongod   RAID  10  

Slide 17

Slide 17 text

CreaDng  the  Components   $ ec2-run-instances ami-41814f28 -n 1 -g database -k cluster-keypair -t m1.large -z us-east-1a! AMI     count   group   keypair   size   zone   Create an instance Create storage volumes (4x) $ ec2-create-volume –s 25 -z us-east-1a! size   zone  

Slide 18

Slide 18 text

Storage  ConfiguraDon   $ ec2-attach-volume vol-e796108a -i i-11eee072 -d /dev/sdh1! volume   instance   device   Attach storage (4x) Start the RAID $ sudo mdadm --create --level=l10 --raid-devices=4 /dev/md0 /dev/sdh*! type   new  device   devices  

Slide 19

Slide 19 text

Storage  ConfiguraDon   $ sudo pvcreate /dev/md0! $ sudo vgcreate vg0 /dev/md0! $ sudo lvcreate -n data vg0! $ sudo mkfs.ext4 /dev/vg0/data! Create volumes and filesystem $ sudo mkdir /data! $ sudo chown mongod:mongod /data! Create mount point and set ownership $ echo ‘/dev/vg0/data /data ext4 defaults,auto,noatime,noexec 0 0’ | sudo tee –a /etc/fstab! $ sudo mount /data! Update the filesystem table and mount

Slide 20

Slide 20 text

Install  MongoDB   $ echo "[10gen]! name=10gen Repository! baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64! gpgcheck=0" | sudo tee -a /etc/yum.repos.d/10gen.repo! Update local repo settings $ sudo yum -y install mongo-10gen-server! $ sudo yum -y install sysstat! Install MongoDB and tools

Slide 21

Slide 21 text

MongoDB  ConfiguraDon   $ sudo $EDITOR /etc/mongod.conf! ...! dbpath=/data! ...! Set the dbpath $ sudo /etc/init.d/mongod start! Start the server now $ mongo! MongoDB shell version: 2.0.4! connecting to: test! >! Connect to MongoDB

Slide 22

Slide 22 text

Adding  AddiDonal  Nodes   •  For  each  node,  first   repeat  steps  for   –  CreaDng  instances  and   volumes   –  Configuring  storage   •  Include  replica  set   parameter  in  MongoDB   configuraDon   •  Start  mongod  

Slide 23

Slide 23 text

MongoDB  ConfiguraDon   $ sudo $EDITOR /etc/mongod.conf! ...! dbpath=/data! replSet=replicaSetName! ...! Set the dbpath $ sudo /etc/init.d/mongod start! Start the server now replica  set  name  

Slide 24

Slide 24 text

IniDalize  Replica  Set   $ mongo! MongoDB shell version: 2.0.4! connecting to: test! >! Connect to MongoDB > rs.initiate()! {! "info2" : "no configuration explicitly specified -- making one",! "me" : "ip-10-127-127-91:27017",! "info" : "Config now saved locally. Should come online in about a minute.",! "ok" : 1! }! Initialize the replica set > rs.add(“ec2-abc.def.amazonaws.com”)! { “ok” : 1 }! Add each replica set member external  DNS  name  

Slide 25

Slide 25 text

Replica  Set  Shell  Prompt   >! The mongo prompt should go from this PRIMARY>! To this SECONDARY>! Or this

Slide 26

Slide 26 text

MARKETPLACE  

Slide 27

Slide 27 text

AWS  Marketplace   •  A  place  to  browse  and  deploy  pre-­‐built  AMIs   •  Free  and  paid  opDons   •  One-­‐click  deploy  (well,  maybe  three)   •  Sofware  available  from  a  variety  of  vendors   •  Deployable  onto  almost  any  instance  

Slide 28

Slide 28 text

AWS  Marketplace  

Slide 29

Slide 29 text

MongoDB  AMI   •  10gen  created   •  Amazon  Linux   •  MongoDB  pre-­‐ installed   •  InstrucDons  for   storage  and   MongoDB   configuraDon  

Slide 30

Slide 30 text

CLOUDFORMATION  

Slide 31

Slide 31 text

AWS  CloudFormaDon   •  Gives  devs  and  admins  easy  way  to  create   and  manage  AWS  resources   •  Create  text-­‐based  templates  which  describe   resources  in  your  stack   – EC2,  EBS,  Load  Balancer,  CDN   •  Templates  are  JSON   – managed  like  code  and  pushed  to  S3  

Slide 32

Slide 32 text

MongoDB  via  CloudFormaDon   •  Reference  templates  for  building  your  own   deployment   – Single  node  for  test  and  development   – 3-­‐node  replica  set  for  producDon-­‐level   deployments   •  Customize  them  for  your  own  needs  

Slide 33

Slide 33 text

MongoDB  Templates   •  Single-­‐node   – Single  mongod  with  4  EBS  volumes  in  a  RAID10   •  Replica  set   – Each  node  similar  to  single  node   – Primary  configured  in  “parent”  template   – Secondary  configured  in  “child”  template   – “Parent”  template  refers  to  “child”  template  to   create  2  secondary  instances  

Slide 34

Slide 34 text

Template  ConfiguraDon   •  Amazon  Linux   •  Inputs   – Key  Name,  Instance  Size,  Volume  Size   •  New  security  group   – Port  22:  open  to  all   – Port  27017:  open  to  instances  in  group   •  4  EBS  volumes,  ajachments    

Slide 35

Slide 35 text

Template  Inputs  

Slide 36

Slide 36 text

Template  ConfiguraDon   •  Instance  installs  MongoDB  via  yum   •  Creates  RAID10   •  Configures  storage  (LVM,  FS,  etc.)   •  Configures  MongoDB  

Slide 37

Slide 37 text

Customizing  Templates   •  Add  more  storage  volumes   •  Add  more  instances   •  Customize  security  group  rules   •  Customize  zones/regions  

Slide 38

Slide 38 text

Download  Sample  Templates   •  hjp://www.mongodb.org/display/DOCS/ AutomaDng+Deployment+with +CloudFormaDon   – MongoDB_SingleNode.template   – MongoDB_ReplicaSetStack.template   – MongoDB_ReplicaSetMember.template  

Slide 39

Slide 39 text

WRAP  UP  

Slide 40

Slide 40 text

Learn  More   •  Amazon  EC2  info  (incl.  in-­‐depth  guide):   hjp://www.mongodb.org/display/DOCS/Amazon+EC2     •  AutomaDng  Deployment  on  AWS  with  CloudFormaDon   hjp://www.mongodb.org/display/DOCS/AutomaDng +Deployment+with+CloudFormaDon     •  MongoDB  AMI  via  AWS  Marketplace   hjps://aws.amazon.com/marketplace/pp/B007IBMJPI/     •  MongoDB  on  Amazon  Web  Services  white  paper:   hjp://www.10gen.com/white-­‐papers  

Slide 41

Slide 41 text

QuesDons  &  Comments   •  Sandeep  Parikh   –  [email protected]   –  @crcsmnky   •  MongoDB   –  hjp://www.mongodb.org   –  Downloads,  Docs,  Forums,  etc.   •  10gen   –  hjp://www.10gen.com/contact   –  [email protected]   –  Training,  ConsulDng,  Support