MHA 實現mysql真正意義上的高可用

MHA:

 MHA數據庫高可用集羣,是一套優秀的作爲mysql高可用性環境下故障切換主從的軟件,在故障切換的過程中MHA能夠做到在30秒自動完成數據庫的故障切換,並在切換的過程中最大程度的保證數據的一致性,以達到真正意義上的高可用。

MHA的特點:
  • 故障轉移
  • 保證數據的一致性
工作流程:

 當監控到集羣中的主庫宕機,會嘗試獲取主庫宕機時的二進制文件,獲取到之後,找到已經同步最新數據的從庫,將該從庫的中繼日誌傳給其他的從庫,來同步數據,保證從庫之間的數據一致性,從從庫中找到一臺作爲新的主庫,並同步從之前的主庫中獲取到的二進制文件,其餘的從庫從這個新的主庫中同步數據,保證主從複製的集羣正常的運行。

部署MHA實現mysql高可用:

Host 網絡信息
Master ens33:192.168.43.176
Slave1 ens33:192.168.43.104
Slave2 ens33:192.168.43.23
MHA ens33:192.168.43.29
軟件包鏈接:http://note.youdao.com/noteshare?id=0afa42355a5acbe6a01fef39b3aa99ea
Master:
[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables-save 
[root@localhost ~]# yum -y install mariadb mariadb-server mariadb-devel
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysqladmin -u root password 123.com
[root@localhost ~]# vim /etc/my.cnf
server-id=1
log-bin=mysql-log
[root@localhost ~]# mysql -u root -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-log.000003 |      245 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> grant all on *.* to 'slave'@'192.168.43.%' identified by '123.com' with grant option;
1 row in set (0.00 sec)

MariaDB [(none)]> flush privileges;
    1 row in set (0.00 sec)
Slave1:
[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables-save 
[root@localhost ~]# yum -y install mariadb mariadb-server mariadb-devel
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysqladmin -u root password 123.com
[root@localhost ~]# vim /etc/my.cnf
server-id=2
log-bin=mysql-log
[root@localhost ~]# mysql -u root -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> stop slave;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> change master to master_host='192.168.43.176',master_user='slave',master_password='123.com',master_log_file='mysql-log.000001',master_log_pos=245;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> start slave;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
                Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.43.176
                Master_User: slave
                Master_Port: 3306
                Connect_Retry: 60
            Master_Log_File: mysql-log.000003
        Read_Master_Log_Pos: 245
            Relay_Log_File: mariadb-relay-bin.000003
                Relay_Log_Pos: 616
    Relay_Master_Log_File: mysql-log.000003
         Slave_IO_Running: Yes
        Slave_SQL_Running: Yes
          Replicate_Do_DB: 
      Replicate_Ignore_DB: 
       Replicate_Do_Table: 
   Replicate_Ignore_Table: 
  Replicate_Wild_Do_Table: 
Replicate_Wild_Ignore_Table: 
               Last_Errno: 0
               Last_Error: 
             Skip_Counter: 0
      Exec_Master_Log_Pos: 245
          Relay_Log_Space: 912
          Until_Condition: None
           Until_Log_File: 
            Until_Log_Pos: 0
       Master_SSL_Allowed: No
       Master_SSL_CA_File: 
       Master_SSL_CA_Path: 
          Master_SSL_Cert: 
        Master_SSL_Cipher: 
           Master_SSL_Key: 
    Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
            Last_SQL_Errno: 0
            Last_SQL_Error: 
Replicate_Ignore_Server_Ids: 
            Master_Server_Id: 2
1 row in set (0.00 sec)
Slave2:
[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables-save 
[root@localhost ~]# yum -y install mariadb mariadb-server mariadb-devel
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysqladmin -u root password 123.com
[root@localhost ~]# vim /etc/my.cnf
server-id=3
log-bin=mysql-log
    [root@localhost ~]# mysql -u root -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> stop slave;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> change master to master_host='192.168.43.176',master_user='slave',master_password='123.com',master_log_file='mysql-log.000001',master_log_pos=245;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> start slave;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
                Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.43.176
                Master_User: slave
                Master_Port: 3306
                Connect_Retry: 60
            Master_Log_File: mysql-log.000003
        Read_Master_Log_Pos: 245
            Relay_Log_File: mariadb-relay-bin.000003
                Relay_Log_Pos: 616
    Relay_Master_Log_File: mysql-log.000003
         Slave_IO_Running: Yes
        Slave_SQL_Running: Yes
          Replicate_Do_DB: 
      Replicate_Ignore_DB: 
       Replicate_Do_Table: 
   Replicate_Ignore_Table: 
  Replicate_Wild_Do_Table: 
Replicate_Wild_Ignore_Table: 
               Last_Errno: 0
               Last_Error: 
             Skip_Counter: 0
      Exec_Master_Log_Pos: 245
          Relay_Log_Space: 912
          Until_Condition: None
           Until_Log_File: 
            Until_Log_Pos: 0
       Master_SSL_Allowed: No
       Master_SSL_CA_File: 
       Master_SSL_CA_Path: 
          Master_SSL_Cert: 
        Master_SSL_Cipher: 
           Master_SSL_Key: 
    Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
            Last_SQL_Errno: 0
            Last_SQL_Error: 
Replicate_Ignore_Server_Ids: 
            Master_Server_Id: 2
1 row in set (0.00 sec)
Slave1:
[root@localhost ~]# vim /etc/my.cnf
relay_log_purge=0
read_only=1
[root@localhost ~]# systemctl restart mariadb
Slave2:
[root@localhost ~]# vim /etc/my.cnf
relay_log_purge=0
read_only=1
[root@localhost ~]# systemctl restart mariadb
Master:
MariaDB [(none)]> grant all on *.* to 'mha'@'192.168.43.%' identified by '123.com';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Slave1:
MariaDB [(none)]> grant all on *.* to 'mha'@'192.168.43.%' identified by '123.com';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Slave2:
MariaDB [(none)]> grant all on *.* to 'mha'@'192.168.43.%' identified by '123.com';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Master:
[root@localhost ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
dd:44:45:b4:4c:31:5f:4a:29:8d:b2:58:d0:2e:8d:83 root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
|        .o  .*Oo.|
|          +.o+o=.|
|       . * o..+ .|
|      E =.+o     |
|        So. .    |
|                 |
|                 |
|                 |
|                 |
+-----------------+
[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.176 (192.168.43.176)' can't be established.
ECDSA key fingerprint is fc:4d:22:b7:b2:79:9f:da:21:1a:57:c5:59:3d:27:63.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.29 (192.168.43.29)' can't be established.
ECDSA key fingerprint is 5f:6a:c4:b2:c9:49:0f:0f:93:c5:49:71:60:0a:68:c5.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
Slave1:
[root@localhost ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
9a:72:8f:ec:21:42:23:41:08:58:a7:82:dc:cc:68:2c root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
|=o. .            |
|B =o             |
|E=.+             |
|oo               |
|. o     S        |
| o .   o         |
|  . o =          |
|   . = +         |
|     .+ .        |
+-----------------+
[root@localhost ~]# ssh-copy-id [email protected]

The authenticity of host '192.168.43.176 (192.168.43.176)' can't be established.
ECDSA key fingerprint is fc:4d:22:b7:b2:79:9f:da:21:1a:57:c5:59:3d:27:63.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.104 (192.168.43.104)' can't be established.
ECDSA key fingerprint is 02:89:1d:f4:9b:66:c4:a9:a9:9e:5f:8d:d9:48:9e:f1.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.23 (192.168.43.23)' can't be established.
ECDSA key fingerprint is 86:09:71:21:24:06:f4:9b:ae:08:08:ea:4c:31:84:8f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.29 (192.168.43.29)' can't be established.
ECDSA key fingerprint is 5f:6a:c4:b2:c9:49:0f:0f:93:c5:49:71:60:0a:68:c5.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
Slave2:
[root@localhost ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
96:fa:3e:e3:b5:ef:59:0a:f6:10:03:82:e9:c9:40:c1 root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
| .o.             |
| .E  o           |
|  . o . .        |
|   + . . o       |
|    +   S o      |
|       o   o     |
|      .   =   .  |
|       .oo = +   |
|       o+o.o*    |
+-----------------+
[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.176 (192.168.43.176)' can't be established.
ECDSA key fingerprint is fc:4d:22:b7:b2:79:9f:da:21:1a:57:c5:59:3d:27:63.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.104 (192.168.43.104)' can't be established.
ECDSA key fingerprint is 02:89:1d:f4:9b:66:c4:a9:a9:9e:5f:8d:d9:48:9e:f1.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.23 (192.168.43.23)' can't be established.
ECDSA key fingerprint is 86:09:71:21:24:06:f4:9b:ae:08:08:ea:4c:31:84:8f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '192.168.43.29 (192.168.43.29)' can't be established.
ECDSA key fingerprint is 5f:6a:c4:b2:c9:49:0f:0f:93:c5:49:71:60:0a:68:c5.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
MHA:
[root@localhost ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zKIX0BtC/08XGpRy9UXdcaEPSDCUTeeN9I8jkGVGXdI root@localhost
The key's randomart image is:
+---[RSA 2048]----+
|    .   .+***+.*X|
|   . o  .o=*=.*oE|
|    o +  o+..=.o |
|     o *   + .o..|
|      + S o o o..|
|     . o o . . . |
|    . .   .      |
|     .           |
|                 |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:     "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.43.176 (192.168.43.176)' can't be established.
ECDSA key fingerprint is SHA256:ykcEsw+4rMNKMOeL3Hj119DxX6izmdRGpgfY/RFHgQA.
ECDSA key fingerprint is MD5:fc:4d:22:b7:b2:79:9f:da:21:1a:57:c5:59:3d:27:63.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.43.104 (192.168.43.104)' can't be established.
ECDSA key fingerprint is SHA256:VUy72dDXxHUZFcfqyGGlGYX3IGBI++aL7uNlufMJAsQ.
ECDSA key fingerprint is MD5:02:89:1d:f4:9b:66:c4:a9:a9:9e:5f:8d:d9:48:9e:f1.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.43.23 (192.168.43.23)' can't be established.
ECDSA key fingerprint is SHA256:PjbUpTdGG1FtiYjG1P2DIADe646/IxZq5ge0sQybAhE.
ECDSA key fingerprint is MD5:86:09:71:21:24:06:f4:9b:ae:08:08:ea:4c:31:84:8f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.43.29 (192.168.43.29)' can't be established.
ECDSA key fingerprint is SHA256:c95uG4dZ1JJ38uiuDU4rF3qiVRGoyjBgqDgWA6aS6NM.
ECDSA key fingerprint is MD5:5f:6a:c4:b2:c9:49:0f:0f:93:c5:49:71:60:0a:68:c5.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
Master:
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm 
warning: epel-release-latest-7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Preparing...                          ################################# [100%]
Updating / installing...
    1:epel-release-7-11                ################################# [100%]
[root@localhost ~]# yum -y install perl-DBD-mysql perl-DBI perl
[root@localhost ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
    1:mha4mysql-node-0.56-0.el6        ################################# [100%]
Slave1:
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm 
warning: epel-release-latest-7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Preparing...                          ################################# [100%]
Updating / installing...
    1:epel-release-7-11                ################################# [100%]
[root@localhost ~]# yum -y install perl-DBD-mysql perl-DBI perl
[root@localhost ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
    1:mha4mysql-node-0.56-0.el6        ################################# [100%]
Slave2:
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm 
warning: epel-release-latest-7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Preparing...                          ################################# [100%]
Updating / installing...
    1:epel-release-7-11                ################################# [100%]
[root@localhost ~]# yum -y install perl-DBD-mysql perl-DBI perl
[root@localhost ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
    1:mha4mysql-node-0.56-0.el6        ################################# [100%]
MHA:
[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables-save 
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm 
warning: epel-release-latest-7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Preparing...                          ################################# [100%]
Updating / installing...
    1:epel-release-7-11                ################################# [100%]
[root@localhost ~]# yum -y install perl-DBD-mysql perl-DBI perl
[root@localhost ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
    1:mha4mysql-node-0.56-0.el6        ################################# [100%]
[root@localhost ~]# yum -y install perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager
[root@localhost ~]# rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm 
[root@localhost ~]# vim /etc/masterha_default.cnf
[server default]
user=mha                        #數據庫對manager授權的用戶。
password=123.com                #用戶的密碼。
repl_user=slave                 #主從複製的用戶。
repl_password=123.com           #用戶密碼。
ssh_user=root                   #ssh協議使用的的用戶。
master_binlog_dir=/var/lib/mysql            #主數據庫二進制文件存放的目錄。
remote_workdir=/data/login                  #主節點宕機後,主節點二進制文件存放的目錄
ping_interval=2                             #manager節點和數據庫之間通訊的時間間隔  單位s。
shutdown_script=""                          #當主節點宕機後要執行的腳本文件  這裏可以是空。
[root@localhost ~]# mkdir /etc/mha
[root@localhost ~]# mkdir /data/login
[root@localhost ~]# vim /etc/mha/app1.cnf
[server default]
manager_workdir=/var/log/manager            #manager節點工作的目錄。
manager_log=/var/log/manager/manager.log    #manager節點日誌文件。
[server1]                                   #監控的節點。
hostname=192.168.43.176                     #監控節點的ip。
port=3306                                   #端口。
ssh_port=22                                 #與節點通信的端口。
[server2]
hostname=192.168.43.104
port=3306
ssh_port=22
candidate_master=1                          #當主節點宕機後,由這個從節點作爲主。
[server3]
hostname=192.168.43.23
port=3306
ssh_port=22
[root@localhost ~]# masterha_check_ssh --global-conf=/etc/masterha_default.cnf --conf=/etc/mha/app1.cnf                    #檢測節點間的主從複製是否正常。
[root@localhost ~]# masterha_check_ssh --global-conf=/etc/masterha_default.cnf --conf=/etc/mha/app1.cnf
Tue Nov 26 17:04:58 2019 - [info] Reading default configuration from /etc/masterha_default.cnf..
Tue Nov 26 17:04:58 2019 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Tue Nov 26 17:04:58 2019 - [info] Reading server configuration from /etc/mha/app1.cnf..
Tue Nov 26 17:04:58 2019 - [info] Starting SSH connection tests..
Tue Nov 26 17:04:59 2019 - [debug] 
Tue Nov 26 17:04:58 2019 - [debug]  Connecting via SSH from [email protected](192.168.43.176:22) to [email protected](192.168.43.104:22)..
Tue Nov 26 17:04:59 2019 - [debug]   ok.
Tue Nov 26 17:04:59 2019 - [debug]  Connecting via SSH from [email protected](192.168.43.176:22) to [email protected](192.168.43.23:22)..
Tue Nov 26 17:04:59 2019 - [debug]   ok.
Tue Nov 26 17:05:00 2019 - [debug] 
Tue Nov 26 17:04:58 2019 - [debug]  Connecting via SSH from [email protected](192.168.43.104:22) to [email protected](192.168.43.176:22)..
Tue Nov 26 17:04:59 2019 - [debug]   ok.
Tue Nov 26 17:04:59 2019 - [debug]  Connecting via SSH from [email protected](192.168.43.104:22) to [email protected](192.168.43.23:22)..
Tue Nov 26 17:05:00 2019 - [debug]   ok.
Tue Nov 26 17:05:00 2019 - [debug] 
Tue Nov 26 17:04:59 2019 - [debug]  Connecting via SSH from [email protected](192.168.43.23:22) to [email protected](192.168.43.176:22)..
Tue Nov 26 17:05:00 2019 - [debug]   ok.
Tue Nov 26 17:05:00 2019 - [debug]  Connecting via SSH from [email protected](192.168.43.23:22) to [email protected](192.168.43.104:22)..
Tue Nov 26 17:05:00 2019 - [debug]   ok.
Tue Nov 26 17:05:00 2019 - [info] All SSH connection tests passed successfully.
[root@localhost ~]# masterha_check_repl --global-conf=/etc/masterha_default.cnf --conf=/etc/mha/app1.cnf
Tue Nov 26 17:06:09 2019 - [info] Reading default configuration from /etc/masterha_default.cnf..
Tue Nov 26 17:06:09 2019 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Tue Nov 26 17:06:09 2019 - [info] Reading server configuration from /etc/mha/app1.cnf..
Tue Nov 26 17:06:09 2019 - [info] MHA::MasterMonitor version 0.56.
Creating directory /var/log/manager.. done.
Tue Nov 26 17:06:11 2019 - [info] GTID failover mode = 0
Tue Nov 26 17:06:11 2019 - [info] Dead Servers:
Tue Nov 26 17:06:11 2019 - [info] Alive Servers:
Tue Nov 26 17:06:11 2019 - [info]   192.168.43.176(192.168.43.176:3306)
Tue Nov 26 17:06:11 2019 - [info]   192.168.43.104(192.168.43.104:3306)
Tue Nov 26 17:06:11 2019 - [info]   192.168.43.23(192.168.43.23:3306)
Tue Nov 26 17:06:11 2019 - [info] Alive Slaves:
Tue Nov 26 17:06:11 2019 - [info]   192.168.43.104(192.168.43.104:3306)      Version=5.5.64-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov 26 17:06:11 2019 - [info]     Replicating from 192.168.43.176(192.168.43.176:3306)
Tue Nov 26 17:06:11 2019 - [info]     Primary candidate for the new Master (candidate_master is set)
Tue Nov 26 17:06:11 2019 - [info]   192.168.43.23(192.168.43.23:3306)  Version=5.5.64-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov 26 17:06:11 2019 - [info]     Replicating from 192.168.43.176(192.168.43.176:3306)
Tue Nov 26 17:06:11 2019 - [info] Current Alive Master: 192.168.43.176(192.168.43.176:3306)
Tue Nov 26 17:06:11 2019 - [info] Checking slave configurations..
Tue Nov 26 17:06:11 2019 - [info] Checking replication filtering settings..
Tue Nov 26 17:06:11 2019 - [info]  binlog_do_db= , binlog_ignore_db= 
Tue Nov 26 17:06:11 2019 - [info]  Replication filtering check ok.
Tue Nov 26 17:06:11 2019 - [info] GTID (with auto-pos) is not supported
Tue Nov 26 17:06:11 2019 - [info] Starting SSH connection tests..
Tue Nov 26 17:06:13 2019 - [info] All SSH connection tests passed successfully.
Tue Nov 26 17:06:13 2019 - [info] Checking MHA Node version..
Tue Nov 26 17:06:14 2019 - [info]  Version check ok.
Tue Nov 26 17:06:14 2019 - [info] Checking SSH publickey authentication settings     on the current master..
Tue Nov 26 17:06:14 2019 - [info] HealthCheck: SSH to 192.168.43.176 is reachable.
Tue Nov 26 17:06:15 2019 - [info] Master MHA Node version is 0.56.
Tue Nov 26 17:06:15 2019 - [info] Checking recovery script configurations on 192.168.43.176(192.168.43.176:3306)..
Tue Nov 26 17:06:15 2019 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql --output_file=/data/login/save_binary_logs_test --manager_version=0.56 --start_file=mysql-log.000002 
Tue Nov 26 17:06:15 2019 - [info]   Connecting to [email protected](192.168.43.176:22).. 
    Creating /data/login if not exists.. Creating directory /data/login.. done.
    ok.
    Checking output directory is accessible or not..
    ok.
    Binlog found at /var/lib/mysql, up to mysql-log.000002
Tue Nov 26 17:06:15 2019 - [info] Binlog setting check done.
Tue Nov 26 17:06:15 2019 - [info] Checking SSH publickey authentication and     checking recovery script configurations on all alive slave servers..
Tue Nov 26 17:06:15 2019 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=192.168.43.104 --slave_ip=192.168.43.104 --slave_port=3306 --workdir=/data/login --target_version=5.5.64-MariaDB --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info  --relay_dir=/var/lib/mysql/  --slave_pass=xxx
Tue Nov 26 17:06:15 2019 - [info]   Connecting to [email protected](192.168.43.104:22).. 
Creating directory /data/login.. done.
    Checking slave recovery environment settings..
        Opening /var/lib/mysql/relay-log.info ... ok.
        Relay log found at /var/lib/mysql, up to mariadb-relay-bin.000005
        Temporary relay log file is /var/lib/mysql/mariadb-relay-bin.000005
        Testing mysql connection and privileges.. done.
        Testing mysqlbinlog output.. done.
        Cleaning up test file(s).. done.
Tue Nov 26 17:06:15 2019 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=192.168.43.23 --slave_ip=192.168.43.23 --slave_port=3306 --workdir=/data/login --target_version=5.5.64-MariaDB --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info  --relay_dir=/var/lib/mysql/  --slave_pass=xxx
Tue Nov 26 17:06:15 2019 - [info]   Connecting to [email protected](192.168.43.23:22).. 
Creating directory /data/login.. done.
    Checking slave recovery environment settings..
        Opening /var/lib/mysql/relay-log.info ... ok.
        Relay log found at /var/lib/mysql, up to mariadb-relay-bin.000005
        Temporary relay log file is /var/lib/mysql/mariadb-relay-bin.000005
        Testing mysql connection and privileges.. done.
        Testing mysqlbinlog output.. done.
        Cleaning up test file(s).. done.
Tue Nov 26 17:06:16 2019 - [info] Slaves settings check done.
Tue Nov 26 17:06:16 2019 - [info] 
192.168.43.176(192.168.43.176:3306) (current master)
    +--192.168.43.104(192.168.43.104:3306)
    +--192.168.43.23(192.168.43.23:3306)

Tue Nov 26 17:06:16 2019 - [info] Checking replication health on 192.168.43.104..
Tue Nov 26 17:06:16 2019 - [info]  ok.
Tue Nov 26 17:06:16 2019 - [info] Checking replication health on 192.168.43.23..
Tue Nov 26 17:06:16 2019 - [info]  ok.
Tue Nov 26 17:06:16 2019 - [warning] master_ip_failover_script is not defined.
Tue Nov 26 17:06:16 2019 - [warning] shutdown_script is not defined.
Tue Nov 26 17:06:16 2019 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.
[root@localhost ~]# masterha_manager --global-conf=/etc/masterha_default.cnf --conf=/etc/mha/app1.cnf
Tue Nov 26 17:08:15 2019 - [info] Reading default configuration from /etc/masterha_default.cnf..
Tue Nov 26 17:08:15 2019 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Tue Nov 26 17:08:15 2019 - [info] Reading server configuration from /etc/mha/app1.cnf..
Master:
[root@localhost mysql]# systemctl stop mariadb
Slave1:
[root@localhost ~]# mysql -u root -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.00 sec)
Slave2:
[root@localhost ~]# mysql -u root -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
5 rows in set (0.00 sec)
MHA:
Creating /data/login if not exists..    ok.
Checking output directory is accessible or not..
ok.
Binlog found at /var/lib/mysql, up to mysql-log.000002
Tue Nov 26 17:09:55 2019 - [info] Reading default configuration from /etc/masterha_default.cnf..
Tue Nov 26 17:09:55 2019 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Tue Nov 26 17:09:55 2019 - [info] Reading server configuration from /etc/mha/app1.cnf..
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章