mysql innodb cluster · linux high availability cluster with drbd and mysql. mysql ndb cluster....

51
MySQL InnoDB Cluster New Feature in MySQL >= 5.7.17 Sergej Kurakin

Upload: others

Post on 04-Jan-2020

49 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL InnoDB ClusterNew Feature in MySQL >= 5.7.17

Sergej Kurakin

Page 2: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Sergej KurakinAge: 36

Company: NFQ Technologies

Position: Software Engineer

Page 3: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Problem

Page 4: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

What if your database server fails?

Page 5: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Reboot? Accidental shutdown?

Page 6: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Kernel panic? Misconfiguration?

Page 7: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Network failure? Hardware failure?

Page 8: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

And this is the ONLY ONE database server that exists for your project.

Page 9: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Visitors, clients and business can’t wait until someone eventually gets to the Data Center and solves all issues.

Page 10: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Of course, there are solutions already created to automate failover and some of

them are quite old and effective!

Page 11: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Master-Slave Replication with manual or automatic failover.

Linux High Availability Cluster with DRBD and MySQL.

MySQL NDB Cluster.

Oracle MySQL Cloud Service.

MySQL with Solaris Cluster.

Galera Cluster for MySQL.

Amazon Relational Database Service.

Page 12: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

But we will talk about the new one!

Page 13: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL InnoDB Cluster

Page 14: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL InnoDB Cluster was introduced in version 5.7.17 on December 12, 2016.

Page 15: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Actually, MySQL Group Replication was introduced in 5.7.17 release and made

MySQL InnoDB Cluster possible.

Page 16: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL InnoDB Cluster is a collection of products that work together to provide a complete High Availability solution for

MySQL.

Page 17: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Products used to build InnoDB Cluster

MySQL Shell >= 1.0.9

MySQL Router >= 2.1.3

MySQL Server >= 5.7.17

Page 18: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Image from https://dev.mysql.com/doc/refman/5.7/en/mysql-innodb-cluster-introduction.html

Page 19: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Shell

Page 20: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

What is MySQL Shell?New advanced command-line client for the MySQL Server.

Uses the X DevAPI to communicate with a MySQL Server running the X Plugin.

Supports SQL, JavaScript and Python languages.

Sessions: XSession, Node Session, Classic Session.

Allows Interactive and Batch Code Execution.

Page 21: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Shell RolesConfigure MySQL instances for Cluster.

Verify MySQL instances are valid for InnoDB Cluster membership.

Create InnoDB Cluster.

Check InnoDB Cluster Status.

Manage InnoDB Cluster.

InnoDB Cluster recovery.

Page 22: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Router

Page 23: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

What is MySQL Router?Lightweight middleware that provides transparent routing between your application and back-end MySQL Servers.

Page 24: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Router RolesAware of the InnoDB Cluster topology.

Know which MySQL instance is the PRIMARY.

Acts as a proxy to hide the multiple MySQL instances.

Handles failover instead of Client.

Page 25: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Server

Page 26: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Server RolesProvides the MySQL Group Replication mechanism to allow data to be replicated within the cluster, with built-in failover.

Page 27: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Image from https://dev.mysql.com/doc/refman/5.7/en/mysql-innodb-cluster-introduction.html

Page 28: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

More about MySQL InnoDB Cluster

Page 29: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL InnoDB Cluster ModesSingle-primary mode.

Multiple-primaries mode - advanced mode.

Page 30: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Important Limitations and RequirementsAt least 3 and not more than 9 servers required for Cluster. Use odd number.

All tables must be of InnoDB type.

All tables must have PRIMARY keys.

Only IPv4 network supported.

Network performance is a must (low latency, high bandwidth).

Page 31: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Supershort How To

Page 32: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Cluster Creation StepsSet up at least 3 identical MySQL servers, but not more than 9.

Add cluster management user on each server.

Configure MySQL servers with MySQL Shell for Cluster for the first time.

Create MySQL Cluster using MySQL Shell.

Configure MySQL servers with MySQL Shell for Cluster for the second time.

Set up MySQL Routers on the same servers where MySQL Clients are located.

Configure your Clients to use MySQL Routers.

Page 33: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Cluster Creation (internals shortly)The InnoDB Cluster Metadata Schema is created.

The new InnoDB cluster information, including the specified name and password, is inserted into the InnoDB cluster Metadata.

The seed instance is added to the InnoDB cluster.

The seed instance information is inserted into the InnoDB cluster Metadata.

Page 34: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Connecting to MySQL InnoDB ClusterIf your Clients need to work with InnoDB Cluster, they must be connected to MySQL Router.

Default Read/Write port: 6446 - connects to the PRIMARY.

Default Read/Only port: 6447 - connects to one of the SLAVES.

Only Classic MySQL protocol supported.

Page 35: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

The gotchas!

Page 36: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

If PRIMARY Node Fails...If PRIMARY node fails MySQL Router drops all connections from Clients until new PRIMARY elected.

Prepare to handle many “MySQL server has gone away” errors for reads and writes.

Page 37: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Cluster falls apart if all Nodes were downIf all your servers eventually go down in same time your Cluster falls apart and needs to be reconfigured.

This is called “Complete Outage”.

Page 38: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Avoid Large TransactionsLarge transactions that cannot be copied between group members over the network within a 5 second window can cause failures in the group communication.

Page 39: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Router GotchasMySQL Router sometimes lags with Cluster updates, especially after recovery.

MySQL Router has weird limit: 500 connections per instance.

Page 40: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

MySQL Shell GotchasTo set up cluster node must be installed on the same host.

During setup must be able to modify MySQL configuration file.

No .deb packages for newer distributions.

Version 1.0.10 has a bug with cluster management user permissions during setup.

No code completion.

Lack of good documentation.

Hangs on lost connection.

Page 41: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Demo!

Page 42: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

What We Will Try in the DemoRestore Cluster from Complete Outage

Kill PRIMARY node during reads.

Restore killed node.

Kill PRIMARY node during writes.

Restore killed node.

Page 43: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

What about Production?

Page 44: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

I have no experience with MySQL InnoDB Cluster in production.

Page 45: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Some notes for ProductionRedundant network.

Redundant power.

Learn to troubleshoot before going live.

Learn how to recover from different failures before going live.

Test failover well before going live.

Big data set might be a problem for initial sync.

Page 46: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Would I run it in Production?

Yes!

But before...

Page 47: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Before going to ProductionBefore going to Production I would like to try this technology on something small scale and not so vital, as someone’s very important and highly loaded project.

Yes, I would need some practice and troubleshooting experience too.

Page 48: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Maybe someone in auditorium already has experience with MySQL InnoDB

Cluster and ready to say a word?

Page 49: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Back to the Problem

Page 50: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

Would it solve our problem?Yes, but with additional cost.

You need two more spare servers with MySQL installed.

You need to monitor and maintain MySQL InnoDB Cluster.

Page 51: MySQL InnoDB Cluster · Linux High Availability Cluster with DRBD and MySQL. MySQL NDB Cluster. Oracle MySQL Cloud Service. MySQL with Solaris Cluster. Galera Cluster for MySQL. Amazon

DiscussionSergej Kurakin

Work @mail: [email protected]

Personal @mail: [email protected]

https://www.linkedin.com/in/sergejkurakin