Deploying MySQL in Production - Percona...2 © 2017 Percona Deploying MySQL in Production •...
Transcript of Deploying MySQL in Production - Percona...2 © 2017 Percona Deploying MySQL in Production •...
©2017Percona1
DanielKowalewski—SeniorTechnicalOperationsEngineer,[email protected]
DeployingMySQLinProduction
©2017Percona2
DeployingMySQLinProduction• Installation• Configuration(OSandMySQL)• Backups• Monitoring• Beforeyougolive...
©2017Percona3
Installation
©2017Percona4
MySQLInstallation• Thisisnotyourjob!• Don'treinventthewheel• Useapackagemanager• Oracle,Percona,MariaDBallhaverepos
• Staycurrent
©2017Percona5
Configmanagement• Ansible,Puppet,Chef,SaltStack,etc.• Usewhattherestofyourcompanyusesifpossible
• Infrastructureascode(revisioncontrol!)• Consistency
©2017Percona6
Useconfigmanagementfor:• Packageinstallation• Volumeanddirectorycreation• Permissions• Firewalls• InitialMySQLaccounts• deletedefaultaccounts
©2017Percona7
OSConfiguration
©2017Percona8
Storage• CanyouaffordSSDs?• RAID10👍,RAID5/6👎,RAID0👎👎(*)• LVMforflexibility• Filesystem–XFSorext4• XFS:inode64,nobarrier,noatime,logbufs=8• ext4:noatime,nodiratime,barrier=0
• IOScheduler–noopordeadline
©2017Percona9
CPU• SetCPUgovernorto"performance"
©2017Percona10
LifeGoal:Don'trunoutofmemory• Setvm.swappiness=1• Don'tdisableswap,it'syourreserveparachute• Usejemalloc• DisableTransparentHugePages
©2017Percona11
MySQLConfiguration
©2017Percona12
MySQLConfiguration• Don'tusethedefaultfiles• PerconaConfigWizardisn'tabadstart
©2017Percona13
Basicsettings• innodb_buffer_pool_size(stilldefaultsto128MiB!)• max_connections(stilldefaultsto151!)• innodb_log_file_size• query_cache_sizeandquery_cache_type• innodb_thread_concurrency• innodb_buffer_pool_instances
©2017Percona14
Alsoconsider• innodb_flush_log_at_transaction_commit• sync_binlog
©2017Percona15
Setnow,orregretlater• character_set(utf8orutf8mb4)• innodb_file_per_table• log-bin• expire_logs_days• innodb_numa_interleave
©2017Percona16
Backups
©2017Percona17
Thingsthatarenotbackups• RAID• SAN• mirroredSAN
• MySQLreplicas• evendelayedreplicas
• Untestedbackups• BackupsstoredontheDBhost
©2017Percona18
Type Size TimetoBackup
TimetoRestore
PartialRestores
Tools
Physical larger faster faster hard xtrabackup,MySQLEnterpriseBackup
Logical smaller slower slower easy mysqldump,mydumper,mysqlpump
©2017Percona19
Incremental/differentialbackups• Storechangessincethelastbackup• Onlypossiblewithphysicalbackups• Morecomplicatedrestores• Don'tgotoolongwithoutafullbackup!
©2017Percona20
Binarylogbackups• Essentialforpoint-in-timerecovery• Streamwithmysqlbinlog--read-from-remote-server• Playbackbypipingtomysql• Youdidturnonlog_bin,right?
©2017Percona21
Testyourbackups• Automaterestores• Watchforerrors(especiallywithlogicalbackups)• Replicatefromproduction• pt-table-checksum• Compareschemas
©2017Percona22
Monitoring
©2017Percona23
Alerting• Nagios,Icinga,Sensu,VividCortex,NewRelic,etc• Usewhatyoualreadyhave
• Alerton:• Thingsthatmattertotheapplication• Thingsthatarehardtorecoverfrom
• Don'tover-alert
©2017Percona24
Metricsthataffecttheapplication:• Servicestatus(connectioncheck)• asrealisticaspossible• Update/selectfromtable
• Averageexecutiontime• threads_running• Maybereplicationdelay
©2017Percona25
Disasterswaitingtohappen:• Diskspace• Historylistsize• Auto-incrementkeys• threads_connected(percentageofmax_connections)• Checksumdifferences• Swapusage
©2017Percona26
Maybenotsoimportant• Longtransactions(checkhistorylistinstead)• threads_connected• CPUusage• Deadlocks
©2017Percona27
Trending• Don'tover-alert,buttrendeverythingyoucan!• PMM,VividCortex,Sensu,etc.
©2017Percona28
Queryanalyzer• Removesguesswork• "ThisqueryisresponsibleforOOM"• "Thisisourworstquery"• "3%ofquerieswouldbenefitfromthisindex"• PMM,VividCortex,NewRelic
©2017Percona29
Beforeyougolive...LEEEEEEROOOOOYJENKINS!
©2017Percona30
Benchmarkeverything• sysbenchforthehardwareandOS• sysbenchOLTPortpcc-mysql• Loadtestfromapplication• Savetheresultstoreferencelater
©2017Percona31
Dataretention• Don'tcountonverticalscalingforever• Everyproblembecomesharderwithmoredata
©2017Percona33
Questions?
DATABASE PERFORMANCE MATTERSDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMatters