环境

  1. manager 192.168.137.141
  2. master1 192.168.137.144
  3. master2 192.168.137.145
  4. slave 192.168.137.141
  5. vip 192.168.137.199

部署

三台机器已安装mysql。

百度云:链接:https://pan.baidu.com/s/1an3QjoFFdqcjo5-KWRCShw 密码:wsq9

  1. 192.168.137.141
  2. mha4mysql-manager-0.55-0.el6.noarch.rpm
  3. mha4mysql-node-0.54-0.el6.noarch.rpm
  4.  
  5. 192.168.137.144
  6. 192.168.137.145
  7. mha4mysql-node-0.54-0.el6.noarch.rpm

依赖

链接:https://pan.baidu.com/s/1mTcoBiUsvATQMkM3bXJKrA 密码:rpvq

  1. yum install perl perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN perl-DBD-MySQL

都要安装。

主模块1:配置集群之前SSH免密码登录

两步完成ssh免密码登录

  1. 192.168.137.141 --> 192.168.137.144
  2. 192.168.137.141 --> 192.168.137.145
  3.  
  4. 192.168.137.144 --> 192.168.137.141
  5. 192.168.137.144 --> 192.168.137.145
  6.  
  7. 192.168.137.145 --> 192.168.137.141
  8. 192.168.137.145 --> 192.168.137.144
  9.  
  10. 6

主模块2:配置集群主从复制

mysql主备部署[高可用]

  1. master: 192.168.137.144
  2. slave: 192.168.137.145
  3.  
  4. master: 192.168.137.144
  5. slave: 192.168.137.141

主模块3:manager配置

  1. mkdir -p /etc/masterha
  2.  
  3. cd /etc/masterha
  4.  
  5. vim app1.cnf

app1.cnf

  1. [server default]
  2. user=root
  3. password=lizhenghua
  4. manager_workdir=/etc/masterha
  5. manager_log=/etc/masterha/logs/manager.log
  6. remote_workdir=/etc/masterha
  7. ssh_user=root
  8. repl_user=sync
  9. repl_password=sync
  10. ping_interval=3
  11. #master_ip_online_change_script=/etc/masterha/script/master_ip_online_change
  12. master_ip_failover_script=/etc/masterha/script/master_ip_failover
  13. #report_script=/etc/masterha/script/sendMail_report
  14. [server1]
  15. hostname=192.168.137.144
  16. port=3306
  17. master_binlog_dir=/usr/local/mysql/data/
  18. candidate_master=1
  19. [server2]
  20. hostname=192.168.137.145
  21. port=3306
  22. master_binlog_dir=/usr/local/mysql/data/
  23. candidate_master=1
  24. [server3]
  25. hostname=192.168.137.141
  26. port=3306
  27. master_binlog_dir=/usr/local/mysql/data/
  28. candidate_master=1

副模块1:检测SSH

  1. masterha_check_ssh --conf=/etc/masterha/app1.cnf

模块2:检测主从

  1. masterha_check_repl --conf=/etc/masterha/app1.cnf

manager启动方式

  1. vim start.sh
  2.  
  3. #!/usr/bin/bash
  4. nohup perl /root/perl5/bin/masterha_manager --conf=/etc/masterha/conf/app1.cnf &

功能测试

192.168.137.141

  1. mysql> show slave status \G\
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.168.137.144
  5. Master_User: sync
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: mysql-bin.000003
  9. Read_Master_Log_Pos: 154
  10. Relay_Log_File: mysql-relay-bin.000004
  11. Relay_Log_Pos: 367
  12. Relay_Master_Log_File: mysql-bin.000003
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 0
  22. Last_Error:
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 154
  25. Relay_Log_Space: 740
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path:
  32. Master_SSL_Cert:
  33. Master_SSL_Cipher:
  34. Master_SSL_Key:
  35. Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37. Last_IO_Errno: 0
  38. Last_IO_Error:
  39. Last_SQL_Errno: 0
  40. Last_SQL_Error:
  41. Replicate_Ignore_Server_Ids:
  42. Master_Server_Id: 144
  43. Master_UUID: 9abbdca0-424e-11e8-a71a-000c29deb434
  44. Master_Info_File: /usr/local/mysql/data/master.info
  45. SQL_Delay: 0
  46. SQL_Remaining_Delay: NULL
  47. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  48. Master_Retry_Count: 86400
  49. Master_Bind:
  50. Last_IO_Error_Timestamp:
  51. Last_SQL_Error_Timestamp:
  52. Master_SSL_Crl:
  53. Master_SSL_Crlpath:
  54. Retrieved_Gtid_Set:
  55. Executed_Gtid_Set:
  56. Auto_Position: 0
  57. Replicate_Rewrite_DB:
  58. Channel_Name:
  59. Master_TLS_Version:
  60. 1 row in set (0.00 sec)

kill掉192.168.137.144机器上的mysql, 然后141开始切换master

  1. mysql> show slave status \G\
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.168.137.145
  5. Master_User: sync
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: mysql-bin.000003
  9. Read_Master_Log_Pos: 154
  10. Relay_Log_File: mysql-relay-bin.000002
  11. Relay_Log_Pos: 320
  12. Relay_Master_Log_File: mysql-bin.000003
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 0
  22. Last_Error:
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 154
  25. Relay_Log_Space: 527
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path:
  32. Master_SSL_Cert:
  33. Master_SSL_Cipher:
  34. Master_SSL_Key:
  35. Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37. Last_IO_Errno: 0
  38. Last_IO_Error:
  39. Last_SQL_Errno: 0
  40. Last_SQL_Error:
  41. Replicate_Ignore_Server_Ids:
  42. Master_Server_Id: 145
  43. Master_UUID: 9abbdca0-424e-11e8-a71a-000c29deb433
  44. Master_Info_File: /usr/local/mysql/data/master.info
  45. SQL_Delay: 0
  46. SQL_Remaining_Delay: NULL
  47. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  48. Master_Retry_Count: 86400
  49. Master_Bind:
  50. Last_IO_Error_Timestamp:
  51. Last_SQL_Error_Timestamp:
  52. Master_SSL_Crl:
  53. Master_SSL_Crlpath:
  54. Retrieved_Gtid_Set:
  55. Executed_Gtid_Set:
  56. Auto_Position: 0
  57. Replicate_Rewrite_DB:
  58. Channel_Name:
  59. Master_TLS_Version:
  60. 1 row in set (0.00 sec)

manager上日志

切换成功!

主模块3:VIP

master_ip_failover

  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings FATAL => 'all';
  5.  
  6. use Getopt::Long;
  7.  
  8. my (
  9. $command, $ssh_user, $orig_master_host, $orig_master_ip,
  10. $orig_master_port, $new_master_host, $new_master_ip, $new_master_port
  11. );
  12.  
  13. my $vip = '192.168.137.199/24';
  14. my $key = '0';
  15. my $ssh_start_vip = "/usr/sbin/ifconfig ens33:$key $vip netmask 255.255.255.0 up";
  16. my $ssh_stop_vip = "/usr/sbin/ifconfig ens33:$key down";
  17.  
  18. GetOptions(
  19. 'command=s' => \$command,
  20. 'ssh_user=s' => \$ssh_user,
  21. 'orig_master_host=s' => \$orig_master_host,
  22. 'orig_master_ip=s' => \$orig_master_ip,
  23. 'orig_master_port=i' => \$orig_master_port,
  24. 'new_master_host=s' => \$new_master_host,
  25. 'new_master_ip=s' => \$new_master_ip,
  26. 'new_master_port=i' => \$new_master_port,
  27. );
  28.  
  29. exit &main();
  30.  
  31. sub main {
  32.  
  33. print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";
  34.  
  35. if ( $command eq "stop" || $command eq "stopssh" ) {
  36.  
  37. my $exit_code = 1;
  38. eval {
  39. print "Disabling the VIP on old master: $orig_master_host \n";
  40. &stop_vip();
  41. $exit_code = 0;
  42. };
  43. if ($@) {
  44. warn "Got Error: $@\n";
  45. exit $exit_code;
  46. }
  47. exit $exit_code;
  48. }
  49. elsif ( $command eq "start" ) {
  50.  
  51. my $exit_code = 10;
  52. eval {
  53. print "Enabling the VIP - $vip on the new master - $new_master_host \n";
  54. &start_vip();
  55. $exit_code = 0;
  56. };
  57. if ($@) {
  58. warn $@;
  59. exit $exit_code;
  60. }
  61. exit $exit_code;
  62. }
  63. elsif ( $command eq "status" ) {
  64. print "Checking the Status of the script.. OK \n";
  65. exit 0;
  66. }
  67. else {
  68. &usage();
  69. exit 1;
  70. }
  71. }
  72.  
  73. sub start_vip() {
  74. `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
  75. }
  76. sub stop_vip() {
  77. return 0 unless ($ssh_user);
  78. `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
  79. }
  80.  
  81. sub usage {
  82. print
  83. "Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip
  84. --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n";
  85. } 

检测VIP漂移

第一步:启动manager

  1. [root@localhost masterha]# ./start.sh
  2. [root@localhost masterha]# nohup: 把输出追加到"nohup.out"
  3.  
  4. 务必保证已经启动成功(ssh,主从检测都没错一般不会出问题)!
  5. start.sh里写了什么? 看上面

第二步:停止master mysql(192.168.137.144)

  1. [root@localhost masterha]# ssh root@192.168.137.144 "service mysql stop"
  2. Shutting down MySQL............ SUCCESS!

看manager.log日志

查看原来master1 192.168.137.144发现VIP已经被down掉

发现VIP漂移到了新的master2 192.168.137.145上

此时VIP切换成功!

同时查看主从切换, 按道理说现在master1 192.168.137.144上的mysql已经宕掉, slave应该连接新的master2 137.145上

  1. 漂移前查询
    mysql> show slave status \G
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.168.137.144
  5. Master_User: sync
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: mysql-bin.000016
  9. Read_Master_Log_Pos: 154
  10. Relay_Log_File: mysql-relay-bin.000002
  11. Relay_Log_Pos: 320
  12. Relay_Master_Log_File: mysql-bin.000016
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 0
  22. Last_Error:
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 154
  25. Relay_Log_Space: 527
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path:
  32. Master_SSL_Cert:
  33. Master_SSL_Cipher:
  34. Master_SSL_Key:
  35. Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37. Last_IO_Errno: 0
  38. Last_IO_Error:
  39. Last_SQL_Errno: 0
  40. Last_SQL_Error:
  41. Replicate_Ignore_Server_Ids:
  42. Master_Server_Id: 144
  43. Master_UUID: 9abbdca0-424e-11e8-a71a-000c29deb434
  44. Master_Info_File: /usr/local/mysql/data/master.info
  45. SQL_Delay: 0
  46. SQL_Remaining_Delay: NULL
  47. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  48. Master_Retry_Count: 86400
  49. Master_Bind:
  50. Last_IO_Error_Timestamp:
  51. Last_SQL_Error_Timestamp:
  52. Master_SSL_Crl:
  53. Master_SSL_Crlpath:
  54. Retrieved_Gtid_Set:
  55. Executed_Gtid_Set:
  56. Auto_Position: 0
  57. Replicate_Rewrite_DB:
  58. Channel_Name:
  59. Master_TLS_Version:
  60. 1 row in set (0.00 sec)
  61. 漂移后查询
  62. mysql> show slave status \G
  63. *************************** 1. row ***************************
  64. Slave_IO_State: Waiting for master to send event
  65. Master_Host: 192.168.137.145
  66. Master_User: sync
  67. Master_Port: 3306
  68. Connect_Retry: 60
  69. Master_Log_File: mysql-bin.000005
  70. Read_Master_Log_Pos: 154
  71. Relay_Log_File: mysql-relay-bin.000002
  72. Relay_Log_Pos: 320
  73. Relay_Master_Log_File: mysql-bin.000005
  74. Slave_IO_Running: Yes
  75. Slave_SQL_Running: Yes
  76. Replicate_Do_DB:
  77. Replicate_Ignore_DB:
  78. Replicate_Do_Table:
  79. Replicate_Ignore_Table:
  80. Replicate_Wild_Do_Table:
  81. Replicate_Wild_Ignore_Table:
  82. Last_Errno: 0
  83. Last_Error:
  84. Skip_Counter: 0
  85. Exec_Master_Log_Pos: 154
  86. Relay_Log_Space: 527
  87. Until_Condition: None
  88. Until_Log_File:
  89. Until_Log_Pos: 0
  90. Master_SSL_Allowed: No
  91. Master_SSL_CA_File:
  92. Master_SSL_CA_Path:
  93. Master_SSL_Cert:
  94. Master_SSL_Cipher:
  95. Master_SSL_Key:
  96. Seconds_Behind_Master: 0
  97. Master_SSL_Verify_Server_Cert: No
  98. Last_IO_Errno: 0
  99. Last_IO_Error:
  100. Last_SQL_Errno: 0
  101. Last_SQL_Error:
  102. Replicate_Ignore_Server_Ids:
  103. Master_Server_Id: 145
  104. Master_UUID: 9abbdca0-424e-11e8-a71a-000c29deb433
  105. Master_Info_File: /usr/local/mysql/data/master.info
  106. SQL_Delay: 0
  107. SQL_Remaining_Delay: NULL
  108. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  109. Master_Retry_Count: 86400
  110. Master_Bind:
  111. Last_IO_Error_Timestamp:
  112. Last_SQL_Error_Timestamp:
  113. Master_SSL_Crl:
  114. Master_SSL_Crlpath:
  115. Retrieved_Gtid_Set:
  116. Executed_Gtid_Set:
  117. Auto_Position: 0
  118. Replicate_Rewrite_DB:
  119. Channel_Name:
  120. Master_TLS_Version:
  121. 1 row in set (0.00 sec)

VIP漂移正常,主从复制正常,MHA搭建成功!

报错信息:

SSH

  1. 测试ssh报错
  2. [root@localhost app]# masterha_check_ssh --conf=/etc/masterha/app/app1.cnf
  3. Thu May 17 01:04:32 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  4. Thu May 17 01:04:32 2018 - [info] Reading application default configurations from /etc/masterha/app/app1.cnf..
  5. Thu May 17 01:04:32 2018 - [info] Reading server configurations from /etc/masterha/app/app1.cnf..
  6. Thu May 17 01:04:32 2018 - [info] Starting SSH connection tests..
  7. Thu May 17 01:04:33 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln63]
  8. Thu May 17 01:04:32 2018 - [debug] Connecting via SSH from root@192.168.137.144(192.168.137.144:22) to root@192.168.137.145(192.168.137.145:22)..
  9. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
  10. Thu May 17 01:04:32 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln111] SSH connection from root@192.168.137.144(192.168.137.144:22) to root@192.168.137.145(192.168.137.145:22) failed!
  11. Thu May 17 01:04:33 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln63]
  12. Thu May 17 01:04:32 2018 - [debug] Connecting via SSH from root@192.168.137.145(192.168.137.145:22) to root@192.168.137.144(192.168.137.144:22)..
  13. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
  14. Thu May 17 01:04:33 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln111] SSH connection from root@192.168.137.145(192.168.137.145:22) to root@192.168.137.144(192.168.137.144:22) failed!
  15. Bizarre copy of ARRAY in scalar assignment at /usr/share/perl5/vendor_perl/Carp.pm line 182.
  16. 解决方案
  17. 三台机器互相配置ssh免密码认证(每台两次共6次)
  18. 再测
  19. [root@localhost app]# masterha_check_ssh --conf=/etc/masterha/app/app1.cnf
  20. Thu May 17 01:12:33 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  21. Thu May 17 01:12:33 2018 - [info] Reading application default configurations from /etc/masterha/app/app1.cnf..
  22. Thu May 17 01:12:33 2018 - [info] Reading server configurations from /etc/masterha/app/app1.cnf..
  23. Thu May 17 01:12:33 2018 - [info] Starting SSH connection tests..
  24. Thu May 17 01:12:34 2018 - [debug]
  25. Thu May 17 01:12:33 2018 - [debug] Connecting via SSH from root@192.168.137.144(192.168.137.144:22) to root@192.168.137.145(192.168.137.145:22)..
  26. Thu May 17 01:12:34 2018 - [debug] ok.
  27. Thu May 17 01:12:35 2018 - [debug]
  28. Thu May 17 01:12:34 2018 - [debug] Connecting via SSH from root@192.168.137.145(192.168.137.145:22) to root@192.168.137.144(192.168.137.144:22)..
  29. Thu May 17 01:12:35 2018 - [debug] ok.
  30. Thu May 17 01:12:35 2018 - [info] All SSH connection tests passed successfully.

主从1

  1. 主主同步报错
  2. mysql> show slave status \G
  3. *************************** 1. row ***************************
  4. Slave_IO_State:
  5. Master_Host: 192.168.137.145
  6. Master_User: sync
  7. Master_Port: 3306
  8. Connect_Retry: 60
  9. Master_Log_File: mysql-bin.000001
  10. Read_Master_Log_Pos: 336
  11. Relay_Log_File: localhost-relay-bin.000001
  12. Relay_Log_Pos: 4
  13. Relay_Master_Log_File: mysql-bin.000001
  14. Slave_IO_Running: No
  15. Slave_SQL_Running: Yes
  16. Replicate_Do_DB:
  17. Replicate_Ignore_DB:
  18. Replicate_Do_Table:
  19. Replicate_Ignore_Table:
  20. Replicate_Wild_Do_Table:
  21. Replicate_Wild_Ignore_Table:
  22. Last_Errno: 0
  23. Last_Error:
  24. Skip_Counter: 0
  25. Exec_Master_Log_Pos: 336
  26. Relay_Log_Space: 154
  27. Until_Condition: None
  28. Until_Log_File:
  29. Until_Log_Pos: 0
  30. Master_SSL_Allowed: No
  31. Master_SSL_CA_File:
  32. Master_SSL_CA_Path:
  33. Master_SSL_Cert:
  34. Master_SSL_Cipher:
  35. Master_SSL_Key:
  36. Seconds_Behind_Master: NULL
  37. Master_SSL_Verify_Server_Cert: No
  38. Last_IO_Errno: 1593
  39. Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
  40. Last_SQL_Errno: 0
  41. Last_SQL_Error:
  42. Replicate_Ignore_Server_Ids:
  43. Master_Server_Id: 145
  44. Master_UUID:
  45. Master_Info_File: /usr/local/mysql/data/master.info
  46. SQL_Delay: 0
  47. SQL_Remaining_Delay: NULL
  48. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  49. Master_Retry_Count: 86400
  50. Master_Bind:
  51. Last_IO_Error_Timestamp: 180517 01:37:32
  52. Last_SQL_Error_Timestamp:
  53. Master_SSL_Crl:
  54. Master_SSL_Crlpath:
  55. Retrieved_Gtid_Set:
  56. Executed_Gtid_Set:
  57. Auto_Position: 0
  58. Replicate_Rewrite_DB:
  59. Channel_Name:
  60. Master_TLS_Version:
  61. 1 row in set (0.00 sec)
  62. 解决:
  63. [root@localhost .ssh]# cd /usr/local/mysql/data/
  64. [root@localhost data]# vim auto.cnf
  65. [auto]
  66. server-uuid=9abbdca0-424e-11e8-a71a-000c29deb434
  67. 保存退出。(保证两个mysqluuid不一致即可)

主从2

  1. 报错3:主从问题
  2. [root@localhost ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
  3. Thu May 17 21:32:15 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  4. Thu May 17 21:32:15 2018 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
  5. Thu May 17 21:32:15 2018 - [info] Reading server configurations from /etc/masterha/app1.cnf..
  6. Thu May 17 21:32:15 2018 - [info] MHA::MasterMonitor version 0.55.
  7. Thu May 17 21:32:15 2018 - [warning] SQL Thread is stopped(no error) on 192.168.137.144(192.168.137.144:3306)
  8. Thu May 17 21:32:15 2018 - [error][/root/perl5/lib/perl5/MHA/ServerManager.pm, ln732] Multi-master configuration is detected, but two or more masters are either writable (read-only is not set) or dead! Check configurations for details. Master configurations are as below:
  9. Master 192.168.137.145(192.168.137.145:3306), replicating from 192.168.137.144(192.168.137.144:3306)
  10. Master 192.168.137.144(192.168.137.144:3306), replicating from 192.168.137.145(192.168.137.145:3306)
  11.  
  12. Thu May 17 21:32:15 2018 - [error][/root/perl5/lib/perl5/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations. at /root/perl5/lib/perl5/MHA/MasterMonitor.pm line 300.
  13. Thu May 17 21:32:15 2018 - [error][/root/perl5/lib/perl5/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.
  14. Thu May 17 21:32:15 2018 - [info] Got exit code 1 (Not master dead).
  15.  
  16. MySQL Replication Health is NOT OK!
  17. [root@localhost ~]#
  18. 解决:
  19. 在每台mysqlmy.cnf下配置属性:(主要是备机)
  20. relay-log=/usr/local/mysql/binlog/mysql-relay-bin
  21. mkdir -p /usr/local/mysql/binlog
  22. chown -R mysql:mysql /usr/local/mysql/binlog
  23. 重启mysql
  24. 重新配置主从:
  25. CHANGE MASTER TO MASTER_HOST='192.168.137.144',MASTER_USER='sync',MASTER_PASSWORD='sync',MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=154;
  26.  
  27. 结果:
  28.  
  29. [root@localhost ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
  30. Thu May 17 21:58:11 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  31. Thu May 17 21:58:11 2018 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
  32. Thu May 17 21:58:11 2018 - [info] Reading server configurations from /etc/masterha/app1.cnf..
  33. Thu May 17 21:58:11 2018 - [info] MHA::MasterMonitor version 0.55.
  34. Thu May 17 21:58:11 2018 - [info] Dead Servers:
  35. Thu May 17 21:58:11 2018 - [info] Alive Servers:
  36. Thu May 17 21:58:11 2018 - [info] 192.168.137.144(192.168.137.144:3306)
  37. Thu May 17 21:58:11 2018 - [info] 192.168.137.145(192.168.137.145:3306)
  38. Thu May 17 21:58:11 2018 - [info] Alive Slaves:
  39. Thu May 17 21:58:11 2018 - [info] 192.168.137.145(192.168.137.145:3306) Version=5.7.21-log (oldest major version between slaves) log-bin:enabled
  40. Thu May 17 21:58:11 2018 - [info] Replicating from 192.168.137.144(192.168.137.144:3306)
  41. Thu May 17 21:58:11 2018 - [info] Primary candidate for the new Master (candidate_master is set)
  42. Thu May 17 21:58:11 2018 - [info] Current Alive Master: 192.168.137.144(192.168.137.144:3306)
  43. Thu May 17 21:58:11 2018 - [info] Checking slave configurations..
  44. Thu May 17 21:58:11 2018 - [info] read_only=1 is not set on slave 192.168.137.145(192.168.137.145:3306).
  45. Thu May 17 21:58:11 2018 - [warning] relay_log_purge=0 is not set on slave 192.168.137.145(192.168.137.145:3306).
  46. Thu May 17 21:58:11 2018 - [info] Checking replication filtering settings..
  47. Thu May 17 21:58:11 2018 - [info] binlog_do_db= , binlog_ignore_db=
  48. Thu May 17 21:58:11 2018 - [info] Replication filtering check ok.
  49. Thu May 17 21:58:11 2018 - [info] Starting SSH connection tests..
  50. Thu May 17 21:58:12 2018 - [info] All SSH connection tests passed successfully.
  51. Thu May 17 21:58:12 2018 - [info] Checking MHA Node version..
  52. Thu May 17 21:58:13 2018 - [info] Version check ok.
  53. Thu May 17 21:58:13 2018 - [info] Checking SSH publickey authentication settings on the current master..
  54. Thu May 17 21:58:13 2018 - [info] HealthCheck: SSH to 192.168.137.144 is reachable.
  55. Thu May 17 21:58:14 2018 - [info] Master MHA Node version is 0.54.
  56. Thu May 17 21:58:14 2018 - [info] Checking recovery script configurations on the current master..
  57. Thu May 17 21:58:14 2018 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/usr/local/mysql/data/ --output_file=/masterha/save_binary_logs_test --manager_version=0.55 --start_file=mysql-bin.000002
  58. Thu May 17 21:58:14 2018 - [info] Connecting to root@192.168.137.144(192.168.137.144)..
  59. Creating /masterha if not exists.. Creating directory /masterha.. done.
  60. ok.
  61. Checking output directory is accessible or not..
  62. ok.
  63. Binlog found at /usr/local/mysql/data/, up to mysql-bin.000002
  64. Thu May 17 21:58:14 2018 - [info] Master setting check done.
  65. Thu May 17 21:58:14 2018 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
  66. Thu May 17 21:58:14 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.137.145 --slave_ip=192.168.137.145 --slave_port=3306 --workdir=/masterha --target_version=5.7.21-log --manager_version=0.55 --relay_log_info=/usr/local/mysql/data/relay-log.info --relay_dir=/usr/local/mysql/data/ --slave_pass=xxx
  67. Thu May 17 21:58:14 2018 - [info] Connecting to root@192.168.137.145(192.168.137.145:22)..
  68. Creating directory /masterha.. done.
  69. Checking slave recovery environment settings..
  70. Opening /usr/local/mysql/data/relay-log.info ... ok.
  71. Relay log found at /usr/local/mysql/binlog, up to mysql-relay-bin.000002
  72. Temporary relay log file is /usr/local/mysql/binlog/mysql-relay-bin.000002
  73. Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
  74. done.
  75. Testing mysqlbinlog output.. done.
  76. Cleaning up test file(s).. done.
  77. Thu May 17 21:58:15 2018 - [info] Slaves settings check done.
  78. Thu May 17 21:58:15 2018 - [info]
  79. 192.168.137.144 (current master)
  80. +--192.168.137.145
  81.  
  82. Thu May 17 21:58:15 2018 - [info] Checking replication health on 192.168.137.145..
  83. Thu May 17 21:58:15 2018 - [info] ok.
  84. Thu May 17 21:58:15 2018 - [warning] master_ip_failover_script is not defined.
  85. Thu May 17 21:58:15 2018 - [warning] shutdown_script is not defined.
  86. Thu May 17 21:58:15 2018 - [info] Got exit code 0 (Not master dead).
  87.  
  88. MySQL Replication Health is OK.

VIP

VIP恢复master1后, 重新启动manager后发现报错

解决方法:按提示删除指定文件即可。

ssh

这是我搭建的第二遍了, 这是第二遍时出的错

由于manager有点特殊,在测试ssh的时候发现了一个大问题, 折磨了我很久

master:148

master2:149

slave:150

为什么会这样, 这是ssh 148 --> 149不行, 但是手动ssh登录的时候是可以免密码跨越的.

后来想到这是manager和slave一体的

  1. ssh-copy-id root@192.168.137.148

192.168.137.148是本机, 这是给本地的一个免密

然后再测试, 完美通过

mysqlbinlog

如下

  1. [root@localhost masterha]# masterha_check_repl --conf=/etc/masterha/app1.cnf
  2. Fri Jul 20 23:39:47 2018 - [info] Checking recovery script configurations on 192.168.137.148(192.168.137.148:3306)..
  3. Fri Jul 20 23:39:47 2018 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/opt/mysql/data/ --output_file=/etc/masterha/save_binary_logs_test --manager_version=0.58 --start_file=mysql-bin.000001
  4. Fri Jul 20 23:39:47 2018 - [info] Connecting to root@192.168.137.148(192.168.137.148:22)..
  5. Creating /etc/masterha if not exists.. ok.
  6. Checking output directory is accessible or not..
  7. ok.
  8. Binlog found at /opt/mysql/data/, up to mysql-bin.000001
  9. Fri Jul 20 23:39:47 2018 - [info] Binlog setting check done.
  10. Fri Jul 20 23:39:47 2018 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
  11. Fri Jul 20 23:39:47 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.137.149 --slave_ip=192.168.137.149 --slave_port=3306 --workdir=/etc/masterha --target_version=5.7.22-log --manager_version=0.58 --relay_log_info=/opt/mysql/data/relay-log.info --relay_dir=/opt/mysql/data/ --slave_pass=xxx
  12. Fri Jul 20 23:39:47 2018 - [info] Connecting to root@192.168.137.149(192.168.137.149:22)..
  13. Can't exec "mysqlbinlog": 没有那个文件或目录 at /usr/share/perl5/vendor_perl/MHA/BinlogManager.pm line 106.
  14. mysqlbinlog version command failed with rc 1:0, please verify PATH, LD_LIBRARY_PATH, and client options
  15. at /usr/bin/apply_diff_relay_logs line 532.
  16. Fri Jul 20 23:39:48 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln208] Slaves settings check failed!
  17. Fri Jul 20 23:39:48 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln416] Slave configuration failed.
  18. Fri Jul 20 23:39:48 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln427] Error happened on checking configurations. at /usr/bin/masterha_check_repl line 48.
  19. Fri Jul 20 23:39:48 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln525] Error happened on monitoring servers.
  20. Fri Jul 20 23:39:48 2018 - [info] Got exit code 1 (Not master dead).
  21.  
  22. MySQL Replication Health is NOT OK!

这个报错就是没有搞这个环境, 然后它找不到mysqlbinlog这个命令, 这个就比较容易解决

  1. ln -s /opt/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog

第一个是你mysql中bin的mysqlbinlog, 把它软链接扔进全局环境/usr/bin里面

Slave IO

如下

  1. Fri Jul 20 23:48:07 2018 - [info] Checking replication health on 192.168.137.149..
  2. Fri Jul 20 23:48:07 2018 - [info] ok.
  3. Fri Jul 20 23:48:07 2018 - [info] Checking replication health on 192.168.137.150..
  4. Fri Jul 20 23:48:07 2018 - [info] ok.
  5. Fri Jul 20 23:48:07 2018 - [info] Checking replication health on 192.168.137.148..
  6. Fri Jul 20 23:48:07 2018 - [error][/usr/share/perl5/vendor_perl/MHA/Server.pm, ln490] Slave IO thread is not running on 192.168.137.148(192.168.137.148:3306)
  7. Fri Jul 20 23:48:07 2018 - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln1526] failed!
  8. Fri Jul 20 23:48:07 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln427] Error happened on checking configurations. at /usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm line 420.
  9. Fri Jul 20 23:48:07 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln525] Error happened on monitoring servers.
  10. Fri Jul 20 23:48:07 2018 - [info] Got exit code 1 (Not master dead).
  11.  
  12. MySQL Replication Health is NOT OK!

这个报错完全就是打快了, 不小心把主从同步的slave命令(下面那一条)扔进了master中, 罪过

CHANGE MASTER TO MASTER_HOST='192.168.137.148',MASTER_USER='sync',MASTER_PASSWORD='lizhenghua',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=1121;

这个解决的思路就是从master中干掉它即可

  1. mysql>stop slave;
  2. mysql>reset slave all;

MYSQL之MHA集群的更多相关文章

  1. 基于Docker Compose构建的MySQL MHA集群

    Docker MySQL MHA 基于Docker 1.13.1之上构建的MySQL MHA Docker Compose Project 可快速启动GTID模式下的MasterHA集群, 主用于My ...

  2. MySQL高可用篇之MHA集群

    1 准备工作 1.1 修改主机名 vim /etc/hosts # 添加对应主机 192.168.28.128 mha1 192.168.28.131 mha2 192.168.28.132 mha3 ...

  3. MySQL高可用集群MHA方案

    MySQL高可用集群MHA方案 爱奇艺在用的数据库高可用方案 MHA 是目前比较成熟及流行的 MySQL 高可用解决方案,很多互联网公司正是直接使用或者基于 MHA 的架构进行改造实现 MySQL 的 ...

  4. MySQL企业常用集群图解

      mysql集群架构图片 1.mysql企业常用集群架构 在中小型互联网的企业中.mysql的集群一般就是上图的架构.WEB节点读取数据库的时候读取dbproxy服务器.dbproxy服务器通过对S ...

  5. MHA集群(gtid复制)和vip漂移

    在上一片博客中,讲述了怎么去配置MHA架构!这片博客不再细说,只说明其中MySQL主从搭建,这里使用的是gtid加上半同步复制! 步骤与上一片博客一样,不同之处在于MySQL主从的搭建!详细的gtid ...

  6. Docker搭建MySQL的PXC集群

    原文:Docker搭建MySQL的PXC集群 一.简介 PXC属于一套近乎完美的mysql高可用集群解决方案,相比那些比较传统的基于主从复制模式的集群架构MHA和MM+keepalived,galer ...

  7. 三十六.MHA集群概述 、 部署MHA集群 测试配置

    1.准备MHA集群环境 准备6台虚拟机,并按照本节规划配置好IP参数 在这些虚拟机之间实现SSH免密登录 在相应节点上安装好MHA相关的软件包   使用6台RHEL 7虚拟机,如图-1所示.准备集群环 ...

  8. MySQL高可用集群方案

    一.Mysql高可用解决方案 方案一:共享存储 一般共享存储采用比较多的是 SAN/NAS 方案. 方案二:操作系统实时数据块复制 这个方案的典型场景是 DRBD,DRBD架构(MySQL+DRBD+ ...

  9. Mysql Innodb cluster集群搭建

    之前搭建过一个Mysql Ndb cluster集群,但是mysql版本是5.7的,看到官网上mysql8的还是开发者版本,所以尝试搭建下mysql Innodb cluster集群. MySQL的高 ...

随机推荐

  1. MySQL--3约束和修改数据表总结

  2. Serveral effective linux commands

    1. 统计当前文件夹下文件个数(不包括子目录下文件): $ ls -l | grep "^-" | wc -l 2. 统计当前文件夹下文件个数(包括子目录下文件): $ ls -l ...

  3. java基础(二) -对象和类

    Java 对象和类 Java作为一种面向对象语言.支持以下基本概念: 多态 继承 封装 抽象 类 对象 实例 方法 重载 对象:对象是类的一个实例(对象不是找个女朋友),有状态和行为.例如,一条狗是一 ...

  4. Robot FrameWork使用中常见问题收集

    1.“假死”现象 在完成一个模块的脚本编写后,多次运行没问题,但是隔了几天再来运行的时候,发现脚本运行会出现浏览器那边不动了,脚本这边的时间一直在跑. 问题原因及解决方法: 问题解决了,原因是**dr ...

  5. echo 内容显示颜色

    一,字体显示颜色 #字体颜色:30m-37m 黑.红.绿.黄.蓝.紫.青.白str=”要显示的字体“echo -e "\033[30m ${str}\033[0m"      ## ...

  6. QT 添加 lib库

    扒自网友文章: 一.添加第三方的头文件 首先,添加头文件  #include "ControlCAN.h" 然后,再将这个头文件放到工程的目录下 二.添加.lib文件 首先,将.l ...

  7. C++时间类型详解( time_t 和 tm )

    原文:http://blog.csdn.net/love_gaohz/article/details/6637625 Unix时间戳(Unix timestamp),或称Unix时间(Unix tim ...

  8. Bootstrap-全局CSS样式-图片样式

    Bootstrap第二部分:全局CSS样式-图片样式.img-rounded   圆角图片.img-circle    圆形图片.img-thumbnail 缩略图片.img-responsive响应 ...

  9. flask orm

    #查询        #查第一行    session.query(User.id,User.userName,User.password).first()        #查所有行    sessi ...

  10. sqlserver清除缓存,记录查询时间

    文章来至:https://www.cnblogs.com/50614090/p/4001464.html --1. 将当前数据库的全部脏页写入磁盘.“脏页”是已输入缓存区高速缓存且已修改但尚未写入磁盘 ...