Table des matières
Summary
Setup
Failover
Tool registration
Running in the background
Errant transactions
Limitations
Conclusion
Maison base de données tutoriel mysql Failover with the MySQL Utilities: Part 2 – mysqlfailover_MySQL

Failover with the MySQL Utilities: Part 2 – mysqlfailover_MySQL

May 31, 2016 am 08:48 AM

In theprevious postof this series we saw how you could usemysqlrpladminto perform manual failover/switchover when GTID replication is enabled in MySQL 5.6. Now we will reviewmysqlfailover(version 1.4.3), another tool from the MySQL Utilities that can be used for automatic failover.

Summary

  • mysqlfailovercan perform automatic failover if MySQL 5.6′s GTID-replication is enabled.
  • All slaves must use--master-info-repository=TABLE.
  • The monitoring node is a single point of failure: don’t forget to monitor it!
  • Detection of errant transactions works well, but you have to use the--pedanticoption to make sure failover will never happen if there is an errant transaction.
  • There are a few limitations such as the inability to only fail over once, or excessive CPU utilization, but they are probably not showstoppers for most setups.

Setup

We will use the same setup as last time: one master and two slaves, all using GTID replication. We can see the topology usingmysqlfailoverwith thehealthcommand:

$ mysqlfailover --master=root@localhost:13001 --discover-slaves-login=root health[...]MySQL Replication Failover UtilityFailover Mode = auto Next Interval = Tue Jul1 10:01:22 2014Master Information------------------Binary Log File PositionBinlog_Do_DBBinlog_Ignore_DBmysql-bin.000003700GTID Executed Seta9a396c6-00f3-11e4-8e66-9cebe8067a3f:1-3Replication Health Status+------------+--------+---------+--------+------------+---------+| host | port | role| state| gtid_mode| health|+------------+--------+---------+--------+------------+---------+| localhost| 13001| MASTER| UP | ON | OK|| localhost| 13002| SLAVE | UP | ON | OK|| localhost| 13003| SLAVE | UP | ON | OK|+------------+--------+---------+--------+------------+---------+
Copier après la connexion

$mysqlfailover--master=root@localhost:13001--discover-slaves-login=roothealth

[...]

MySQLReplicationFailoverUtility

FailoverMode=auto    NextInterval=TueJul  110:01:222014

MasterInformation

------------------

BinaryLogFile  Position  Binlog_Do_DB  Binlog_Ignore_DB  

mysql-bin.000003  700                                      

GTIDExecutedSet

a9a396c6-00f3-11e4-8e66-9cebe8067a3f:1-3

ReplicationHealthStatus

+------------+--------+---------+--------+------------+---------+

|host      |port  |role    |state  |gtid_mode  |health  |

+------------+--------+---------+--------+------------+---------+

|localhost  |13001  |MASTER  |UP    |ON        |OK      |

|localhost  |13002  |SLAVE  |UP    |ON        |OK      |

|localhost  |13003  |SLAVE  |UP    |ON        |OK      |

+------------+--------+---------+--------+------------+---------+

Note that--master-info-repository=TABLEneeds to be configured on all slaves or the tool will exit with an error message:

2014-07-01 10:18:55 AM CRITICAL Failover requires --master-info-repository=TABLE for all slaves.ERROR: Failover requires --master-info-repository=TABLE for all slaves.
Copier après la connexion

2014-07-0110:18:55AMCRITICALFailoverrequires--master-info-repository=TABLEforallslaves.

ERROR:Failoverrequires--master-info-repository=TABLEforallslaves.

Failover

You can use 2 commands to trigger automatic failover:

  • auto: the tool tries to find a candidate in the list of servers specified with--candidates, and if no good server is found in this list, it will look at the other slaves to see if one can be a good candidate. This is the default command
  • elect: same asauto, but if no good candidate is found in the list of candidates, other slaves will not be checked and the tool will exit with an error.

Let’s start the tool withauto:

$ mysqlfailover --master=root@localhost:13001 --discover-slaves-login=root auto
Copier après la connexion

$mysqlfailover--master=root@localhost:13001--discover-slaves-login=rootauto

The monitoring console is visible and is refreshed every--intervalseconds (default: 15). Its output is similar to what you get when using thehealthcommand.

Then let’s kill -9 the master to see what happens once the master is detected as down:

Failed to reconnect to the master after 3 attemps.Failover starting in 'auto' mode...# Candidate slave localhost:13002 will become the new master.# Checking slaves status (before failover).# Preparing candidate for failover.# Creating replication user if it does not exist.# Stopping slaves.# Performing STOP on all slaves.# Switching slaves to new master.# Disconnecting new master as slave.# Starting slaves.# Performing START on all slaves.# Checking slaves for errors.# Failover complete.# Discovering slaves for master at localhost:13002Failover console will restart in 5 seconds.MySQL Replication Failover UtilityFailover Mode = auto Next Interval = Tue Jul1 10:59:47 2014Master Information------------------Binary Log File PositionBinlog_Do_DBBinlog_Ignore_DBmysql-bin.000005191GTID Executed Seta9a396c6-00f3-11e4-8e66-9cebe8067a3f:1-3Replication Health Status+------------+--------+---------+--------+------------+---------+| host | port | role| state| gtid_mode| health|+------------+--------+---------+--------+------------+---------+| localhost| 13002| MASTER| UP | ON | OK|| localhost| 13003| SLAVE | UP | ON | OK|+------------+--------+---------+--------+------------+---------+
Copier après la connexion

Failedtoreconnecttothemasterafter3attemps.

Failoverstartingin'auto'mode...

# Candidate slave localhost:13002 will become the new master.

# Checking slaves status (before failover).

# Preparing candidate for failover.

# Creating replication user if it does not exist.

# Stopping slaves.

# Performing STOP on all slaves.

# Switching slaves to new master.

# Disconnecting new master as slave.

# Starting slaves.

# Performing START on all slaves.

# Checking slaves for errors.

# Failover complete.

# Discovering slaves for master at localhost:13002

Failoverconsolewillrestartin5seconds.

MySQLReplicationFailoverUtility

FailoverMode=auto    NextInterval=TueJul  110:59:472014

MasterInformation

------------------

BinaryLogFile  Position  Binlog_Do_DB  Binlog_Ignore_DB  

mysql-bin.000005  191                                      

GTIDExecutedSet

a9a396c6-00f3-11e4-8e66-9cebe8067a3f:1-3

ReplicationHealthStatus

+------------+--------+---------+--------+------------+---------+

|host      |port  |role    |state  |gtid_mode  |health  |

+------------+--------+---------+--------+------------+---------+

|localhost  |13002  |MASTER  |UP    |ON        |OK      |

|localhost  |13003  |SLAVE  |UP    |ON        |OK      |

+------------+--------+---------+--------+------------+---------+

Looks good! The tool is then ready to fail over to another slave if the new master becomes unavailable.

You can also run custom scripts at several points of execution with the--exec-before,--exec-after,--exec-fail-check,--exec-post-failoveroptions.

However it would be great to have a--failover-and-exitoption to avoid flapping: the tool would detect master failure, promote one of the slaves, reconfigure replication and then exit (this is what MHA does for instance).

Tool registration

When the tool is started, it registers itself on the master by writing a few things in the specific table:

mysql> SELECT * FROM mysql.failover_console;+-----------+-------+| host| port|+-----------+-------+| localhost | 13001 |+-----------+-------+
Copier après la connexion

mysql>SELECT*FROMmysql.failover_console;

+-----------+-------+

|host      |port  |

+-----------+-------+

|localhost|13001|

+-----------+-------+

This is nice as it avoids that you start several instances ofmysqlfailoverto monitor the same master. If we try, this is what we get:

$ mysqlfailover --master=root@localhost:13001 --discover-slaves-login=root auto[...]Multiple instances of failover console found for master localhost:13001.If this is an error, restart the console with --force.Failover mode changed to 'FAIL' for this instance.Console will start in 10 seconds..........starting Console.
Copier après la connexion

$mysqlfailover--master=root@localhost:13001--discover-slaves-login=rootauto

[...]

Multipleinstancesoffailoverconsolefoundformasterlocalhost:13001.

Ifthisisanerror,restarttheconsolewith--force.

Failovermodechangedto'FAIL'forthisinstance.

Consolewillstartin10seconds..........startingConsole.

With thefailcommand,mysqlfailoverwill monitor replication health and exit in the case of a master failure, without actually performing failover.

Running in the background

In all previous examples,mysqlfailoverwas running in the foreground. This is very good for demo, but in a production environment you are likely to prefer running it in the background. This can be done with the--daemonoption:

$ mysqlfailover --master=root@localhost:13001 --discover-slaves-login=root auto --daemon=start --log=/var/log/mysqlfailover.log
Copier après la connexion

$mysqlfailover--master=root@localhost:13001--discover-slaves-login=rootauto--daemon=start--log=/var/log/mysqlfailover.log

and it can be stopped with:

$ mysqlfailover --daemon=stop
Copier après la connexion

$mysqlfailover--daemon=stop

Errant transactions

If we create an errant transaction on one of the slaves, it will be detected:

MySQL Replication Failover UtilityFailover Mode = auto Next Interval = Tue Jul1 16:29:44 2014[...]WARNING: Errant transaction(s) found on slave(s).Replication Health Status[...]
Copier après la connexion

MySQLReplicationFailoverUtility

FailoverMode=auto    NextInterval=TueJul  116:29:442014

[...]

WARNING:Erranttransaction(s)foundonslave(s).

ReplicationHealthStatus

[...]

However this does not prevent failover from occurring! You have to use--pedantic:

$ mysqlfailover --master=root@localhost:13001 --discover-slaves-login=root --pedantic auto[...]# WARNING: Errant transaction(s) found on slave(s).#- For slave 'localhost@13003': db906eee-012d-11e4-8fe1-9cebe8067a3f:12014-07-01 16:44:49 PM CRITICAL Errant transaction(s) found on slave(s). Note: If you want to ignore this issue, please do not use the --pedantic option.ERROR: Errant transaction(s) found on slave(s). Note: If you want to ignore this issue, please do not use the --pedantic option.
Copier après la connexion

$mysqlfailover--master=root@localhost:13001--discover-slaves-login=root--pedanticauto

[...]

# WARNING: Errant transaction(s) found on slave(s).

#  - For slave 'localhost@13003': db906eee-012d-11e4-8fe1-9cebe8067a3f:1

2014-07-0116:44:49PMCRITICALErranttransaction(s)foundonslave(s).Note:Ifyouwanttoignorethisissue,pleasedonotusethe--pedanticoption.

ERROR:Erranttransaction(s)foundonslave(s).Note:Ifyouwanttoignorethisissue,pleasedonotusethe--pedanticoption.

Limitations

  • Like formysqlrpladmin, the slave election process is not very sophisticated and it cannot be tuned.
  • The server on whichmysqlfailoveris running is a single point of failure.
  • Excessive CPU utilization: once it is running,mysqlfailoverhogs one core. This is quite surprising.

Conclusion

mysqlfailoveris a good tool to automate failover in clusters using GTID replication. It is flexible and looks reliable. Its main drawback is that there is no easy way to make it highly available itself: ifmysqlfailovercrashes, you will have to manually restart it.

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

Video Face Swap

Video Face Swap

Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Quand une analyse de table complète pourrait-elle être plus rapide que d'utiliser un index dans MySQL? Quand une analyse de table complète pourrait-elle être plus rapide que d'utiliser un index dans MySQL? Apr 09, 2025 am 12:05 AM

La numérisation complète de la table peut être plus rapide dans MySQL que l'utilisation d'index. Les cas spécifiques comprennent: 1) le volume de données est petit; 2) Lorsque la requête renvoie une grande quantité de données; 3) Lorsque la colonne d'index n'est pas très sélective; 4) Lorsque la requête complexe. En analysant les plans de requête, en optimisant les index, en évitant le sur-index et en maintenant régulièrement des tables, vous pouvez faire les meilleurs choix dans les applications pratiques.

Expliquez les capacités de recherche en texte intégral InNODB. Expliquez les capacités de recherche en texte intégral InNODB. Apr 02, 2025 pm 06:09 PM

Les capacités de recherche en texte intégral d'InNODB sont très puissantes, ce qui peut considérablement améliorer l'efficacité de la requête de la base de données et la capacité de traiter de grandes quantités de données de texte. 1) INNODB implémente la recherche de texte intégral via l'indexation inversée, prenant en charge les requêtes de recherche de base et avancées. 2) Utilisez la correspondance et contre les mots clés pour rechercher, prendre en charge le mode booléen et la recherche de phrases. 3) Les méthodes d'optimisation incluent l'utilisation de la technologie de segmentation des mots, la reconstruction périodique des index et l'ajustement de la taille du cache pour améliorer les performances et la précision.

Puis-je installer mysql sur Windows 7 Puis-je installer mysql sur Windows 7 Apr 08, 2025 pm 03:21 PM

Oui, MySQL peut être installé sur Windows 7, et bien que Microsoft ait cessé de prendre en charge Windows 7, MySQL est toujours compatible avec lui. Cependant, les points suivants doivent être notés lors du processus d'installation: téléchargez le programme d'installation MySQL pour Windows. Sélectionnez la version appropriée de MySQL (communauté ou entreprise). Sélectionnez le répertoire d'installation et le jeu de caractères appropriés pendant le processus d'installation. Définissez le mot de passe de l'utilisateur racine et gardez-le correctement. Connectez-vous à la base de données pour les tests. Notez les problèmes de compatibilité et de sécurité sur Windows 7, et il est recommandé de passer à un système d'exploitation pris en charge.

Différence entre l'index cluster et l'index non cluster (index secondaire) dans InnODB. Différence entre l'index cluster et l'index non cluster (index secondaire) dans InnODB. Apr 02, 2025 pm 06:25 PM

La différence entre l'index cluster et l'index non cluster est: 1. Index en cluster stocke les lignes de données dans la structure d'index, ce qui convient à la requête par clé et plage primaire. 2. L'index non clumpant stocke les valeurs de clé d'index et les pointeurs vers les lignes de données, et convient aux requêtes de colonne de clés non primaires.

MySQL: Concepts simples pour l'apprentissage facile MySQL: Concepts simples pour l'apprentissage facile Apr 10, 2025 am 09:29 AM

MySQL est un système de gestion de base de données relationnel open source. 1) Créez une base de données et des tables: utilisez les commandes CreateDatabase et CreateTable. 2) Opérations de base: insérer, mettre à jour, supprimer et sélectionner. 3) Opérations avancées: jointure, sous-requête et traitement des transactions. 4) Compétences de débogage: vérifiez la syntaxe, le type de données et les autorisations. 5) Suggestions d'optimisation: utilisez des index, évitez de sélectionner * et utilisez les transactions.

La relation entre l'utilisateur de MySQL et la base de données La relation entre l'utilisateur de MySQL et la base de données Apr 08, 2025 pm 07:15 PM

Dans la base de données MySQL, la relation entre l'utilisateur et la base de données est définie par les autorisations et les tables. L'utilisateur a un nom d'utilisateur et un mot de passe pour accéder à la base de données. Les autorisations sont accordées par la commande Grant, tandis que le tableau est créé par la commande Create Table. Pour établir une relation entre un utilisateur et une base de données, vous devez créer une base de données, créer un utilisateur, puis accorder des autorisations.

Mysql et Mariadb peuvent-ils coexister Mysql et Mariadb peuvent-ils coexister Apr 08, 2025 pm 02:27 PM

MySQL et MARIADB peuvent coexister, mais doivent être configurés avec prudence. La clé consiste à allouer différents numéros de port et répertoires de données à chaque base de données et ajuster les paramètres tels que l'allocation de mémoire et la taille du cache. La mise en commun de la connexion, la configuration des applications et les différences de version doivent également être prises en compte et doivent être soigneusement testées et planifiées pour éviter les pièges. L'exécution de deux bases de données simultanément peut entraîner des problèmes de performances dans les situations où les ressources sont limitées.

Expliquez différents types d'index MySQL (B-Tree, hachage, texte intégral, spatial). Expliquez différents types d'index MySQL (B-Tree, hachage, texte intégral, spatial). Apr 02, 2025 pm 07:05 PM

MySQL prend en charge quatre types d'index: B-Tree, hachage, texte intégral et spatial. 1. L'indice de tree B est adapté à la recherche de valeur égale, à la requête de plage et au tri. 2. L'indice de hachage convient aux recherches de valeur égale, mais ne prend pas en charge la requête et le tri des plages. 3. L'index de texte complet est utilisé pour la recherche en texte intégral et convient pour le traitement de grandes quantités de données de texte. 4. L'indice spatial est utilisé pour la requête de données géospatiaux et convient aux applications SIG.

See all articles