conceptos básicos. seminario web 6: despliegue de producción
TRANSCRIPT
![Page 1: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/1.jpg)
![Page 2: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/2.jpg)
MongoDB Europe 2016Old Billingsgate, London
15th November
Use my code rubenterceno20 for 20% off ticketsmongodb.com/europe
![Page 3: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/3.jpg)
Conceptos Básicos 2016Despliegue en Producción
Rubén TerceñoSenior Solutions Architect, [email protected]@rubenTerceno
![Page 4: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/4.jpg)
Agenda del CursoDate Time Webinar25-Mayo-2016 16:00 CEST Introducción a NoSQL 7-Junio-2016 16:00 CEST Su primera aplicación MongoDB 21-Junio-2016 16:00 CEST Diseño de esquema orientado a documentos 07-Julio-2016 16:00 CEST Indexación avanzada, índices de texto y geoespaciales 19-Julio-2016 16:00 CEST Introducción al Aggregation Framework 28-Julio-2016 16:00 CEST Despliegue en producción
![Page 5: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/5.jpg)
Resumen de lo visto hasta ahora• ¿Porqué existe NoSQL?• Características clave de MongoDB
• Instalación y creación de bases de datos y colecciones• Operaciones CRUD, Índices y explain()
• Diseño de esquema dinámico• Jerarquía y documentos embebidos
• Búsquedas de texto libre y geoespaciales
• Pipeline de Agregación
![Page 6: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/6.jpg)
Production Checklist•Alta Disponibilidad•Escalabilidad Horizontal•Monitorización y Performance Tuning•Backup y Recovery•Seguridad
![Page 7: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/7.jpg)
Replica Sets
• Replica set – 2 to 50 copies
• Replica sets make up a self-healing ‘shard’
• Data center awareness
• Replica sets address:
• High availability
• Data durability, consistency
• Maintenance (e.g., HW swaps)
• Disaster Recovery
Application
Driver
Primary
Secondary
Secondary
Replication
![Page 8: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/8.jpg)
Replica Sets – Workload Isolation
• Replica sets enable workload isolation
• Example: Operational workloads on the primary node,
analytical workloads on the secondary nodes
eCommerce Application
MongoDB PrimaryIn-memory Storage Engine
MongoDB SecondaryWiredTiger Storage Engine
User DataSessions, Cart,Recommendations
MongoDB SecondaryWiredTiger Storage Engine
PersistedUser Data
![Page 9: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/9.jpg)
Node 1
Node 2 Node 3
Replica Set Creation
![Page 10: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/10.jpg)
Node 1(Primary)
Node 2(Secondary)
Node 3(Secondary)
Replication Replication
Heartbeat
Replica Set - Initialize
![Page 11: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/11.jpg)
Node 2(Secondary)
Node 3(Secondary)
Heartbeat
Primary Election
Node 1(Primary)
Replica Set - Failure
![Page 12: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/12.jpg)
Node 1(Primary)
Node 2(Primary)
Node 3(Secondary)
Heartbeat
Replication
Replica Set - Failover
![Page 13: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/13.jpg)
Node 2(Primary)
Node 3(Secondary)
Heartbeat
Replication
Node 1(Recovery)
Replication
Replica Set - Recovery
![Page 14: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/14.jpg)
Node 2(Primary)
Node 3(Secondary)
Heartbeat
Replication
Node 1(Secondary)
Replication
Replica Set - Recovered
![Page 15: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/15.jpg)
writeConcern & readConcern• writeConcern
• Configurable level of acknowledgement• { w: <value>, j: <boolean>, wtimeout: <number> }
• w 1, n, majority, tag
• readConcern• Configurable level of read isolation• readConcern: { level: <"majority"|"local"> }
![Page 16: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/16.jpg)
Node 1(Primary)
Node 2(Secondary)
Node 3(Secondary)
Application
Driver
Read and write
Strong Consistency
![Page 17: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/17.jpg)
Node 1(Primary)
Node 2(Secondary)
Node 3(Secondary)
Application
Driver
Strong Consistency
Read Read
Read and write
![Page 18: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/18.jpg)
readPreference• Read preference describes how MongoDB clients route
read operations to the members of a replica set.• primary• primaryPreferred• secondary• secondaryPreferred• nearest• tags
![Page 19: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/19.jpg)
Elastic Scalability: Automatic Sharding
• Increase or decrease capacity as you go
• Automatic load balancing
• Three types of sharding
• Hash-based
• Range-based
• Tag-aware
Shard 1 Shard 2 Shard 3 Shard N
Horizontally Scalable
![Page 20: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/20.jpg)
Query Routing
• Multiple query optimization models
• Each of the sharding options are appropriate
for different apps / use cases
![Page 21: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/21.jpg)
Sharding key• Sharding key is the way MongoDB partition collections.• The range of the sharding key is split in several chunks.• The chunks are distributed evenly among the available shards
![Page 22: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/22.jpg)
Selecting a sharding key• Probably the most influential decision on performance• A good sharding key has:
• High cardinality• Evenly distributed frequency• A non-monotonic creation rate
• And much more important: is used on queries.• Limitations
• Sharding key is immutable• Sharding key values are immutable• Sharding key can’t be a multikey, geospatial or text index
![Page 23: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/23.jpg)
Config servers and mongos• Config servers store metadata (chunk distribution and location)• The can be configured as a replica set from version 3.2 (CSRS)
• Up to 50 config servers• Hardened failover
• mongos acts as query routers• mongos keep a local copy of config server information• mongos can be deployed on the application server
![Page 24: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/24.jpg)
Sharding, when?• Shard only when needed:
• Vertical scalability is not possible anymore• RAM• CPU• IOPS• Concurrency
• Depending on the server technology the range to start thinking in sharding is around a few Tb of data.
![Page 25: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/25.jpg)
Monitoring• MongoDB offers tools for monitoring the cluster performance
• mongostats• Shows operations per second, memory usage, page faults, queues and more
• mongotop• Provides statistics on a per collection basis
• Mongo Shell• db.serverStatus()• db.serverStatus({ workingSet : 1 })
![Page 26: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/26.jpg)
Profiling• Database profiler
• db.setProfilingLevel(<level>,slowOpThresholdMs)• level 0: Profiler off. Slow operations are always written to the log (default)• level 1: Collects data for operations slower than the threshold• level 2: Collect information for all operations
• Profile info is on system.profile collection on admin database
![Page 27: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/27.jpg)
Logs• Logs
• db.setLogLevel(<level>, <component>)• level 0-5 : Different verbosity levels• level -1 : Inherits verbosity from parent• https://docs.mongodb.com/manual/reference/log-messages/#components
• In order to analyze the log information you can use mtools• https://github.com/rueckstiess/mtools• Not supported by MongoDB, but built by MongoDB employees and
used internally (a lot)
![Page 28: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/28.jpg)
Backup – mongodump• Generates a BSON file and a JSON metadata file.• Better done from a secondary• Potentially generates inconsistent data
• Lock the database during dump db.fsyncLock() & db.fsyncUnlock()• Disconnect a secondary node temporally• Use the -oplog and -oplogReplay options
• mongodump -h myhost –oplog• mongorestore –h myhost –oplogReplay ./cms/dump
• Simple but slow for both backup and restore
![Page 29: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/29.jpg)
Backup – file system copy/snapshot• Copy files on your data directory
• Lock the database first!!• Fastest way to restore• Challenging on a sharded environment
• Disable the chunks balancer sh.setBalancerState(false)• Backup each shard• Backup the config servers
![Page 30: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/30.jpg)
Security• MongoDB is unsecured by default• It’s up to you to use the provided security mechanism
• Authentication Users, Certificates• Authorization Roles• Encrypt communications TLS/SSL• Limit network exposure bindIp• Use dedicated OS users.• …
• Read the security checklist: https://docs.mongodb.com/manual/administration/security-checklist/
![Page 31: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/31.jpg)
MongoDB – We’re here to helpSecurity License SupportTooling Services
![Page 32: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/32.jpg)
MongoDB Compass MongoDB Connector for BI
MongoDB Enterprise Server
MongoDB Enterprise AdvancedC
omm
ercial License
(No A
GP
L Copyleft R
estrictions)
Platform Certifications
MongoDB Ops Manager
Monitoring & Alerting
Query Optimization
Backup & Recovery
Automation & Configuration
Schema Visualization
Data Exploration
Ad-Hoc Queries
Visualization
Analysis
Reporting
LDAP & Kerberos Auditing FIPS 140-2Encryption at Rest
REST APIEmergency Patches
Customer Success Program
On-Demand Online Training
Warranty
Limitation of Liability
Indemnification
24 x
7 S
uppo
rt(1
hou
r SLA
)
![Page 33: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/33.jpg)
MongoDB AtlasDatabase as a service for MongoDB
MongoDB Atlas is…
• Automated: The easiest way to build, launch, and scale apps on MongoDB
• Flexible: The only database as a service with all you need for modern applications
• Secured: Multiple levels of security available to give you peace of mind
• Scalable: Deliver massive scalability with zero downtime as you grow
• Highly available: Your deployments are fault-tolerant and self-healing by default
• High performance: The performance you need for your most demanding workloads
![Page 34: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/34.jpg)
Summary• Los Replica Sets permiten alta disponibilidad y facilitan las operaciones
de mantenimiento.• writeConcern, readConcern y readPreference permiten controlar la persistencia
y consistencia de los datos.
• El sharding permite escalar horizontalmente• La selección de una buena clave de sharding es la clave.
• MongoDB ofrece herramientas para monitorizar y controlar el rendimiento de la base de datos, así como para generar los backups
• ¡La seguridad es lo primero! Usuarios, roles y encriptación• MongoDB proporciona todas la herramientas requeridas para operar su
despliegue en producción con seguridad y de manera profesional.
![Page 35: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/35.jpg)
¿Ya no hay más webinars?• Sigue habiendo webinars en https://www.mongodb.com/webinars
• Si quiere aprender más sobre mongodb:• University: https://university.mongodb.com/
• Si quiere demostrar el mundo lo que sabe:• Certificaciones: https://university.mongodb.com/exams
• Si quiere conocer otras personas que usan mongodb:• MongoDB User Groups (MUGs): http://www.meetup.com/pro/mongodb/
• Denos su opinión, por favor: [email protected]
![Page 36: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/36.jpg)
¿Preguntas?
![Page 37: Conceptos básicos. Seminario web 6: Despliegue de producción](https://reader035.vdocumento.com/reader035/viewer/2022062823/5873ec901a28abb1528b4703/html5/thumbnails/37.jpg)