conceptos básicos. seminario web 6: despliegue de producción

Post on 10-Jan-2017

628 Views

Category:

Data & Analytics

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MongoDB Europe 2016Old Billingsgate, London

15th November

Use my code rubenterceno20 for 20% off ticketsmongodb.com/europe

Conceptos Básicos 2016Despliegue en Producción

Rubén TerceñoSenior Solutions Architect, EMEAruben@mongodb.com@rubenTerceno

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

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

Production Checklist•Alta Disponibilidad•Escalabilidad Horizontal•Monitorización y Performance Tuning•Backup y Recovery•Seguridad

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

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

Node 1

Node 2 Node 3

Replica Set Creation

Node 1(Primary)

Node 2(Secondary)

Node 3(Secondary)

Replication Replication

Heartbeat

Replica Set - Initialize

Node 2(Secondary)

Node 3(Secondary)

Heartbeat

Primary Election

Node 1(Primary)

Replica Set - Failure

Node 1(Primary)

Node 2(Primary)

Node 3(Secondary)

Heartbeat

Replication

Replica Set - Failover

Node 2(Primary)

Node 3(Secondary)

Heartbeat

Replication

Node 1(Recovery)

Replication

Replica Set - Recovery

Node 2(Primary)

Node 3(Secondary)

Heartbeat

Replication

Node 1(Secondary)

Replication

Replica Set - Recovered

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"> }

Node 1(Primary)

Node 2(Secondary)

Node 3(Secondary)

Application

Driver

Read and write

Strong Consistency

Node 1(Primary)

Node 2(Secondary)

Node 3(Secondary)

Application

Driver

Strong Consistency

Read Read

Read and write

readPreference• Read preference describes how MongoDB clients route

read operations to the members of a replica set.• primary• primaryPreferred• secondary• secondaryPreferred• nearest• tags

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

Query Routing

• Multiple query optimization models

• Each of the sharding options are appropriate

for different apps / use cases

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

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

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

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.

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 })

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

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)

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

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

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/

MongoDB – We’re here to helpSecurity License SupportTooling Services

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

)

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

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.

¿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: back-to-basics@mongodb.com

¿Preguntas?

top related