SlideShare a Scribd company logo
MySQL HA Using
Orchestrator, Proxysql
and Consul
Yunus Shaikh
● MySQL DBA II at Percona
● 15 Years of experience in System
and Database administration
● Enjoys discovering new open
source technologies
● Likes to play Cricket in free time
Kedar Vaijanapurkar
● Living in Vadodara, Gujarat, India
● Major components: SPOF (wife) and two HA (highly active) replicas.
● Educated Masters in Computer Applications (2006)
● Eventual DBA and loving it (VB/VC/C# >> Perl/PHP >> MySQL)
● Enjoys music, photography, chess, cricket, blogging and knowledge
sharing
● Knows a bit about MySQL ecosystem, still learning.
● Proud Perconian
MySQL HA Orchestrator Proxysql Consul.pdf
● Introduction
● Whys of High Availability
● Building A High Availability Solution
● Questions
Agenda
Whys of
High Availability
Let's try to understand what is HA?
● Eliminate single point of failure
● Reduces interruptions and downtime
● Quick recovery during failures
● Scalable to handle high traffic
● Maintain high level of system uptime
Factors considered for High Availability
● Unplanned Downtime
○ Hardware failures
○ Software failures
● Planned Downtime
○ Hardware maintenance
○ Software maintenance
How many 9’s do you really need?
Building a HA
Solution
MySQL
● Async replication: Oldest, popular and
widely deployed, simple.
● Scale, Backup
● GTID v Non-GTID
● SPOF - Single Point of Failure
● Primary is a weak link.
● Downtime or degraded action for application.
MySQL (SPOF)
We need protection against SPOF to
● Let application continue writes
● Cleanup what’s bad in the environment
● Maintain architecture
● Editing app configuration to point to replica
● If we need to failover for any reason, we might need to
do it manually
○ More time in manual effort means more
downtime.
○ Writes need to be stopped during manual failover.
○ Human error prone.
Disadvantage
● How can we improve?
Orchestrator
● Thank you Shlomi
● Replication Topology Manager
● Discover, Visualize Topology
● Restructure Architecture
● Clustering support
● Free and Open Source
● https://github.com/openark/orchestrator
● Prerequisite
○ Orchestrator user
○ binlog & log_slave_updates
○ Master_info_repository - Table
● GTID / Non GTID Support
● Pseudo GTID
● MySQL or SQLite Backend options
● Percona Support
Orchestrator
CREATE USER 'orchestrator'@'orch_host' IDENTIFIED BY 'orch_topology_password';
GRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD ON *.* TO
'orchestrator'@'orch_host';
GRANT SELECT ON mysql.slave_master_info TO 'orchestrator'@'orch_host';
GRANT DROP ON _pseudo_gtid_.* TO 'orchestrator'@'orch_host';
● Orchestrator HA possible in 2 ways
○ Orchestrator RAFT
○ SHARED backend
● Nodes communicate with Raft consensus protocol
○ Why Raft?
● Only leader makes the changes (though everyone
runs discoveries)
● Little cross-node communication; fit for high
latency cross DC networks
Orchestrator (HA)
Orchestrator (Discovery)
- Image with orchestrator discovery | UI
- Image with orchestrator discovery | CLI
Orchestrator (Restructure)
- Image with instance promotion | UI
- Image with instance promotion | CLI
Orchestrator (Failure Detection)
● Naive Approach without orchestrator
○ Cannot contact master then failover
○ Can cause false positives
○ N checks in some intervals increases response
time.
● The holistic failure detection approach
○ Orchestrator cannot see master
○ Replicas cannot see the master.
● Recommended for faster detection
○ Slave_net_timeout
○ Master connect retry and master_retry count.
Orchestrator (Candidate Selection)
● Promote replica with 0 replication lag (least lag / first
to catch-up)
● Don’t promote servers without bin logs
● Replication filters
● Mysql versions
● Register_candidate
Orchestrator (Recovery)
● Pre-and-Post recovery hooks (once, sequentially)
● Healing of topology
● Events
○ OnFailureDetectionProcesses
○ PreGracefulTakeoverProcesses
○ PreFailoverProcesses
○ PostFailoverProcesses
○ PostUnsuccessfulFailoverProcesses
○ PostMasterFailoverProcesses
○ PostIntermediateMasterFailoverProcesses
○ PostGracefulTakeoverProcesses
Orchestrator (Recovery)
● Automatic recovery
● Manual recovery
{
"RecoveryPeriodBlockSeconds": 3600,
"RecoveryIgnoreHostnameFilters": [],
"RecoverMasterClusterFilters": [
"thiscluster",
"thatcluster"
],
"RecoverIntermediateMasterClusterFilters": [
"*"
],
}
Something is still lacking?
● We have failover tool now with orchestrator
● MySQL is HA, Orchestrator is HA
What is missing?
● We will still have to manually point application after
failover.
● No use of auto failover. As it needs manual intervention
to edit application config to point to new master
● No scaling/distributed read/writes
ProxySQL
● Proxy for database
● Connection pooling / multiplexing
● Load balancing
● Query Caching / Rewrite / Blocks
● Facilitates read write splits
● Easy configuration using SQL
interface with tables
● Clustering support
ProxySQL (Implementation)
On Application Node On Dedicated Node
● Tables and variables to configure
○ mysql_users: define DB users
○ mysql_servers: Backend MySQL Servers
○ mysql_replication_hostgroups: MySQL replication clusters
with servers in RW or RO mode
○ mysql_query_rules: Rules for query to backend databases.
ProxySQL (Configuration)
ProxySQL (SPOF)
● Available since version 1.4.x
● ProxySQL nodes watches each other for changes in
configuration checksums (runtime_checksums_values)
● Monitors + Reconfigure - 4 tables and global variables
○ mysql_query_rules
○ mysql_servers
○ mysql_users
○ proxysql_servers
ProxySQL (HA)
What do we have now?
Orchestrator: Hello! Can you talk?
ProxySQL: Not yet!
Orchestrator: Let me hook it up.
● No native communication
● ProxySQL: read_only monitor
● Orchestrator: Failover
● Orchestrator comes to rescue with “Hooks”
○ Scripts executed on events
○ Pre and Post failover execution on recovery
ProxySQL + Orchestrator
Orchestrator: I see fire, inside the mountains
ProxySQL: I see fire, burning the trees
Orchestrator Hooks: And I hope that you remember me.
● Don’t let the dead come alive - STONITH (via hooks)
● Can be used to generate alerts!
● Hooks are executed only once.
○ If ProxySQL is OoO, hook fails!
■ Who can be our messenger?
ProxySQL + Orchestrator (...)
Consul
● Built on Golang
● Service discovery tool
● Key value store
● Lightweight
● Native support in Orchestrator
● HA
● 3 Default ports
○ 8400 - RPC
○ 8500 - HTTP
○ 8600 - DNS
Consul (features)
● Service Discovery − Using either DNS or HTTP, applications
can easily find the services they depend upon.
● Health Check Status − It can provide any number of health
checks. It is used by the service discovery components to
route traffic away from unhealthy hosts.
● Key/Value Store − It can make use of Consul's hierarchical
key/value store for any number of purposes, including
dynamic configuration, feature flagging, coordination, leader
election, etc.
● Multi Datacenter Deployment − Consul supports multiple
datacenters. It is used for building additional layers of
abstraction to grow to multiple regions.
● Web UI − Consul provides its users a beautiful web interface
using which it can be easy to use and manage all of the
features in consul.
● Configure consul on (all) Orchestrator node(s) as Server
● Local install -> faster communication, 0 network latency
● Orchestrator config
“KVClusterMasterPrefix”: ”mysql/master”
“ConsulAddress”: “127.0.0.1:8500”
● Restart orchestrator
● orchestrator-client -c submit-masters-to-kv-stores
Consul (talking to Orchestrator)
● What Key Value
○ Orchestrator writes master info to Consul as per
defined KVClusterMasterPrefix Key.
■ IPV4, IPV6, Host, Port
Consul (What)
● Configure consul on (all) ProxySQL node(s) as
Agent joining Consul server on Orchestrator.
● Orchestrator -> Consul (S) -> Consul (A) ->
ProxySQL
● Apply changes using consul-template.
Consul (talking to ProxySQL)
● Consul Template is a simple and powerful tool that populates
values from consul into the file system.
● Consul templates can also execute some commands.
● Runs as a daemon and queries consul
Consul Template
# Snip from Template
REPLACE mysql_servers (hostgroup_id,hostname,port) values (2, "{{ key
$get_ip }}", "{{ key $get_port }}")
…
# Snip from config
command = "/bin/bash -c 'mysql -P 6032 -h 127.0.0.1 -u admin -padmin
< /opt/consul-template/templates/proxysql.sql'"
● Raft consensus protocol
● Leader elected, all requests processed by leader.
Consul (HA)
Orchestrator
+
ProxySQL
+
Consul
Consul
● Orchestrator writes to consul.
● Consul acts as source of truth to proxysql.
● Consul-template can be used as a script to make
changes in proxysql.
● Service discovery can be used along with DNS using
dnsmasq for discovering proxysql servers
○ Load balancing
○ Fault Tolerance
Service Discovery
root@localhost consul.d]# cat proxysql.json
{"services": [
{
"id": "proxy1",
"name": "proxysql",
"address": "192.168.103.30",
"tags": ["mysql"],
"port": 6033,
"check": {
"args": ["/usr/bin/mysqladmin", "ping", "--host=192.168.103.30", "--port=6033", "--user=test",
"--password=test@123"],
"interval": "3s"}
},
{
"id": "proxy2",
"name": "proxysql",
"address": "192.168.103.40",
"tags": ["mysql"],
"port": 6033,
"check": {
"args": ["/usr/bin/mysqladmin", "ping", "--host=192.168.103.40", "--port=6033", "--user=test",
"--password=test@123"],
"interval": "3s"}
}
]
}
Service Discovery Web GUI
Orchestrator hook and Consul-template
Hook
"PostGracefulTakeoverProcesses": [
"echo 'Planned takeover complete' >> /tmp/recovery.log",
"/root/orchestrator/post_failover2.sh {successorHost} {successorPort} {failedHost} {failedPort} >>
/tmp/recovery.log"
],
cat /root/orchestrator/post_failover2.sh
#!/bin/bash
IFS=' '
echo "-------------------------------"
echo $@
echo "-----------------------------------------"
consul kv put mysql/slave/percona_live/$3/ip $3
consul kv put mysql/slave/percona_live/$3/port $4
consul kv delete -recurse mysql/slave/percona_live/$1/
Logs for Orchestrator hook
Detected DeadMaster on 192.168.103.100:3307. Affected replicas: 1
Will recover from DeadMaster on 192.168.103.100:3307
Recovered from DeadMaster on 192.168.103.100:3307. Failed: 192.168.103.100:3307; Promoted:
192.168.103.10:3306
(for all types) Recovered from DeadMaster on 192.168.103.100:3307. Failed: 192.168.103.100:3307; Successor:
192.168.103.10:3306
Planned takeover about to take place on 192.168.103.10:3306. Master will switch to read_only
Detected DeadMaster on 192.168.103.10:3306. Affected replicas: 1
Will recover from DeadMaster on 192.168.103.10:3306
Recovered from DeadMaster on 192.168.103.10:3306. Failed: 192.168.103.10:3306; Promoted:
192.168.103.20:3306
(for all types) Recovered from DeadMaster on 192.168.103.10:3306. Failed: 192.168.103.10:3306; Successor:
192.168.103.20:3306
Planned takeover complete
-------------------------------
192.168.103.20 3306 192.168.103.10 3306
-----------------------------------------
Success! Data written to: mysql/slave/percona_live/192.168.103.10/ip
Success! Data written to: mysql/slave/percona_live/192.168.103.10/port
Success! Deleted keys with prefix: mysql/slave/percona_live/192.168.103.20/
How does consul-template work
template {
source = "/opt/consul-template/templates/proxysql.ctmpl"
destination = "/opt/consul-template/templates/proxysql.sql"
command = "/bin/bash -c 'mysql -P 6032 -h 127.0.0.1 -u admin -padmin <
/opt/consul-template/templates/proxysql.sql'"
command_timeout = "60s"
perms = 0644
backup = true
wait = "2s:6s"
}
[root@localhost consul-template]# tail -n 6 consul-template.log
2022/04/02 15:14:05.289735 [INFO] (runner) initiating run
2022/04/02 15:14:05.420448 [INFO] (runner) initiating run
2022/04/02 15:14:07.421302 [INFO] (runner) initiating run
2022/04/02 15:14:07.436471 [INFO] (runner) rendered "/opt/consul-template/templates/proxysql.ctmpl" =>
"/opt/consul-template/templates/proxysql.sql"
2022/04/02 15:14:07.436556 [INFO] (runner) executing command "/bin/bash -c 'mysql -P 6032 -h 127.0.0.1 -u admin -padmin <
/opt/consul-template/templates/proxysql.sql'" from "/opt/consul-template/templates/proxysql.ctmpl" =>
"/opt/consul-template/templates/proxysql.sql"
2022/04/02 15:14:07.436668 [INFO] (child) spawning: /bin/bash -c mysql -P 6032 -h 127.0.0.1 -u admin -padmin <
/opt/consul-template/templates/proxysql.sql
Proxysql before Failover
Proxysql after Failover
MySQL [(none)]> select hostgroup_id,hostname,port,status from runtime_mysql_servers;
+--------------+-----------------+------+--------+
| hostgroup_id | hostname | port | status |
+--------------+-----------------+------+--------+
| 1 | 192.168.103.20 | 3306 | ONLINE |
| 2 | 192.168.103.20 | 3306 | ONLINE |
| 2 | 192.168.103.10 | 3306 | ONLINE |
| 2 | 192.168.103.100 | 3307 | ONLINE |
+--------------+-----------------+------+--------+
MySQL [(none)]> select hostgroup_id,hostname,port,status from runtime_mysql_servers;
+--------------+-----------------+------+--------+
| hostgroup_id | hostname | port | status |
+--------------+-----------------+------+--------+
| 1 | 192.168.103.10 | 3306 | ONLINE |
| 2 | 192.168.103.20 | 3306 | ONLINE |
| 2 | 192.168.103.10 | 3306 | ONLINE |
| 2 | 192.168.103.100 | 3307 | ONLINE |
+--------------+-----------------+------+--------+
The Flow
Conclusions
● Consul Orchestrator ProxySQL saves the day.
● Every component is highly available.
● All components are Open Source and Free.
● Well supported by Percona and community.
● Works with Percona Xtradb Cluster (Galera),
MariaDB Galera Cluster and other MySQL
setups.
?
Thank you!

More Related Content

PDF
Cv farid kadi 2018
PPTX
2. global tourism trends and changes
PPTX
Le Tourisme Vert
PPTX
User Camp High Availability Presentation
PDF
Implementing MySQL Database-as-a-Service using open source tools
PPTX
My sql failover test using orchestrator
PDF
Deploying MariaDB for HA on Google Cloud Platform
PDF
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
Cv farid kadi 2018
2. global tourism trends and changes
Le Tourisme Vert
User Camp High Availability Presentation
Implementing MySQL Database-as-a-Service using open source tools
My sql failover test using orchestrator
Deploying MariaDB for HA on Google Cloud Platform
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...

Similar to MySQL HA Orchestrator Proxysql Consul.pdf (20)

PDF
Choosing a MySQL High Availability Solution.pdf
PDF
Managing and Visualizing your Replication Topologies with Orchestrator
PDF
OCP with super tengen toppa
PDF
High Availability in GCE
PDF
Pl2017 High Availability in GCE
PDF
ProxySQL Tutorial - PLAM 2016
PDF
MHA: Getting started & moving past quirks percona live santa clara 2013
PDF
MySQL Fabric: Easy Management of MySQL Servers
PDF
Proxysql ha plam_2016_2_keynote
PDF
Sharding and Scale-out using MySQL Fabric
PDF
MySQL High Availability - Managing Farms of Distributed Servers
PDF
HandsOn ProxySQL Tutorial - PLSC18
PPTX
MySQL High Availibility Solutions
PDF
MySQL topology healing at OLA.
PDF
EXPERIENCE WITH MYSQL HA SOLUTION AND GROUP REPLICATION
PDF
Automated MySQL failover with MHA: Getting started & moving past its quirks
PDF
Best practices for MySQL/MariaDB Server/Percona Server High Availability
PDF
Best practices for MySQL High Availability Tutorial
PDF
OSDC 2014: Colin Charles - Automated MySQL failover with MHA: getting started...
ODP
PoC: Using a Group Communication System to improve MySQL Replication HA
Choosing a MySQL High Availability Solution.pdf
Managing and Visualizing your Replication Topologies with Orchestrator
OCP with super tengen toppa
High Availability in GCE
Pl2017 High Availability in GCE
ProxySQL Tutorial - PLAM 2016
MHA: Getting started & moving past quirks percona live santa clara 2013
MySQL Fabric: Easy Management of MySQL Servers
Proxysql ha plam_2016_2_keynote
Sharding and Scale-out using MySQL Fabric
MySQL High Availability - Managing Farms of Distributed Servers
HandsOn ProxySQL Tutorial - PLSC18
MySQL High Availibility Solutions
MySQL topology healing at OLA.
EXPERIENCE WITH MYSQL HA SOLUTION AND GROUP REPLICATION
Automated MySQL failover with MHA: Getting started & moving past its quirks
Best practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL High Availability Tutorial
OSDC 2014: Colin Charles - Automated MySQL failover with MHA: getting started...
PoC: Using a Group Communication System to improve MySQL Replication HA
Ad

Recently uploaded (20)

PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PPT
Quality review (1)_presentation of this 21
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
Computer network topology notes for revision
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
Database Infoormation System (DBIS).pptx
PPTX
Supervised vs unsupervised machine learning algorithms
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PDF
Clinical guidelines as a resource for EBP(1).pdf
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PPTX
Introduction to Knowledge Engineering Part 1
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPT
ISS -ESG Data flows What is ESG and HowHow
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPT
Reliability_Chapter_ presentation 1221.5784
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Quality review (1)_presentation of this 21
climate analysis of Dhaka ,Banglades.pptx
Computer network topology notes for revision
Data_Analytics_and_PowerBI_Presentation.pptx
.pdf is not working space design for the following data for the following dat...
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
Database Infoormation System (DBIS).pptx
Supervised vs unsupervised machine learning algorithms
Miokarditis (Inflamasi pada Otot Jantung)
Clinical guidelines as a resource for EBP(1).pdf
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
Introduction to Knowledge Engineering Part 1
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
ISS -ESG Data flows What is ESG and HowHow
Business Ppt On Nestle.pptx huunnnhhgfvu
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
IBA_Chapter_11_Slides_Final_Accessible.pptx
Reliability_Chapter_ presentation 1221.5784
Ad

MySQL HA Orchestrator Proxysql Consul.pdf

  • 1. MySQL HA Using Orchestrator, Proxysql and Consul
  • 2. Yunus Shaikh ● MySQL DBA II at Percona ● 15 Years of experience in System and Database administration ● Enjoys discovering new open source technologies ● Likes to play Cricket in free time
  • 3. Kedar Vaijanapurkar ● Living in Vadodara, Gujarat, India ● Major components: SPOF (wife) and two HA (highly active) replicas. ● Educated Masters in Computer Applications (2006) ● Eventual DBA and loving it (VB/VC/C# >> Perl/PHP >> MySQL) ● Enjoys music, photography, chess, cricket, blogging and knowledge sharing ● Knows a bit about MySQL ecosystem, still learning. ● Proud Perconian
  • 5. ● Introduction ● Whys of High Availability ● Building A High Availability Solution ● Questions Agenda
  • 7. Let's try to understand what is HA? ● Eliminate single point of failure ● Reduces interruptions and downtime ● Quick recovery during failures ● Scalable to handle high traffic ● Maintain high level of system uptime
  • 8. Factors considered for High Availability ● Unplanned Downtime ○ Hardware failures ○ Software failures ● Planned Downtime ○ Hardware maintenance ○ Software maintenance
  • 9. How many 9’s do you really need?
  • 11. MySQL ● Async replication: Oldest, popular and widely deployed, simple. ● Scale, Backup ● GTID v Non-GTID
  • 12. ● SPOF - Single Point of Failure ● Primary is a weak link. ● Downtime or degraded action for application. MySQL (SPOF) We need protection against SPOF to ● Let application continue writes ● Cleanup what’s bad in the environment ● Maintain architecture
  • 13. ● Editing app configuration to point to replica ● If we need to failover for any reason, we might need to do it manually ○ More time in manual effort means more downtime. ○ Writes need to be stopped during manual failover. ○ Human error prone. Disadvantage ● How can we improve?
  • 14. Orchestrator ● Thank you Shlomi ● Replication Topology Manager ● Discover, Visualize Topology ● Restructure Architecture ● Clustering support ● Free and Open Source ● https://github.com/openark/orchestrator
  • 15. ● Prerequisite ○ Orchestrator user ○ binlog & log_slave_updates ○ Master_info_repository - Table ● GTID / Non GTID Support ● Pseudo GTID ● MySQL or SQLite Backend options ● Percona Support Orchestrator CREATE USER 'orchestrator'@'orch_host' IDENTIFIED BY 'orch_topology_password'; GRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD ON *.* TO 'orchestrator'@'orch_host'; GRANT SELECT ON mysql.slave_master_info TO 'orchestrator'@'orch_host'; GRANT DROP ON _pseudo_gtid_.* TO 'orchestrator'@'orch_host';
  • 16. ● Orchestrator HA possible in 2 ways ○ Orchestrator RAFT ○ SHARED backend ● Nodes communicate with Raft consensus protocol ○ Why Raft? ● Only leader makes the changes (though everyone runs discoveries) ● Little cross-node communication; fit for high latency cross DC networks Orchestrator (HA)
  • 17. Orchestrator (Discovery) - Image with orchestrator discovery | UI - Image with orchestrator discovery | CLI
  • 18. Orchestrator (Restructure) - Image with instance promotion | UI - Image with instance promotion | CLI
  • 19. Orchestrator (Failure Detection) ● Naive Approach without orchestrator ○ Cannot contact master then failover ○ Can cause false positives ○ N checks in some intervals increases response time. ● The holistic failure detection approach ○ Orchestrator cannot see master ○ Replicas cannot see the master. ● Recommended for faster detection ○ Slave_net_timeout ○ Master connect retry and master_retry count.
  • 20. Orchestrator (Candidate Selection) ● Promote replica with 0 replication lag (least lag / first to catch-up) ● Don’t promote servers without bin logs ● Replication filters ● Mysql versions ● Register_candidate
  • 21. Orchestrator (Recovery) ● Pre-and-Post recovery hooks (once, sequentially) ● Healing of topology ● Events ○ OnFailureDetectionProcesses ○ PreGracefulTakeoverProcesses ○ PreFailoverProcesses ○ PostFailoverProcesses ○ PostUnsuccessfulFailoverProcesses ○ PostMasterFailoverProcesses ○ PostIntermediateMasterFailoverProcesses ○ PostGracefulTakeoverProcesses
  • 22. Orchestrator (Recovery) ● Automatic recovery ● Manual recovery { "RecoveryPeriodBlockSeconds": 3600, "RecoveryIgnoreHostnameFilters": [], "RecoverMasterClusterFilters": [ "thiscluster", "thatcluster" ], "RecoverIntermediateMasterClusterFilters": [ "*" ], }
  • 23. Something is still lacking? ● We have failover tool now with orchestrator ● MySQL is HA, Orchestrator is HA What is missing? ● We will still have to manually point application after failover. ● No use of auto failover. As it needs manual intervention to edit application config to point to new master ● No scaling/distributed read/writes
  • 24. ProxySQL ● Proxy for database ● Connection pooling / multiplexing ● Load balancing ● Query Caching / Rewrite / Blocks ● Facilitates read write splits ● Easy configuration using SQL interface with tables ● Clustering support
  • 26. ● Tables and variables to configure ○ mysql_users: define DB users ○ mysql_servers: Backend MySQL Servers ○ mysql_replication_hostgroups: MySQL replication clusters with servers in RW or RO mode ○ mysql_query_rules: Rules for query to backend databases. ProxySQL (Configuration)
  • 28. ● Available since version 1.4.x ● ProxySQL nodes watches each other for changes in configuration checksums (runtime_checksums_values) ● Monitors + Reconfigure - 4 tables and global variables ○ mysql_query_rules ○ mysql_servers ○ mysql_users ○ proxysql_servers ProxySQL (HA)
  • 29. What do we have now? Orchestrator: Hello! Can you talk? ProxySQL: Not yet! Orchestrator: Let me hook it up.
  • 30. ● No native communication ● ProxySQL: read_only monitor ● Orchestrator: Failover ● Orchestrator comes to rescue with “Hooks” ○ Scripts executed on events ○ Pre and Post failover execution on recovery ProxySQL + Orchestrator Orchestrator: I see fire, inside the mountains ProxySQL: I see fire, burning the trees Orchestrator Hooks: And I hope that you remember me.
  • 31. ● Don’t let the dead come alive - STONITH (via hooks) ● Can be used to generate alerts! ● Hooks are executed only once. ○ If ProxySQL is OoO, hook fails! ■ Who can be our messenger? ProxySQL + Orchestrator (...)
  • 32. Consul ● Built on Golang ● Service discovery tool ● Key value store ● Lightweight ● Native support in Orchestrator ● HA ● 3 Default ports ○ 8400 - RPC ○ 8500 - HTTP ○ 8600 - DNS
  • 33. Consul (features) ● Service Discovery − Using either DNS or HTTP, applications can easily find the services they depend upon. ● Health Check Status − It can provide any number of health checks. It is used by the service discovery components to route traffic away from unhealthy hosts. ● Key/Value Store − It can make use of Consul's hierarchical key/value store for any number of purposes, including dynamic configuration, feature flagging, coordination, leader election, etc. ● Multi Datacenter Deployment − Consul supports multiple datacenters. It is used for building additional layers of abstraction to grow to multiple regions. ● Web UI − Consul provides its users a beautiful web interface using which it can be easy to use and manage all of the features in consul.
  • 34. ● Configure consul on (all) Orchestrator node(s) as Server ● Local install -> faster communication, 0 network latency ● Orchestrator config “KVClusterMasterPrefix”: ”mysql/master” “ConsulAddress”: “127.0.0.1:8500” ● Restart orchestrator ● orchestrator-client -c submit-masters-to-kv-stores Consul (talking to Orchestrator)
  • 35. ● What Key Value ○ Orchestrator writes master info to Consul as per defined KVClusterMasterPrefix Key. ■ IPV4, IPV6, Host, Port Consul (What)
  • 36. ● Configure consul on (all) ProxySQL node(s) as Agent joining Consul server on Orchestrator. ● Orchestrator -> Consul (S) -> Consul (A) -> ProxySQL ● Apply changes using consul-template. Consul (talking to ProxySQL)
  • 37. ● Consul Template is a simple and powerful tool that populates values from consul into the file system. ● Consul templates can also execute some commands. ● Runs as a daemon and queries consul Consul Template # Snip from Template REPLACE mysql_servers (hostgroup_id,hostname,port) values (2, "{{ key $get_ip }}", "{{ key $get_port }}") … # Snip from config command = "/bin/bash -c 'mysql -P 6032 -h 127.0.0.1 -u admin -padmin < /opt/consul-template/templates/proxysql.sql'"
  • 38. ● Raft consensus protocol ● Leader elected, all requests processed by leader. Consul (HA)
  • 40. Consul ● Orchestrator writes to consul. ● Consul acts as source of truth to proxysql. ● Consul-template can be used as a script to make changes in proxysql. ● Service discovery can be used along with DNS using dnsmasq for discovering proxysql servers ○ Load balancing ○ Fault Tolerance
  • 41. Service Discovery root@localhost consul.d]# cat proxysql.json {"services": [ { "id": "proxy1", "name": "proxysql", "address": "192.168.103.30", "tags": ["mysql"], "port": 6033, "check": { "args": ["/usr/bin/mysqladmin", "ping", "--host=192.168.103.30", "--port=6033", "--user=test", "--password=test@123"], "interval": "3s"} }, { "id": "proxy2", "name": "proxysql", "address": "192.168.103.40", "tags": ["mysql"], "port": 6033, "check": { "args": ["/usr/bin/mysqladmin", "ping", "--host=192.168.103.40", "--port=6033", "--user=test", "--password=test@123"], "interval": "3s"} } ] }
  • 43. Orchestrator hook and Consul-template Hook "PostGracefulTakeoverProcesses": [ "echo 'Planned takeover complete' >> /tmp/recovery.log", "/root/orchestrator/post_failover2.sh {successorHost} {successorPort} {failedHost} {failedPort} >> /tmp/recovery.log" ], cat /root/orchestrator/post_failover2.sh #!/bin/bash IFS=' ' echo "-------------------------------" echo $@ echo "-----------------------------------------" consul kv put mysql/slave/percona_live/$3/ip $3 consul kv put mysql/slave/percona_live/$3/port $4 consul kv delete -recurse mysql/slave/percona_live/$1/
  • 44. Logs for Orchestrator hook Detected DeadMaster on 192.168.103.100:3307. Affected replicas: 1 Will recover from DeadMaster on 192.168.103.100:3307 Recovered from DeadMaster on 192.168.103.100:3307. Failed: 192.168.103.100:3307; Promoted: 192.168.103.10:3306 (for all types) Recovered from DeadMaster on 192.168.103.100:3307. Failed: 192.168.103.100:3307; Successor: 192.168.103.10:3306 Planned takeover about to take place on 192.168.103.10:3306. Master will switch to read_only Detected DeadMaster on 192.168.103.10:3306. Affected replicas: 1 Will recover from DeadMaster on 192.168.103.10:3306 Recovered from DeadMaster on 192.168.103.10:3306. Failed: 192.168.103.10:3306; Promoted: 192.168.103.20:3306 (for all types) Recovered from DeadMaster on 192.168.103.10:3306. Failed: 192.168.103.10:3306; Successor: 192.168.103.20:3306 Planned takeover complete ------------------------------- 192.168.103.20 3306 192.168.103.10 3306 ----------------------------------------- Success! Data written to: mysql/slave/percona_live/192.168.103.10/ip Success! Data written to: mysql/slave/percona_live/192.168.103.10/port Success! Deleted keys with prefix: mysql/slave/percona_live/192.168.103.20/
  • 45. How does consul-template work template { source = "/opt/consul-template/templates/proxysql.ctmpl" destination = "/opt/consul-template/templates/proxysql.sql" command = "/bin/bash -c 'mysql -P 6032 -h 127.0.0.1 -u admin -padmin < /opt/consul-template/templates/proxysql.sql'" command_timeout = "60s" perms = 0644 backup = true wait = "2s:6s" } [root@localhost consul-template]# tail -n 6 consul-template.log 2022/04/02 15:14:05.289735 [INFO] (runner) initiating run 2022/04/02 15:14:05.420448 [INFO] (runner) initiating run 2022/04/02 15:14:07.421302 [INFO] (runner) initiating run 2022/04/02 15:14:07.436471 [INFO] (runner) rendered "/opt/consul-template/templates/proxysql.ctmpl" => "/opt/consul-template/templates/proxysql.sql" 2022/04/02 15:14:07.436556 [INFO] (runner) executing command "/bin/bash -c 'mysql -P 6032 -h 127.0.0.1 -u admin -padmin < /opt/consul-template/templates/proxysql.sql'" from "/opt/consul-template/templates/proxysql.ctmpl" => "/opt/consul-template/templates/proxysql.sql" 2022/04/02 15:14:07.436668 [INFO] (child) spawning: /bin/bash -c mysql -P 6032 -h 127.0.0.1 -u admin -padmin < /opt/consul-template/templates/proxysql.sql
  • 46. Proxysql before Failover Proxysql after Failover MySQL [(none)]> select hostgroup_id,hostname,port,status from runtime_mysql_servers; +--------------+-----------------+------+--------+ | hostgroup_id | hostname | port | status | +--------------+-----------------+------+--------+ | 1 | 192.168.103.20 | 3306 | ONLINE | | 2 | 192.168.103.20 | 3306 | ONLINE | | 2 | 192.168.103.10 | 3306 | ONLINE | | 2 | 192.168.103.100 | 3307 | ONLINE | +--------------+-----------------+------+--------+ MySQL [(none)]> select hostgroup_id,hostname,port,status from runtime_mysql_servers; +--------------+-----------------+------+--------+ | hostgroup_id | hostname | port | status | +--------------+-----------------+------+--------+ | 1 | 192.168.103.10 | 3306 | ONLINE | | 2 | 192.168.103.20 | 3306 | ONLINE | | 2 | 192.168.103.10 | 3306 | ONLINE | | 2 | 192.168.103.100 | 3307 | ONLINE | +--------------+-----------------+------+--------+
  • 48. Conclusions ● Consul Orchestrator ProxySQL saves the day. ● Every component is highly available. ● All components are Open Source and Free. ● Well supported by Percona and community. ● Works with Percona Xtradb Cluster (Galera), MariaDB Galera Cluster and other MySQL setups.
  • 49. ?