Best practices for MySQL High Availability in 2017
Colin Charles, Chief Evangelist, Percona Inc. colin.charles@percona.com / byte@bytebot.net http://www.bytebot.net/blog/ | @bytebot on Twitter Percona Live Santa Clara, California, USA 24 April 2017
Best practices for MySQL High Availability in 2017 Colin Charles, - - PowerPoint PPT Presentation
Best practices for MySQL High Availability in 2017 Colin Charles, Chief Evangelist, Percona Inc. colin.charles@percona.com / byte@bytebot.net http://www.bytebot.net/blog/ | @bytebot on Twitter Percona Live Santa Clara, California, USA 24 April
Colin Charles, Chief Evangelist, Percona Inc. colin.charles@percona.com / byte@bytebot.net http://www.bytebot.net/blog/ | @bytebot on Twitter Percona Live Santa Clara, California, USA 24 April 2017
Monty Program Ab, merged with SkySQL Ab, now MariaDB Corporation
Year Award winner 2014
2
3
4
5
6
7
8
9
10
Percentile target Max downtime per year 90% 36 days 99% 3.65 days 99.5% 1.83 days 99.9% 8.76 hours 99.99% 52.56 minutes 99.999% 5.25 minutes 99.9999% 31.5 seconds
11
12
Method Level of Availability Simple replication 98-99.9% Master-Master/MMM 99% SAN 99.5-99.9% DRBD, MHA, Tungsten Replicator 99.9% NDBCluster, Galera Cluster 99.999%
another DC
13
crash safety, integrity?
14
by restoring a new/backup server
15
16
17
18
higher average latencies
19
20
MariaDB
21
22
23
part of standard MySQL replication (yet?)
24
i/o thread
master
relay log
25
after written to relay log & flushed to disk
when slaves catch up
yoshinorimatsunobu.blogspot.com/2014/04/semi-synchronous- replication-at-facebook.html
26
27
(filtering)
slave
log
logs
database)
28
implementation
replication
TO w/o stopping replication thread
29
fsync(), InnoDB group commit)
30
fsync())
31
fsync(), InnoDB group commit)
commit
32
recovery is needed before it. In InnoDB you wait for flush + fsync its redo log for commit
33
prepared transactions to commit (since crash recovery can
34
35
transactions across binlogs, so big transactions do not lead to big binlog files
master rather than after commit)
36
transactional snapshot of the database without blocking any other queries.
Server 5.3+, Percona Server for MySQL 5.6+)
data to do a fully non-blocking backup
37
backups, etc.
name (used if connection name is not given)
CHANGE MASTER “connection_name”, SHOW SLAVE “connection_name” STATUS, etc.)
38
slaves
streams)
39
(only 5.7 supports this)
40
mysql.rpl_slave_state
recovered after crash along with user data.
41
updates required)
42
binlog stream.
master: mysqld --git-domain-id=#)
topology
43
44
DELETE with LIMIT and without ORDER BY)
(deadlocks)
qualified queries
not enough files to update slave
max_allowed_packet
45
46
47
$ mysqlbinlog mysql-bin.000001 # at 3134 #140721 13:59:57 server id 1 end_log_pos 3217 CRC32 0x974e3831 Querythread_id=9 exec_time=0 error_code=0 SET TIMESTAMP=1405943997/*!*/; BEGIN /*!*/; # at 3217 #140721 13:59:57 server id 1 end_log_pos 3249 CRC32 0x8de28161 Intvar SET INSERT_ID=2/*!*/; # at 3249 #140721 13:59:57 server id 1 end_log_pos 3370 CRC32 0x121ef29f Querythread_id=9 exec_time=0 error_code=0 SET TIMESTAMP=1405943997/*!*/; insert into auto (data) values ('a test 2') /*!*/; # at 3370 #140721 13:59:57 server id 1 end_log_pos 3401 CRC32 0x34354945 Xid = 414 COMMIT/*!*/; 48
MySQL 5.7+
49
> mysqlbinlog mysql-bin.* # at 3401 #140721 14:03:59 server id 1 end_log_pos 3477 CRC32 0xa37f424a Query thread_id=9 exec_time=0 error_code=0 SET TIMESTAMP=1405944239.559237/*!*/; BEGIN /*!*/; # at 3477 #140721 14:03:59 server id 1 end_log_pos 3529 CRC32 0xf4587de5 Table_map: `demo`.`auto` mapped to number 80 # at 3529 #140721 14:03:59 server id 1 end_log_pos 3585 CRC32 0xbfd73d98 Write_rows: table id 80 flags: STMT_END_F BINLOG ' rwHNUxMBAAAANAAAAMkNAAAAAFAAAAAAAAEABGRlbW8ABGF1dG8AAwMRDwMGZAAE5X1Y9A== rwHNUx4BAAAAOAAAAAEOAAAAAFAAAAAAAAEAAgAD//gDAAAAU80BrwiIhQhhIHRlc3QgM5g9178= '/*!*/; # at 3585 #140721 14:03:59 server id 1 end_log_pos 3616 CRC32 0x5f422fed Xid = 416 COMMIT/*!*/;
50
event in binary log', data_len: 56, event_type: 30
MariaDB 10 doesn’t - v.3.3 (fixed in 10.2 - MDEV-8713)
51
52
# at 471 #140721 14:20:01 server id 1 end_log_pos 519 CRC32 0x209d8843 GTID [commit=yes] SET @@SESSION.GTID_NEXT= 'ff89bf58-105e-11e4-b2f1-448a5b5dd481:2'/*!*/; # at 519 #140721 14:20:01 server id 1 end_log_pos 602 CRC32 0x5c798741 Query thread_id=3 exec_time=0 error_code=0 SET TIMESTAMP=1405945201.329607/*!*/; BEGIN /*!*/; # at 602 # at 634 #140721 14:20:01 server id 1 end_log_pos 634 CRC32 0xa5005598 Intvar SET INSERT_ID=5/*!*/; #140721 14:20:01 server id 1 end_log_pos 760 CRC32 0x0b701850 Query thread_id=3 exec_time=0 error_code=0 SET TIMESTAMP=1405945201.329607/*!*/; insert into auto (data) values ('a test 5 gtid') /*!*/; # at 760 #140721 14:20:01 server id 1 end_log_pos 791 CRC32 0x497a23e0 Xid = 31 COMMIT/*!*/;
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: server1 Master_User: repluser Master_Port: 3306 ... Master_Log_File: server1-binlog.000008 <- io_thread (read) Read_Master_Log_Pos: 436614719 <- io_thread (read) Relay_Log_File: server2-relaylog.000007 <- io_thread (write) Relay_Log_Pos: 236 <- io_thread (write) Relay_Master_Log_File: server1-binlog.000008 <- sql_thread Slave_IO_Running: Yes Slave_SQL_Running: Yes ... Exec_Master_Log_Pos: 436614719 <- sql_thread ... Seconds_Behind_Master: 0
53
changes
54
doing intra-schema parallel replication
55
56
migration
FREE)
57
58
59
60
redundancy
magic!
in-mysql-galera-vs-group-replication/
61
, memcached, native NDBAPI, node.js
62
for throughput.
issues!
63
brain)
64
ClusterControl
Manager
mysqlrpladmin
65
66
67
etc.)
68
continuous polling
69
Yoshinori Matsunobu at DeNA
70
Disk solutions (preferred)
71
Manager (PRM)
72
VM, etc can migrate / failover the entire VM guest
73
balancers
74
Image via Giuseppe Maxia
mysql-scalability-problems/
XtraDB Cluster 5.7, proxysql- admin tool available for PXC configurations
understand and solve performance issues, HA to DB topology
rerouting), load balancing
firewall)
hosts in the properties)
selection, and more
94
Baron Schwartz, VividCortex
“failover” moment, you don’t need a clustering framework (JDBC or PHP can load balance), and is relatively elegant overall
95
InnoDB
session management for high bandwidth sites, but setup, maintenance, etc. is complex
96
failover
97
98
99
100
101
Community Contributor of the Year (April 2011)
Yoshinori Matsunobu, Oracle ACE Director
102
MySQL
minimal downtime
103
gh-ost
master failure + VIP takeover to Pacemaker)
104
till failover complete
asynchronous (MHA works with async + semi-sync replication)
missing events, MHA does:
105
master or the most current slave to become new master
106
107
108
109
your application
a virtual IP (VIP) for your master
replication environments for you - that’s DIY
110
master, slaves, monitor
the path of your MySQL
111
up
where MHA Manager gets installed
automated failover is now disabled
112
manager
Config::Tiny, Log::Dispatch, Parallel::ForkManager, Time::HiRes
113
app1.cnf
masterha_default.cnf (see samples/conf/ masterha_default.cnf)
114
[server default] manager_workdir=/var/log/masterha/app1 manager_log=/var/log/masterha/app1/manager.log [server1] hostname=host1 [server2] hostname=host2 candidate_master=1 [server3] hostname=host3 [server4] hostname=host4 no_master=1
115
no need to specify master as MHA auto-detects this sets priority, but doesn’t necessarily mean it gets promoted as a default (say its too far behind replication). But maybe this is a more powerful box, or has a better setup will never be the master. RAID0 instead
Slave is in another data centre?
[server default] user=root password=rootpass ssh_user=root master_binlog_dir= /var/lib/mysql,/var/log/mysql remote_workdir=/data/log/masterha ping_interval=3 # secondary_check_script=masterha_secondary_check -s remote_host1 -s remote_host2 # master_ip_failover_script= /script/masterha/master_ip_failover # shutdown_script= /script/masterha/power_manager # report_script= /script/masterha/send_report # master_ip_online_change_script= /script/masterha/ master_ip_online_change
116
check master activity from manager->remote_hostN-> master (multiple hosts to ensure its not a network issue) STONITH
117
app1.cnf
will fail
privileges on binary/relay log not granted, using multi-master replication w/o read-only=1 set (only 1 writable master allowed)
118
(preferred in production)
Runnning_Background
119
120
VIP if required
VIP is easy to implement with minimal changes to master_ip_failover itself (however, use shutdown_script to power off machine)
121
maintenance
master_state=alive
the writing freeze
122
app1.cnf
123
master_state=alive --conf=/etc/MHA/ app1.cnf --new_master_host=host2
124
my $vip = ‘192.168.0.1/24”; my $interface = “0”; my $ssh_start_vip = “sudo /sbin/ifconfig eth0:$key $vip”; my $ssh_stop_vip = “sudo /sbin/ifconfig eth0:$key down”; ... sub start_vip() { `ssh $ssh_user\@$new_master_host \” $ssh_start_vip \”`; } sub stop_vip() { `ssh $ssh_user\@$orig_master_host \” $ssh_stop_vip \”`; }
125
VIP
interactive=0 --wait_on_failover_error=0 -- dead_master_host=host1 --new_master_host=host2`
126
more than 100MB, it is never a candidate master
check_repl_delay=0
Toolkit
127
128
data centre aware
HTTP API
129
130
VIPs and had to write to master_ip_online_change/master_ip_failover
v1/catalog/deregister);
\”$new_master_host\”}’ localhost:8500/v1/catalog/register);
131
132
bin.00024", 1600); CHANGE MASTER TO master_host="10.2.3.4", master_use_gtid=slave_pos; START SLAVE;
CHANGE MASTER TO master_use_gtid=current_pos; START SLAVE;
CHANGE MASTER TO master_host="10.2.3.5"; START SLAVE;
133
134
December 12 2012)
wiki/ReleaseNotes
135
not relay log failover
136
isn’t accepting writes)
137
138
139
restarting all write connections
happen within 8h, unless -- last_failover_minute=n is set
id=101, loss
innodb_flush_log_at_trx_commit=1 can be enabled! (just wait for master to recover)
time
140
MySQL day
failover, and how it compares to Tungsten
141
dramatically-increasing-uptime-mha
142
143
144
145
clouds)
146
147
tablespaces, authentication plugins, semi-sync replication
SELECT ... INTO OUTFILE
148
my.cnf naturally
parameter groups which allow configuration of MySQL
149
source: http://www.mysqlperformanceblog.com/2013/08/21/amazon-rds-with-mysql-5-6-configuration-variables/
150
codes?
151
152
192.168.0.1
User
id int(10) username char(15) password char(15) email char(50)
192.168.0.2
User
id int(10) username char(15) password char(15) email char(50)
192.168.0.3
User
id int(10) username char(15) password char(15) email char(50)
192.168.0.1
User
id int(10) username char(15) password char(15) email char(50)
192.168.0.2
UserInfo
login datetime md5 varchar(32) guid varchar(32)
Better if INSERT heavy and there’s less frequently changed data
Vitess
153
154
used
155
use MHA for master promotions)
156
management, zero downtime restarts
Kubernetes)
157
158
well enough
failover
159
Percona Monitoring & Management (PMM)
160
161
162
colin.charles@percona.com / byte@bytebot.net @bytebot on Twitter | http://bytebot.net/blog/ slides: slideshare.net/bytebot
163