oss4b: installing & managing mysql like a real devops

77
OSS4B: Installing & managing MySQL like a real devops Automation in production Frédéric Descamps 20 Sep 2013

Upload: frederic-descamps

Post on 25-Jan-2017

148 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: OSS4B: Installing & Managing MySQL like a real devops

OSS4B: Installing & managing MySQL like a real devops

Automation in production

Frédéric Descamps20 Sep 2013

Page 2: OSS4B: Installing & Managing MySQL like a real devops

Who am I ?

• Frédéric Descamps “lefred”• @lefred• http://about.me/lefred• Percona Consultant since 2011• Managing MySQL since 3.23 (as far as

I remember)• devops believer

2

Page 3: OSS4B: Installing & Managing MySQL like a real devops

Agenda

• devops ?• Installation automation• Test automation• Schema management automation

3

Page 4: OSS4B: Installing & Managing MySQL like a real devops

devops ?

devopsis a movement willing to help

aligning IT with company needs

(starting by aligning devs and ops)

@endemics - Gildas Le Nadan - “The Devops movement”, Mixit Lyon 2011

Page 5: OSS4B: Installing & Managing MySQL like a real devops

We can say that devops is bringing together people

and practices from development and

operations

devops ?

Page 6: OSS4B: Installing & Managing MySQL like a real devops

We can say that devops is bringing together people

and practices from development and

operations

devops ? I am a happy dev !I am a happy op !

Page 7: OSS4B: Installing & Managing MySQL like a real devops

devops ?

devops is about CAMS

Page 8: OSS4B: Installing & Managing MySQL like a real devops

devops ?

CULTUREAUTOMATION

MEASUREMENTSHARING

@botchagalupe @damonedwards http://www.opscode.com/blog/2010/07/16/what-devops-means-to-me/

Page 9: OSS4B: Installing & Managing MySQL like a real devops

devops ?

What techniques can I use ?

Page 10: OSS4B: Installing & Managing MySQL like a real devops

MonitoringInfrastructure as Code

Continuous Improvement

Page 11: OSS4B: Installing & Managing MySQL like a real devops

devops & DBAs ?

What about DBAs ?

Page 12: OSS4B: Installing & Managing MySQL like a real devops

devops & DBAs !

Join the team, follow the

movement !

Page 13: OSS4B: Installing & Managing MySQL like a real devops

devdbaops

You are already between devs

and ops

Page 14: OSS4B: Installing & Managing MySQL like a real devops

devdbaops

You are already between devs

and ops

I am a happy DBA !

Page 15: OSS4B: Installing & Managing MySQL like a real devops

CAM

CULTUREAUTOMATION

MEASUREMENTSHARING

Page 16: OSS4B: Installing & Managing MySQL like a real devops

CAMS 1st principle: CULTURE

Communication !

Usually DEVS communicate with managers (all kinds of!)

Page 17: OSS4B: Installing & Managing MySQL like a real devops

CAMS 1st principle: CULTURE

Communication !

OPS communicate with support, ISP's and... their servers

Page 18: OSS4B: Installing & Managing MySQL like a real devops

CAMS 1st principle: CULTURE

Communication !

DBAs just don't communicate

Page 19: OSS4B: Installing & Managing MySQL like a real devops

CAMS 1st principle: CULTURE

The interaction between developers, sysadmins, dbas and all the actors

should begin from the start of any projects !

Page 20: OSS4B: Installing & Managing MySQL like a real devops
Page 21: OSS4B: Installing & Managing MySQL like a real devops

and do itin team !

Page 22: OSS4B: Installing & Managing MySQL like a real devops

CAMS 1st principle: CULTURE

Discuss everything database related with developers and sysadmins:

disks and raid design

schema design & partitions

additional columns & indexes

tables repair, ...

Page 23: OSS4B: Installing & Managing MySQL like a real devops

CAMS 1st principle: CULTURE

This is just a culture change

Page 24: OSS4B: Installing & Managing MySQL like a real devops

CAM

CULTUREAUTOMATIONMEASUREMENT

SHARING

Page 25: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

Can we automate DBAs job ?

Should we ??

Even if we have only one database ?

Page 26: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

Page 27: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

YES !YES !

Page 28: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

A lot of things to take care

binaries installation

configs

cron jobs

monitoring

grants

databases

replication

Page 29: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

Documentation is needed and must be up to date

Page 30: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

Everything needs to be reproducible

quickly without missing anything !

Page 31: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

The “easy” part to automate is the part

close to the dark side of the force: sysadmins

Page 32: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

The “easy” part to automate is the part

close to the dark side of the force: sysadmins

Page 33: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

Installation, configuration, cron jobs, monitoring and even grants can be automated using a configuration management system

Consider your infrastructure as code

Page 34: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

Example

node percona1 {        include percona::repository        include percona::toolkit

        Class['percona::repository'] ­> Class['percona::server']

        class {                'percona::server':                        mysql_version   => "5.6",                        perconaserverid => "1",                        enable          => "true",                        ensure          => "running"        }}

Page 35: OSS4B: Installing & Managing MySQL like a real devops

CAMS 2nd principle: AUTOMATION

But how do you manage schemas ?

Is it automated ?

And in production ?

V 1 V 2

Page 36: OSS4B: Installing & Managing MySQL like a real devops

Database Schema Migration

There are some existing tools:– Liquibase (probably the best right now)

– Flyway

– c5-db-migration

– dbdeploy

– MyBatis

– Autopatch

– Sqitch

Page 37: OSS4B: Installing & Managing MySQL like a real devops

Database Schema Migration

Most of them are ...

Integrated with a framework or an ORM

Page 38: OSS4B: Installing & Managing MySQL like a real devops

Database Schema Migration

Most of them are ...

for JAVA applications

Page 39: OSS4B: Installing & Managing MySQL like a real devops

Database Schema Migration

Most of them use ...

XML definitions

Page 40: OSS4B: Installing & Managing MySQL like a real devops

What is easier ? This:

<?xml version="1.0" encoding="UTF­8"?> <databaseChangeLogxmlns="http://www.liquibase.org/xml/ns/dbchangelog"xmlns:xsi="http://www.w3.org/2001/XMLSchema­instance"xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangeloghttp://www.liquibase.org/xml/ns/dbchangelog/dbchangelog­2.0.xsd"> <changeSet id="1" author="lefred"><createTable tableName="department"><column name="id" type="int"><constraints primaryKey="true" nullable="false"/></column><column name="name" type="varchar(50)"><constraints nullable="false"/></column><column name="active" type="boolean" defaultValueBoolean="true"/></createTable></changeSet> </databaseChangeLog>

Page 41: OSS4B: Installing & Managing MySQL like a real devops

Or this ?

CREATE TABLE department (id INT NOT NULL PRIMARY KEY,name VARCHAR(50) NOT NULL

);

Page 42: OSS4B: Installing & Managing MySQL like a real devops

Database Schema Migration

also they are...

blocking

schema changes

Page 43: OSS4B: Installing & Managing MySQL like a real devops

Database Schema Migration

and finally...

not made to be used

via a configuration management system

Page 44: OSS4B: Installing & Managing MySQL like a real devops

Is there an alternative ?

Yes ;-)

online-migration

Page 45: OSS4B: Installing & Managing MySQL like a real devops

Online-migration: what is it ?

standalone Python script

command line only

Uses Oracle mysql-utilities

Uses pt-online-schema-change

Uses normal SQL statements

Can be easily integrated with puppet as a type and a provider are available

Page 46: OSS4B: Installing & Managing MySQL like a real devops

Online-migration: features

schema versioning and status

$ ./online­migration.py status worldMigration of schema world :+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+| VERSION | APPLIED             | STATUS           | COMMENT                |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+|    0000 | 2013­02­22 09:17:16 |               ok |           Initial file ||    0001 |                none |          pending |                   none ||    0002 |                none |          pending |                   none ||    0003 |                none |          pending | add nice column to cit |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+

Page 47: OSS4B: Installing & Managing MySQL like a real devops

Online-migration: features

schema migration up$ ./online­migration.py up world to 3INFO : You want to migrate up to version 0003INFO : Ok this version is pendingINFO : Preparing migration to version 0001INFO : Applied changes match the requested schemaINFO : Preparing migration to version 0002INFO : Applied changes match the requested schemaINFO : Preparing migration to version 0003INFO : Applied changes match the requested schema

$ ./online­migration.py status worldMigration of schema world :+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+| VERSION | APPLIED             | STATUS           |                COMMENT |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+|    0000 | 2013­02­22 09:17:16 |               ok |           Initial file ||    0001 | 2013­02­22 09:17:46 |               ok |                   none ||    0002 | 2013­02­22 09:18:24 |               ok |                   none ||    0003 | 2013­02­22 09:18:36 |               ok | add nice column to cit |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+

Page 48: OSS4B: Installing & Managing MySQL like a real devops

Online-migration: features

schema checksum

$ ./online­migration.py status worldMigration of schema world :+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+| VERSION | APPLIED             | STATUS           |                COMMENT |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+|    0000 | 2013­02­22 09:17:16 |               ok |           Initial file ||    0001 | 2013­02­22 09:17:46 | checksum problem |                   none |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+

$ ./online­migration.py checksum worldworld's current schema checksum = 3239e7245d98d27681020e36d0085676

Page 49: OSS4B: Installing & Managing MySQL like a real devops

Online-migration: features

schema migration down (rollback)$ ./online­migration.py down world 2INFO : You want to migrate down 2 version(s)INFO : rollback from 0003 to 0002INFO : rollback from 0002 to 0001

$ ./online­migration.py status worldMigration of schema world :+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+| VERSION | APPLIED             | STATUS           |                COMMENT |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+|    0000 | 2013­02­22 09:17:16 |               ok |           Initial file ||    0001 | 2013­02­22 09:17:46 |               ok |                   none ||    0002 | 2013­02­22 09:18:24 |         rollback |                   none ||    0003 | 2013­02­22 09:18:36 |         rollback | add nice column to cit ||    0002 |                none |          pending |                   none ||    0003 |                none |          pending | add nice column to cit |+­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­+

Page 50: OSS4B: Installing & Managing MySQL like a real devops

Online-migration: features

schema dif$ ./online­migration.py diff worldWARNING : Schema of world doesn't have expected checksum(4478d85870969436400bac023f2b2b7c)

TABLE `City`­ `CountryCode` varchar(10) DEFAULT NULL,+ `CountryCode` char(3) NOT NULL DEFAULT '',

Page 51: OSS4B: Installing & Managing MySQL like a real devops

Online-migration with puppet

Example

node percona1 { include percona::repository include percona::toolkit include online­migration

        Class['percona::repository'] ­> Class['percona::server']

        mysql_schema { "world":                     ensure  => present,         require => [ Package["online­migration"], 

   Service['mysql'] ],                     version => 1,                      cwd     => "/root/om",        }        ...}

Page 52: OSS4B: Installing & Managing MySQL like a real devops

CAM

CULTUREAUTOMATION

MEASUREMENTSHARING

Page 53: OSS4B: Installing & Managing MySQL like a real devops

CAMS 3rd & 4th principles: MEASUREMENT & SHARING

This can be summarized in two other words :

TEST&

VISIBILITY

Page 54: OSS4B: Installing & Managing MySQL like a real devops

TEST

Page 55: OSS4B: Installing & Managing MySQL like a real devops

TEST

What should you test as a

devops DBA ?

Page 56: OSS4B: Installing & Managing MySQL like a real devops

TEST as a devops DBA

Test if you can deploy everything and you didn't forget anything

Test every changes (even small configuration change)

Test also the performance ! Is it faster with this change ?

Automate your tests !

Page 57: OSS4B: Installing & Managing MySQL like a real devops

TEST as a devops DBA

To test performance you can use several tools from Percona like:– pt-query-digest

– pt-upgrade

– Percona-playback

Page 58: OSS4B: Installing & Managing MySQL like a real devops

Visibility

Share the following metrics with everybody in

your company

Page 59: OSS4B: Installing & Managing MySQL like a real devops

Visibility: tests results

Share the results of the tests:

jenkins dashboard

Page 60: OSS4B: Installing & Managing MySQL like a real devops

Visibility: monitoring

Monitor your database with an alerting system

(nagios)

Page 61: OSS4B: Installing & Managing MySQL like a real devops

Visibility: monitoring

But don't alert too much !

Page 62: OSS4B: Installing & Managing MySQL like a real devops

Visibility: monitoring

Your alerting system should answer those questions:

Is the database server running ?

Does it allow connections

Is replication lagging on production slaves ?

Page 63: OSS4B: Installing & Managing MySQL like a real devops

Visibility: trending

The most interesting facts for a DBA are the trending results !

Use cacti with Percona Monitoring Plugins, they provide very good metrics

http://www.percona.com/doc/percona­monitoring­plugins/cacti/mysql­templates.html

Page 64: OSS4B: Installing & Managing MySQL like a real devops

Visibility: trending

Correlate changes in the trending results with your

configuration changes...

everything should be tracked

Page 65: OSS4B: Installing & Managing MySQL like a real devops

Time for a demo ?

Installation of a development and a production environment (using vagrant)

You can view this part of demo at http://tinyurl.com/kafboua

Page 66: OSS4B: Installing & Managing MySQL like a real devops

demo

Let's create a schema for our application in development

And push it to production

Page 67: OSS4B: Installing & Managing MySQL like a real devops

demo

Now let's modify the schema

And deploy it to production

Page 68: OSS4B: Installing & Managing MySQL like a real devops

demo

Now let's modify the schema

And deploy it to production

V 0 empty database “world”

Page 69: OSS4B: Installing & Managing MySQL like a real devops

demo

v1 (release 1 of the schema)

SQL can be downloaded at http://tinyurl.com/n3upcyq

Demo available at http://tinyurl.com/k7lm2yf

Page 70: OSS4B: Installing & Managing MySQL like a real devops

demo

v2

SQL can be downloaded at http://tinyurl.com/ld7pwf7

alter table City    add PolutionLevel int;alter table City    add index pol_idx(PolutionLevel);

Page 71: OSS4B: Installing & Managing MySQL like a real devops

demo

v3

SQL can be downloaded at http://tinyurl.com/knqx4ql

alter table City    add nice tinyint default 1;

Page 72: OSS4B: Installing & Managing MySQL like a real devops

Warning !

A current bug in pt-online-schema-change prevents the program to work as expected when a table has constraints

https://bugs.launchpad.net/percona-toolkit/+bug/1207186

Page 73: OSS4B: Installing & Managing MySQL like a real devops

demo

Now let's upgrade this in production

Preparation

– copy all meta files into our puppet module

– specify the version in our manifest

Deployment

– run puppet

Demo at http://tinyurl.com/mq6sw33

Page 74: OSS4B: Installing & Managing MySQL like a real devops

demo

 mysql_schema { "world":                        ensure  => present,                        require => [ 

Package["online­migration"],  Service['mysql'] 

 ],                        version => 1,                        cwd     => "/root/om",        }

...info: Mysql_schema[world](provider=mysql_schema): performing the check, last_version is 0info: Mysql_schema[world](provider=mysql_schema): we need to migrate to another version (1)info: Mysql_schema[world](provider=mysql_schema): performing the migration...

Page 75: OSS4B: Installing & Managing MySQL like a real devops

Resources

Percona – http://www.percona.com

Percona playback - http://www.percona.com/doc/percona-playback/

online-migration - https://github.com/lefred/online-migration

pt-online-schema-change - http://www.percona.com/doc/percona-toolkit/pt-online-schema-change.html

mysql-utilities - http://dev.mysql.com/downloads/tools/utilities/1.3.html

Vagrant schema versioning environment - https://github.com/lefred/schemas-versioning

shelr.tv – http://shelr.tv/users/4f85fb1b9660807969000005

Page 76: OSS4B: Installing & Managing MySQL like a real devops

Percona provides

24 x 7 Support Services Quick and Easy Access to Consultants Same Day Emergency Data Recovery Remote DBA Services QUOTE OSS4B for Special Consulting Offer – Free Mini Health Audit with Gold Support and Free Performance Audit with Platinum Support Valid September-October 2013

[email protected] or 00442081330309

Page 77: OSS4B: Installing & Managing MySQL like a real devops

Thank you !

Questions?