Setting up a MySQL replica

From Wikitech
(Difference between revisions)
Jump to: navigation, search
m (New Server Setup)
m (Reverted edits by Bhartshorne (talk) to last revision by Afeldman)
Line 1: Line 1:
 
== Pre-requisite ==  
 
== Pre-requisite ==  
  
* ('''deprecated''' - this is now in puppet.  Good to verify anyways though: <code>dpkg -l xtrabackup</code>). Install current xtrabackup, i.e. xtrabackup_1.4-193.lucid.25_amd64.deb on all servers involved
+
* Install current xtrabackup, i.e. xtrabackup_1.4-193.lucid.25_amd64.deb on all servers involved ('''To Do:''' add to wfm apt repo, install via puppet on all dbs)
  
 
== New Server Setup ==
 
== New Server Setup ==
  
# Ensure hardware raid is properly configured (raid-10, 256k strip, writeback cache, no read ahead)
+
* Ensure hardware raid is properly configured (raid-10, 256k strip, writeback cache, no read ahead)  
#* if cache policy says 'ReadAdaptive' instead of 'ReadAheadNone', run <code>MegaCli -LDSetProp NORA -Lall -Aall</code>
+
* Setup /a xfs volume according to Domas' xfsfix (i.e. ''mkfs.xfs -f -d sunit=512,swidth=4096 -L data /dev/sda3'' with uuid preservation)
#: '''ToDo''' add in MegaCli line to show the raid level clearly
+
** Can be run from root@fenari via: ('''To Do:''' put this somewhere standard, /home/w/bin?)
#: root@db1047:~# MegaCli -LDInfo -Lall -Aall | egrep -e "Current Cache Policy" -e "Stripe Size"
+
*** cat /home/midom/xfsfix | ssh NEWDB "python" - to see what will run.  if ok:
#: Stripe Size: 256kB
+
*** cat /home/midom/xfsfix | ssh NEWDB "python | bash"
#: Current Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
+
* Add to /etc/fstab as /a via device uuid and include nobarrier,noatime options, mount /a
# Setup /a xfs volume according to Domas' xfsfix (i.e. ''mkfs.xfs -f -d sunit=512,swidth=4096 -L data /dev/sda3'' with uuid preservation)
+
* Install current prod mysql version  
#* Can be run from root@fenari via: ('''To Do:''' put this somewhere standard, /home/w/bin?)
+
** Currently copying /usr/local/mysql-at-facebook from the source db and symlinking to /usr/local/mysql ('''To Do:''' make dpkg of our facebook patched mysql 5.1)
#** cat /home/midom/xfsfix | ssh NEWDB "python" - to see what will run.  if ok:
+
** useradd -d /home/mysql mysql
#** cat /home/midom/xfsfix | ssh NEWDB "python | bash"
+
* mkdir /a/sqldata /a/tmp ; chown -R mysql: /a
#* '''Note''' xfsfix needs to be updated.  The xfs settings do not correctly apply.  Domas has blessed the following output as "good enough":
+
* [ -s /etc/mysql/my.cnf ] && > /etc/mysql/my.cnf
#:: root@db1047:~# xfs_info /a | grep swidth
+
* Install /etc/my.cnf by copying from another host in the same mysql cluster
#::        =                      sunit=64    swidth=512 blks
+
** Set server-id to the first, third, and fourth octets of the server ip address (i.e. 10.0.6.42 = 10642)
#* '''Note''' xfsfix will erase the contents of /a.  This is fine because there's no data there yet, but be aware.
+
** Alter buffer pool size and other tunables if hardware sufficiently differs from the source server
# Update /etc/fstab to mount /a with nobarrier,noatime options instead of deafults.  Verify it is mounted via uuid.
+
#: root@db1047:~# cat /etc/fstab
+
#::  [excerpted]
+
#: # /a was on /dev/sda6 during installation
+
#: UUID=f1363f7d-8a44-4abe-9e38-bf2171e265c8 /a              xfs    nobarrier,noatime        0      2
+
# remount /a: <code>umount /a; mount /a</code>
+
# mkdir /a/sqldata /a/tmp ; chown -R mysql: /a
+
#* '''Note''' Puppet makes these directories if they don't exist, so don't be surprised if they magically appear or already exist.  You will have to create them after reformatting the partition above.
+
# Install current prod mysql version  
+
#* Currently copying /usr/local/mysql-at-facebook from the source db and symlinking to /usr/local/mysql ('''To Do:''' make dpkg of our facebook patched mysql 5.1)
+
# Empty out /etc/mysql/my.cnf; it is not used.  (/etc/my.cnf is used instead)
+
#* [ -s /etc/mysql/my.cnf ] && > /etc/mysql/my.cnf
+
  
 
== On New/Intended Slave ==
 
== On New/Intended Slave ==
Line 39: Line 27:
 
== On Existing DB ==  
 
== On Existing DB ==  
  
* innobackupex-1.5.1 --stream=tar /a/sqldata --user=root --slave-info | nc NEW-SERVER 9210  
+
* innobackupex-1.5.1 --stream=tar /a/sqldata --user=root --password=PASSWORD --slave-info | nc NEW-SERVER 9210  
* This results in a brief write lock towards the end of the process while the table definition files (but not data) are copied.  For enwiki, this is around 200Mb of data.  For this reason, this shouldn't be run on a write master if slaves are available.
+
* This results in a brief write lock towards the end of the process while the table definition files (but not data) are copied.  For enwiki, this is around 200Mb of data.  For this reason, this shouldn't be run on a write master if slaves are available.  
  
 
== On New Slave, after data copy ==  
 
== On New Slave, after data copy ==  
Line 47: Line 35:
 
* This is required to make the copied data consistent to a specific binlog position.   
 
* This is required to make the copied data consistent to a specific binlog position.   
 
* Start mysql, and CHANGE MASTER based on the information in /a/sqldata/xtrabackup_slave_info on the new host. '''Important:''' this should point to the correct binlog position on the actual write master on the cluster at which to start replication.  innobackupex will also display the log position on the slave the copy was made from, but we don't want to chain replication.
 
* Start mysql, and CHANGE MASTER based on the information in /a/sqldata/xtrabackup_slave_info on the new host. '''Important:''' this should point to the correct binlog position on the actual write master on the cluster at which to start replication.  innobackupex will also display the log position on the slave the copy was made from, but we don't want to chain replication.
 
== Make any use-specific tweaks ==
 
Some DBs have differences from the normally generated config.  These should come from puppet (and many do).  This section serves to document some of those tweaks and why they're made.
 
 
=== Research Slave ===
 
*'''Hosts''': db42, db1047, db1048
 
*'''Purpose''': slaves of the s1 cluster dedicated to intense queries by the Summer of Research team (aka community intern statisticians).
 
*'''Contact''':
 
*'''Tweaks''': (note that these are not yet done on db1047)
 
** no binlog
 
** disable binlogs on these two
 
** they also need innodb-locks-unsafe-for-binlog set.
 
*** hey get lots of ugly long running (4-24 hour) write queries in the style of 'insert mydb.foo select enwiki.revision …'.  Without locks-unsafe-for-binlog, such queries set a read lock on the enwiki tables for the duration of the queries which breaks replication
 
** set slave_transaction_retries to something insanely high. the researchers occasionally find other ways to set read locks despite locks-unsafe-for-binlog
 
  
 
[[Category:How-To]]
 
[[Category:How-To]]
 
[[Category:MySQL]]
 
[[Category:MySQL]]

Revision as of 21:51, 31 July 2011

Contents

Pre-requisite

  • Install current xtrabackup, i.e. xtrabackup_1.4-193.lucid.25_amd64.deb on all servers involved (To Do: add to wfm apt repo, install via puppet on all dbs)

New Server Setup

  • Ensure hardware raid is properly configured (raid-10, 256k strip, writeback cache, no read ahead)
  • Setup /a xfs volume according to Domas' xfsfix (i.e. mkfs.xfs -f -d sunit=512,swidth=4096 -L data /dev/sda3 with uuid preservation)
    • Can be run from root@fenari via: (To Do: put this somewhere standard, /home/w/bin?)
      • cat /home/midom/xfsfix | ssh NEWDB "python" - to see what will run. if ok:
      • cat /home/midom/xfsfix | ssh NEWDB "python | bash"
  • Add to /etc/fstab as /a via device uuid and include nobarrier,noatime options, mount /a
  • Install current prod mysql version
    • Currently copying /usr/local/mysql-at-facebook from the source db and symlinking to /usr/local/mysql (To Do: make dpkg of our facebook patched mysql 5.1)
    • useradd -d /home/mysql mysql
  • mkdir /a/sqldata /a/tmp ; chown -R mysql: /a
  • [ -s /etc/mysql/my.cnf ] && > /etc/mysql/my.cnf
  • Install /etc/my.cnf by copying from another host in the same mysql cluster
    • Set server-id to the first, third, and fourth octets of the server ip address (i.e. 10.0.6.42 = 10642)
    • Alter buffer pool size and other tunables if hardware sufficiently differs from the source server

On New/Intended Slave

  • cd /a/sqldata
  • nc -l 9210 | tar xvi

On Existing DB

  • innobackupex-1.5.1 --stream=tar /a/sqldata --user=root --password=PASSWORD --slave-info | nc NEW-SERVER 9210
  • This results in a brief write lock towards the end of the process while the table definition files (but not data) are copied. For enwiki, this is around 200Mb of data. For this reason, this shouldn't be run on a write master if slaves are available.

On New Slave, after data copy

Do this before starting mysql!

  • innobackupex-1.5.1 --apply-log --use-memory=22G --ibbackup=xtrabackup_51 /a/sqldata
  • This is required to make the copied data consistent to a specific binlog position.
  • Start mysql, and CHANGE MASTER based on the information in /a/sqldata/xtrabackup_slave_info on the new host. Important: this should point to the correct binlog position on the actual write master on the cluster at which to start replication. innobackupex will also display the log position on the slave the copy was made from, but we don't want to chain replication.
Personal tools
Namespaces

Variants
Actions
Navigation
Ops documentation
Wiki
Toolbox