Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% •...

40
Running MySQL on CentOS Linux Peter Zaitsev April 14, 2014

Transcript of Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% •...

Page 1: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Running  MySQL  on  CentOS  Linux  

Peter  Zaitsev  April  14,  2014  

Page 2: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

About  the  Presenta9on  

• Distribu7on  • Hardware  • OS  Configura7on  • MySQL  Installa7on  • MySQL  Configura7on    

Cover  what  you  need  to  run  

MySQL  on  CentOS  Linux  

successfully  

2  

Page 3: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Why  Linux?  

• Almost  80%  for  Development  • hNp://bit.ly/QSdooC  

Almost  90%  of  MySQL  users  use  Linux  for  

produc7on  

• hNp://bit.ly/1rLIUnv    CentOS  the  Most  Popular  Linux  

Distribu7on  for  MySQL  

• Unless  you  have  a  very  good  reason  not  to,  choose  Linux  for  MySQL  Great  default  choice  

3  

Page 4: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Reasons  for  CentOS    

Server  Grade  Distribu7on  •  Long  support,  stability  

Completely  Open  Source  •  Free  

Modern    •  but  not  bleeding  Edge  

Great  Community  support  •  You  can  get  help  when  you  need  to  

4  

Page 5: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Hardware  

• Really!  Hardware  can  go  a  long  way!    

• With  100  queries/page  =  120K  page  views/minute  

• Some  80M  page  views/day  (considering  daily  spike)  

Over  200K  simple  queries/sec  on  modern  

hardware  

5  

Page 6: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Hardware  

• Go  for  fast  cores.  All  cores  are  rarely  used  these  days  

• Cache  and  fast  memory  bus  is  important  

CPU  

• Ocen  most  important  for  performance  • Your  working  set  must  fit  in  memory  well  

• Less  memory  =  more  pressure  on  IO  Memory  

6  

Page 7: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Storage  

Directly  aNached  Flash  is  best  -­‐  PCI-­‐E  cards  (FusionIO,  Virident)  are  fastest  

SATA  SSD  are  very  cost  effec7ve  

Mind  vendors  and  monitor  for  uniform  performance  

Where  performance  might  be  limi7ng  (hNp://bit.ly/1f2u919)  

Ensure  you  have  a  RAID  w  BBU  on  conven7onal  drives  

RAID10  is  best  for  heavy  loads  

7  

Page 8: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Know  your  Goals  

• Reads?    • Writes?    • Random?    • Sequen7al?  

Are  you  bound  by    

• Sustained  writes?          • Handle  spikes?  Do  you  need    

• Many  devices  reach  peak  IOPs  at  unreachable  concurrency  What  concurrency  do  you  operate?  

• SAN/NAS  is  a  frequent  cause  of  surprise  Think  about  latency/

response  7me  

8  

Page 9: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Performance  vs.  Memory  9  

Page 10: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Compression  of  Performance  Gains  10  

Page 11: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Alignment  

Par77on  alignment  

File  system  alignment  op7ons  

Can  cause  significant  performance  difference  • hNp://bit.ly.ilfNkT  • hNp://bit.ly.ks9trM  

11  

Page 12: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Alignment  Benchmarks  12  

Page 13: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

More  on  SSD/Flash  

Think  about  Write  Endurance  

Behavior  on  Power  Loss    

Data  Reten7on    

Firmware  

Linux  RAID  Compa7bility  

13  

Page 14: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Network  

Latency  is  king  

Minimize  number  of  hops  between  Database  and  Web  Server  

Ensure  running  1Gbit  link  speed  at  least  (10Gb  is  gaining  popularity)  

Monitor  for  packet  loss  and  latency  

Network  problems  are  ocen  blamed  on  database  

14  

Page 15: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Network  Tuning  

Might  be  needed  some7mes  • echo  8192  >  /proc/sys/net/ipv4/tcp_max_syn_backlog  • Mysql:    back_log=1000  • net.ipv4.ip_local_port_range="1024  64000“  • net.core.somaxconn  =  1024  • net.core.rmem_max  =  16777216  • net.core.wmem_max  =  16777216  • net.ipv4.tcp_rmem  =  4096  87380  16777216  • net.ipv4.tcp_wmem  =  4096  65536  16777216  • net.ipv4.max_tw_buckets=360000  • net.core.netdev_max_backlog  =  2500  • ifconfig  eth0  txqueuelen  1000  

Persistent  connec7ons  with  MySQL  • Thread_pool      (Percona  Server,  MariaDB,  MySQL  Enterprise)  •   Proxy  

15  

Page 16: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Virtualiza9on  and  Cloud  

Virtualiza7on  has  cost  

Cloud  rarely  provides  highest  performance  hardware  (Gerng  beNer)  

There  is  a  lot  of  MySQL  use  in  the  Cloud  and  Virtualized  Environments  

16  

Page 17: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

   

Linux  Configura9on  

17  

Page 18: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

In  General…  

For  most  workloads  Linux  Runs  MySQL  surprisingly  well  with  no  addi7onal  tuning  

18  

Page 19: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

General  Configura9on  

• Unless  you  really  need  it  on  your  system  •  In  /etc/selinux/config  •  SELINUX=disabled  

•  Same  with  AppArmor  

Disable  SELinux  

•  vm.swappiness=0  •  vm.dirty_ra7o=5    

Reduce  Tendency  to  swap  

19  

Page 20: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

General  Configura9on  

Reduce  the  File  Cache    • vm.dirty_ra7o=5  

NUMA  can  cause  problems  • hNp://bit.ly/I0GSt3  • Interleaving  with  numactl  • Out  there  in    Percona  Server  startup  scripts  

20  

Page 21: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Storage  Configura9on  

• Re-­‐Configure  MySQL  without  OS  Reinstall  Separate  OS  and  MySQL  Par77on  

• CFQ  can  cause  problems  • Deadline  or  Noop  are  ocen  beNer  choice  • elevator=deadline  on  kernel  boot  

Configure  IO  Scheduler  

• #  echo  100000  >  /sys/block/sdX/queue/nr_requests  Queue  length  (especially  MyISAM)  

• Virtually  no  overhead  when  not  in  snapshot  mode  • Reserve  some  space  for  snapshots  Consider  using  LVM  

21  

Page 22: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

         Which  one  do  you  use  ?    FILESYSTEMS  

22  

Page 23: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Filesystems  

XFS  –  “Old”  High  Performance  Favorite  

EXT4  –  Works  very  good  for  some  workloads  

Avoid:  • Ext2  • Ext3  • ReiserFS  •  ZFS  (may  be  good  for  development)    • Btrfs  

23  

Page 24: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

FS  Tuning  

rela7me  (noa7me)  

ext3:  tune2fs  –O  dir_index  -­‐c  –l  –i  0  –e  remount-­‐ro  

xfs:  nobarrier    • Assuming  RAID  w  BBU  or  Flash  

24  

Page 25: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

         Why  are  you  running?  MYSQL  VARIANTS  

25  

Page 26: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Main  Choices  

MySQL    

Percona  Server  

MariaDB  

26  

Page 27: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

MySQL  Versions  

Newer  versions  scale  beNer  

MySQL  5.6  is  most  scalable  

Percona  Server  5.6  brings  even  more  improvements  J  

Use  5.6  for  New  Development  

Upgrade  to  MySQL  5.6  if  you  need  it  now  

27  

Page 28: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Check  out  Percona  XtraDB  Cluster  

Based  on  Galera  Technology  

Innodb  Storage  Engine  you  already  know  

Synchronous  Replica7on  

Parallel  Apply  

Automa7c  Provisioning  

No  Stale  Reads  

Not  for  all  workloads  

28  

Page 29: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

How  to  Install  

•  hNp://dev.mysql.com/downloads/repo/  •  hNp://www.percona.com/doc/percona-­‐server/5.6/installa7on.html  

Use  Repositories:  Best  

•  Need  older  Version    Download  RPM  

•  Good  for  tes7ng  with  MySQL  Sandbox  Use  Tar.gz  package  

•  Do  you  really  have  good  reason  to  do  it  ?  • Many  problems  are  caused  by  bad  builds  Build  our  own  

29  

Page 30: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

MySQL  Configura9on  

• Even  newer  MySQL  5.6  defaults  are  unlikely  to  be  op7mal  

You  need  to  tune  MySQL  configura7on  

• hNp://bit.ly/1fuP0SZ  Check  out  presenta7on  which  goes  in  depth  into  configura7on  tuning  

• Avoid  obsessive  tuning  disorder  Typically  gerng  5  variables  right  

responsible  for  90%  performance  gain  

30  

Page 31: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Top  Variables  

•  Set  80%  of  memory  some7mes  more  Innodb_buffer_pool_size  

•  Best  serng  in  most  cases  Innodb_flush_method=O_DIRECT  

•  Set  256MB  or  more    •  Larger  logs  =  longer  recovery  7me  

Innodb_log_file_size  

•  Truly  ACID:  1    •  Can  Afford  Data  Loss:  2  

Innodb_flush_log_at_trx_commit=?  

31  

Page 32: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Advanced  Ideas  

•  taskset  -­‐pc  0,12,2,14  `cat  /var/lib/mysql/mysqld1.pid`    

Running  mul7ple  MySQL  instances  ?  

•  Jemalloc    • Tcmalloc  –old  favorite  

Memory  Alloca7on  Hostspot  ?  

• Roll  back  easily  if  things  go  wrong  

LVM  Snapshot  before  maintenance  

or  upgrade  

32  

Page 33: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Beware  of  the  “Scripts”  

• Timeouts  might  be  not  enough  for  safe  database  shutdown  

• The  automated  upgrade/check    

Start/Stop  Scripts  can  be  nasty  

33  

Page 34: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Automa9on  

Manual  approach  is  a  no  

• Does  not  Scale  • And  is  Error  Prone  

Automate  installa7on,  upgrades,  

configura7on  

• Puppet,    • Chef    • Ansible    

Keep  Configura7on  under  version  control  

• At  very  least  leave  comments  on  what  you  chance  and  why  

34  

Page 35: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Monitoring  and  Trending  

•  Just  make  sure  you’re  doing  it  Many  tools  to  choose  from!  

•  Check  out  PMP  •  hNp://www.percona.com/socware/percona-­‐monitoring-­‐plugins  

Nagios  and  CACTI  

•  hNp://graphite.wikidot.com/  Graphite  is  a  great  tool  for  advanced  analyses  

•  Percona  Cloud  Tools    (FREE  Beta)  •  hNps://cloud.percona.com/  

Looking  for  Cloud  Based  Solu7ons  

35  

Page 36: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Linux  OOM  Killer  

• SSH  • MySQL  Server  • Various  jobs  • Backup    • Percona  Toolkit    • Background  Batch  jobs  

What  are  your  

priori7es  ?  

• echo  -­‐17  >  /proc/2592/oom_adj  • do  not  kill  ever  

• echo  10  >  /proc/2592/oom_adj      • More  like    to  be  killed  

Configuring  

36  

Page 37: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Tools  you  need  to  know  

General  Linux  

• Top  • Vmstat  • Iostat  • Strace  • gdb  

MySQL  

• Percona  Toolkit  • Innotop  • Percona  Xtrabackup  

• MyDumper  

37  

Page 38: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Learn  more  

• hNp://www.percona.com/training  Percona  Training  

• hNp://www.percona.com/webinars  Percona  Webinars  

• hNp://www.mysqlperformanceblog.com  

MySQL  Performance  Blog  

38  

Page 39: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

Aaend  The  Conference  

4  More  Days  of  great  Learning  and  Networking  

Expo  Hall,  Keynote  Free  for  CentOS  Dojo  ANendees  

Single  Day  Passes  Available  

Use  “GoLinux”  Discount  Code  for  15%  off    

39  

Page 40: Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% • Long%support,%stability% Completely%Open%Source% • Free% Modern%% • butnotbleeding%Edge%

40  

Thank You! Peter  Zaitsev  

[email protected]