1. 程式人生 > >MHA-Atlas-MYSQL高可用叢集

MHA-Atlas-MYSQL高可用叢集

一,mysql-mha環境準備

  1.1 準備三臺虛擬機器

主機名 IP地址 描述
MySQL-Master 192.168.200.130 CentOS6.5  安裝mysql5.6
MySQL-SLaveA 192.168.200.144 CentOS6.5  安裝mysql5.6
MySQL-SLaveB 192.168.200.145 CentOS6.5  安裝mysql5.6

  1.2 準備軟體包

  (1)mha manager管理節點安裝包

    mha4mysql-manager-0.56-0.el6.noarch.rpm

    mha4mysql-manager-0.56.tar.gz

  (2)mha node節點安裝包

    mha4mysql-node-0.56-0.el6.noarch.rpm

    mha4mysql-node-0.56.tar.gz

  (3)mysql中介軟體

    Atlas-2.2.1.el6.x86_64.rpm

  (4)mysql原始碼包

    mysql-5.6.17-linux-glibc2.5-x86_64.tar

  1.3 主機名對映

1 [[email protected] ~]# echo "192.168.200.130 MySQL-Master" >> /etc/hosts
2 [[email protected] ~]# echo "192.168.200.144 MySQL-SlaveA" >> /etc/hosts
3 [[email protected] ~]# echo "192.168.200.144 MySQL-SlaveB" >> /etc/hosts
4 [[email protected] ~]# cat /etc/hosts
5 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 6 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 7 192.168.200.130 MySQL-Master 8 192.168.200.144 MySQL-SlaveA 9 192.168.200.144 MySQL-SlaveB

  1.4 關閉selinux和iptables

 1 [[email protected] ~]# vim /etc/sysconfig/selinux 
 2 [[email protected] ~]# cat /etc/sysconfig/selinux 
 3 
 4 # This file controls the state of SELinux on the system.
 5 # SELINUX= can take one of these three values:
 6 #     enforcing - SELinux security policy is enforced.
 7 #     permissive - SELinux prints warnings instead of enforcing.
 8 #     disabled - No SELinux policy is loaded.
 9 SELINUX=disabled
10 # SELINUXTYPE= can take one of these two values:
11 #     targeted - Targeted processes are protected,
12 #     mls - Multi Level Security protection.
13 SELINUXTYPE=targeted 
14 
15 [[email protected] ~]# setenforce 0
16 [[email protected] ~]# service iptables stop   #關閉防火牆
17 [[email protected] ~]# chkconfig iptables off  #關閉防火牆開機啟動
18 [[email protected] ~]# 

二,簡介

  2.1 軟體介紹

  (1)MHA(Master High Availability)目前在MySQL高可用方面是一個相對成熟的解決方案,是一套優 秀的作為MySQL高可用性環境下故障切換和主從提升的高可用軟體。在MySQL故障切換過程中,MHA能做到0~30秒之內自動完成資料庫的故障切換操作,並且在進行故障切換過程中,MHA能最大程度上保證資料庫的一致性,以達到真正意義上的高可用。

  (2)MHA由兩部分組成:MHA Manager(管理節點)和MHA Node(資料節點)。MHA Manager可以獨立部署在一臺獨立的機器上管理多個Master-Slave叢集,也可以部署在一臺Slave上。當Master出現故障時,它可以自動將最新資料的Slave提升為新的Master,然後將所有其他的Slave重新指向新的Master。整個故障轉移過程對應程式是完全透明的。

  2.2 工作流程

  (1)從宕機崩潰的master儲存二進位制日誌事件(binlog events)

  (2)識別含有最新更新的slave

  (3)應用差異的中繼日誌(relay log)到其他的slave

  (4)應用從master儲存的二進位制日誌事件(binlog events)

  (5)提升一個slave為新的master

  (6)使其他的slave連線新的master進行復制

  2.3 MHA工具

 1 #Manager工具包主要包括以下幾個工具:
 2 
 3 masterha_check_ssh          #檢查MHA的SSH配置狀況
 4 masterha_check_repl         #檢查MySQL複製狀況
 5 masterha_check_status       #檢測當前MHA執行狀態
 6 masterha_master_monitor     #檢測master是否宕機
 7 masterha_manger             #啟動MHA
 8 masterha_master_switch      #控制故障轉移(自動或者手動)
 9 masterha_conf_host          #新增或刪除配置的server資訊
10 masterha_secondary_check    #試圖建立TCP連線從遠端伺服器
11 masterha_stop               #停止MHA
12 
13 #Node工具包主要包括以下幾個工具:
14 
15 save_binary_logs            #儲存和複製master的二進位制日誌
16 apply_diff_relay_logs       #識別差異的中繼日誌事件
17 filter_mysqlbinlog          #去除不必要的ROLLBACK事件
18 purge_relay_logs            #清除中繼日誌

三,MySQL環境準備

  3.1 環境檢查

  MySQL-Master

#系統版本
1
[[email protected] ~]# cat /etc/redhat-release 2 CentOS release 6.5 (Final) 3 [[email protected] ~]# uname -r 4 2.6.32-431.el6.x86_64 5 [[email protected] ~]# hostname -I 6 192.168.200.130 7 [[email protected] ~]#

  MySQL-SlaveA

#系統版本
1
[[email protected] ~]# cat /etc/redhat-release 2 CentOS release 6.5 (Final) 3 [[email protected] ~]# uname -r 4 2.6.32-431.el6.x86_64 5 [[email protected] ~]# hostname -I 6 192.168.200.144

  MySQL-SlaveB

#系統版本
1
[[email protected] ~]# cat /etc/redhat-release 2 CentOS release 6.5 (Final) 3 [[email protected] ~]# uname -r 4 2.6.32-431.el6.x86_64 5 [[email protected] ~]# hostname -I 6 192.168.200.145 7 [[email protected] ~]#

  3.2 安裝MySQL

  3.2.1 安裝MYSQL( 由於mysql不能克隆,所以3臺虛擬機器都要安裝)

 1 [[email protected] ~]# yum -y install ncurses-devel
 2 [[email protected] ~]# yum -y install libaio
 3 [[email protected] ~]# tar xf mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
 4 [[email protected] ~]# ln -s /usr/local/mysql-5.6.17-linux-glibc2.5-x86_64 /usr/local/mysql
 5 [[email protected] ~]# useradd mysql -s /sbin/nologin -M
 6 [[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
 7 [[email protected] ~]# /bin/cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
 8 [[email protected] ~]# /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
 9 [[email protected] ~]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
10 [[email protected] ~]# which mysqladmin
11 /usr/local/bin/mysqladmin

  3.2.2 加入開機自啟動並啟動mysql

1 [[email protected] ~]# chkconfig mysqld on
2 [[email protected] ~]# chkconfig mysqld --list
3 mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
4 [[email protected] ~]# /etc/init.d/mysqld start
5 Starting MySQL. SUCCESS! 

  3.2.2 設定mysql密碼

1 [[email protected] ~]# mysqladmin -uroot password '123123'

四,配置基於GTID的主從複製

  4.1 滿足的條件

  主庫和從庫都要開啟binlog日誌

  主庫和從庫的server-id不能相同

  要有主從複製賬戶

  4.2 主庫操作(MySQL-Master)

  4.2.1 修改主庫配置檔案 

 1 [[email protected] ~]# cat /etc//my.cnf 
 2 [client]
 3 socket          = /usr/local/mysql/data/mysql.sock
 4 [mysqld]
 5 lower_case_table_names  = 1
 6 default-storage-engine  = InnoDB
 7 port            = 3306
 8 datadir         = /usr/local/mysql/data
 9 character-set-server    = utf8
10 socket          = /usr/local/mysql/data/mysql.sock
11 
12 log_bin         = mysql-bin     #開啟binlog日誌
13 server_id       = 1             #設定server_id
14 
15 innodb_buffer_pool_size = 200M
16 slave-parallel-workers  = 8
17 thread_cache_size   = 600
18 back_log        = 600
19 slave_net_timeout   = 60
20 max_binlog_size     = 512M
21 key_buffer_size     = 8M
22 query_cache_size    = 64M
23 join_buffer_size    = 2M
24 sort_buffer_size    = 2M
25 query_cache_type    = 1
26 thread_stack        = 192K

  重啟MySQL服務

1 [[email protected] ~]# /etc/init.d/mysqld restart
2 Shutting down MySQL.. SUCCESS! 
3 Starting MySQL.. SUCCESS! 

  4.2.2 登入MySQL刪除不必要的使用者並建立主從複製賬戶

  (1)刪除不必要的使用者

1 [[email protected] ~]# mysql -uroot -p123123    #登入MySQL 
 1 mysql> select user,host from mysql.user;
 2 +------+--------------+
 3 | user | host         |
 4 +------+--------------+
 5 | root | 127.0.0.1    |
 6 | root | ::1          |
 7 |      | localhost    |
 8 | root | localhost    |
 9 |      | mysql-master |
10 | root | mysql-master |
11 +------+--------------+
12 6 rows in set (0.01 sec)
13 
14 mysql> drop user [email protected]127.0.0.1;
15 Query OK, 0 rows affected (0.32 sec)
16 
17 mysql> drop user [email protected]'::1';
18 Query OK, 0 rows affected (0.00 sec)
19 
20 mysql> drop user ' '@'localhost';
21 Query OK, 0 rows affected (0.00 sec)
22 
23 mysql> drop user ' '@'mysql-master';
24 Query OK, 0 rows affected (0.00 sec)
25 
26 mysql> select user,host from mysql.user;
27 +------+--------------+
28 | user | host         |
29 +------+--------------+
30 | root | localhost    |
31 | root | mysql-master |
32 +------+--------------+
33 2 rows in set (0.00 sec)

  (2)建立主從複製賬戶

 1 mysql> grant replication slave on *.* to [email protected]'192.168.200.%' identified by '123123';
 2 Query OK, 0 rows affected (0.01 sec)
 3 
 4 mysql> select user,host from mysql.user;
 5 +------+---------------+
 6 | user | host          |
 7 +------+---------------+
 8 | rep  | 192.168.200.% |
 9 | root | localhost     |
10 | root | mysql-master  |
11 +------+---------------+
12 3 rows in set (0.00 sec)
13 
14 mysql> show grants for [email protected]'192.168.200.%';
15 +----------------------------------------------------------------------------------------------------------------------------+
16 | Grants for [email protected]192.168.200.%                                                                                               |
17 +----------------------------------------------------------------------------------------------------------------------------+
18 | GRANT REPLICATION SLAVE ON *.* TO 'rep'@'192.168.200.%' IDENTIFIED BY PASSWORD '*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1' |
19 +----------------------------------------------------------------------------------------------------------------------------+
20 1 row in set (0.00 sec)

  4.3 從庫操作(MySQL-SlaveA和MySQL-SlaveB)

  4.3.1 修改配置檔案

  MySQL-SlaveA配置檔案與MySQL-Master相同,只需修改server-id=5 即可

 1 [[email protected] ~]# cat /etc/my.cnf 
 2 [client]
 3 socket          = /usr/local/mysql/data/mysql.sock
 4 [mysqld]
 5 lower_case_table_names  = 1
 6 default-storage-engine  = InnoDB
 7 port            = 3306
 8 datadir         = /usr/local/mysql/data
 9 character-set-server    = utf8
10 socket          = /usr/local/mysql/data/mysql.sock
11 
12 log_bin         = mysql-bin         #從binlog也要開啟
13 server_id       = 5                 #僅需修改此項
14 
15 innodb_buffer_pool_size = 200M
16 slave-parallel-workers  = 8
17 thread_cache_size   = 600
18 back_log        = 600
19 slave_net_timeout   = 60
20 max_binlog_size     = 512M
21 key_buffer_size     = 8M
22 query_cache_size    = 64M
23 join_buffer_size    = 2M
24 sort_buffer_size    = 2M
25 query_cache_type    = 1
26 thread_stack        = 192K 
1 [[email protected] ~]# /etc/init.d/mysqld restart #重啟mysql
2 Shutting down MySQL.. SUCCESS! 
3 Starting MySQL. SUCCESS!

  MySQL-SlaveB配置檔案與MySQL-Master相同,只需修改server-id=10即可

 1 [[email protected] ~]# cat /etc/my.cnf 
 2 [client]
 3 socket          = /usr/local/mysql/data/mysql.sock
 4 [mysqld]
 5 lower_case_table_names  = 1
 6 default-storage-engine  = InnoDB
 7 port            = 3306
 8 datadir         = /usr/local/mysql/data
 9 character-set-server    = utf8
10 socket          = /usr/local/mysql/data/mysql.sock
11 
12 log_bin         = mysql-bin     #從binlog也要開啟
13 server_id       = 10            #只需修改此項
14 
15 innodb_buffer_pool_size = 200M
16 slave-parallel-workers  = 8
17 thread_cache_size   = 600
18 back_log        = 600
19 slave_net_timeout   = 60
20 max_binlog_size     = 512M
21 key_buffer_size     = 8M
22 query_cache_size    = 64M
23 join_buffer_size    = 2M
24 sort_buffer_size    = 2M
25 query_cache_type    = 1
26 thread_stack        = 192K
1 [[email protected] ~]# /etc/init.d/mysqld restart #重啟mysql
2 Shutting down MySQL.. SUCCESS! 
3 Starting MySQL. SUCCESS! 

  注:在以前如果是基於binlog日誌的主從複製,則必須要記住主庫的master狀態,但是在MySQL5.6版本以後多了一個GTID功能,可以自動記錄主從複製位置點的資訊,並在日誌中輸出出來。

  4.4 開啟GTID

  我們檢視一下GTID的狀態,發現是關閉的

 1 mysql> show global variables like '%gtid%';
 2 +--------------------------+-------+
 3 | Variable_name            | Value |
 4 +--------------------------+-------+
 5 | enforce_gtid_consistency | OFF   |
 6 | gtid_executed            |       |
 7 | gtid_mode                | OFF   |
 8 | gtid_owned               |       |
 9 | gtid_purged              |       |
10 +--------------------------+-------+
11 5 rows in set (0.01 sec)

  修改MySQL配置檔案(主庫從庫都要修改)

  

  修改完配置檔案重啟資料庫

1 [[email protected] ~]# /etc/init.d/mysqld restart
2 Shutting down MySQL.. SUCCESS! 
3 Starting MySQL..................... SUCCESS! 
4 [[email protected] ~]# /etc/init.d/mysqld restart
5 Shutting down MySQL.. SUCCESS! 
6 Starting MySQL. SUCCESS! 
7 [[email protected] ~]# /etc/init.d/mysqld restart
8 Shutting down MySQL.. SUCCESS! 
9 Starting MySQL. SUCCESS! 

  再次檢視GTID狀態

 1 [[email protected] ~]# mysql -uroot -p123123
 2 Warning: Using a password on the command line interface can be insecure.
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 1
 5 Server version: 5.6.17-log MySQL Community Server (GPL)
 6 
 7 Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql> show global variables like '%gtid%';
16 +--------------------------+-------+
17 | Variable_name            | Value |
18 +--------------------------+-------+
19 | enforce_gtid_consistency | ON    |
20 | gtid_executed            |       |
21 | gtid_mode                | ON    | #開啟GTID模組
22 | gtid_owned               |       |
23 | gtid_purged              |       |
24 +--------------------------+-------+
25 5 rows in set (0.00 sec)

  注:主庫從庫都要開啟GTID,否則主從複製時會報錯

  4.5 配置主從複製(MySQL-SlaveA,MySQL-SlaveB)

1 mysql> change master to \
2     -> master_host='192.168.200.130',\     #主庫IP
3     -> master_user='rep',\              #主庫複製使用者
4     -> master_password='123123',\       #主庫複製用密碼
5     -> master_auto_position=1;          #GTID位置點(自動追蹤需要同步的position)
6 Query OK, 0 rows affected, 2 warnings (0.00 sec)

  4.6 開啟從庫的主從複製功能(MySQL-SlaveA,MySQL-SlaveB)

 1 mysql> start slave;                      #開啟主從同步功能
 2 Query OK, 0 rows affected, 1 warning (0.15 sec)
 3 
 4 mysql> show slave status\G
 5 *************************** 1. row ***************************
 6                Slave_IO_State: Waiting for master to send event
 7                   Master_Host: 192.168.200.130
 8                   Master_User: rep
 9                   Master_Port: 3306
10                 Connect_Retry: 60
11               Master_Log_File: mysql-bin.000002
12           Read_Master_Log_Pos: 151
13                Relay_Log_File: MySQL-SlaveA-relay-bin.000002
14                 Relay_Log_Pos: 361
15         Relay_Master_Log_File: mysql-bin.000002
16              Slave_IO_Running: Yes       #yes表示成功
17             Slave_SQL_Running: Yes      #yes表示成功
18               Replicate_Do_DB: 
19           Replicate_Ignore_DB: 
20            Replicate_Do_Table: 
21        Replicate_Ignore_Table: 
22       Replicate_Wild_Do_Table: 
23   Replicate_Wild_Ignore_Table: 
24                    Last_Errno: 0
25                    Last_Error: 
26                  Skip_Counter: 0
27           Exec_Master_Log_Pos: 151
28               Relay_Log_Space: 572
29               Until_Condition: None
30                Until_Log_File: 
31                 Until_Log_Pos: 0
32            Master_SSL_Allowed: No
33            Master_SSL_CA_File: 
34            Master_SSL_CA_Path: 
35               Master_SSL_Cert: 
36             Master_SSL_Cipher: 
37                Master_SSL_Key: 
38         Seconds_Behind_Master: 0
39 Master_SSL_Verify_Server_Cert: No
40                 Last_IO_Errno: 0
41                 Last_IO_Error: 
42                Last_SQL_Errno: 0
43                Last_SQL_Error: 
44   Replicate_Ignore_Server_Ids: 
45              Master_Server_Id: 1
46                   Master_UUID: 34ea0409-eea5-11e8-b1b0-000c29812e4d
47              Master_Info_File: /usr/local/mysql/data/master.info
48                     SQL_Delay: 0
49           SQL_Remaining_Delay: NULL
50       Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
51            Master_Retry_Count: 86400
52                   Master_Bind: 
53       Last_IO_Error_Timestamp: 
54      Last_SQL_Error_Timestamp: 
55                Master_SSL_Crl: 
56            Master_SSL_Crlpath: 
57            Retrieved_Gtid_Set: 
58             Executed_Gtid_Set: 
59                 Auto_Position: 1
60 1 row in set (0.00 sec)

  4.7 從庫設定(MySQL-SlaveA,MySQL-SlaveB)

 1 [[email protected] ~]# mysql -uroot -p123123      #登入從庫
 2 Warning: Using a password on the command line interface can be insecure.
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 12
 5 Server version: 5.6.17-log MySQL Community Server (GPL)
 6 
 7 Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql> set global relay_log_purge = 0;   #臨時禁用自動刪除relay log 功能
16 Query OK, 0 rows affected (0.00 sec)
17 
18 mysql> set global read_only=1;         #設定只讀
19 Query OK, 0 rows affected (0.00 sec)

  編輯配置檔案

  修改完配置檔案,重啟MySQL服務

1 [[email protected] ~]# /etc/init.d/mysqld restart
2 Shutting down MySQL.. SUCCESS! 
3 Starting MySQL.. SUCCESS! 
4 
5 [[email protected] ~]# /etc/init.d/mysqld restart
6 Shutting down MySQL.. SUCCESS! 
7 Starting MySQL.. SUCCESS! 

五,部署MHA

  5.1 環境準備(三個都要裝)

 1 #光碟安裝依賴包
 2 [[email protected] ~]# yum -y install perl-DBD-MySQL
 3 
 4 #安裝mha4mysql-node-0.56-0.el6.noarch.rpm
 5 rpm -ivh rpm/mha4mysql-node-0.56-0.el6.noarch.rpm
 6 Preparing...                ########################################### [100%]
 7    1:mha4mysql-node         ########################################### [100%]
 8 
 9 [[email protected] ~]# mysql -uroot -p123123
10 mysql> grant all privileges on *.* to [email protected]'192.168.200.%' identified by '123123';
11 Query OK, 0 rows affected (0.15 sec)
12 
13 mysql> select user,host from mysql.user where user='mha';
14 +------+---------------+
15 | user | host          |
16 +------+---------------+
17 | mha  | 192.168.200.% |
18 +------+---------------+
19 1 row in set (0.12 sec)

  注:主庫上建立mha賬戶,從庫自動複製

  5.2 部署管理節點(mha-manager)

  5.2.1 在MySQL-SlaveB上部署管理節點

 1 #使用阿里雲源+epel源
 2 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
 3 wget -O /etc/yum.repos.d/epel-6.repo http://mirrors.aliyun.com/repo/epel-6.repo
 4 
 5 #安裝manager依賴包(需要公網源)
 6 yum -y install perl-Config-Tiny epel-release perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
 7 
 8 #安裝manager包
 9 [[email protected] ~]# rpm -ivh rpm/mha4mysql-manager-0.56-0.el6.noarch.rpm
10 Preparing...                ########################################### [100%]
11    1:mha4mysql-manager      ########################################### [100%]

  5.2.2 修改配置檔案

 1 #建立配置檔案目錄
 2 [[email protected] ~]# mkdir -p /etc/mha
 3 
 4 #建立日誌目錄
 5 mkdir -p /var/log/mha/mhal
 6 
 7 #建立配置檔案(預設沒有)
 8 [[email protected] ~]# cd /etc/mha/
 9 [[email protected]SlaveB mha]# ls
10 [[email protected] mha]# vim /etc/mha/mhal.cnf
11 
12 [server default]
13 manager_log=/var/log/mha/mha1/manager     #manager管理日誌存放路徑
14 manager_workdir=/var/log/mha/mha1             #manager管理日誌的目錄路徑
15 master_binlog_dir=/usr/local/mysql/data          #binlog日誌的存放路徑
16 user=mha                                                       #管理賬戶
17 password=123123                                            #管理賬戶密碼
18 ping_interval=2                                                #存貨檢查的間隔時間
19 repl_user=rep                                                  #主從複製的授權賬戶
20 repl_password=123123                                      #主從複製的授權賬戶密碼
21 ssh_user=root                                                  #用於ssh連線的賬戶
22 
23 [server1]
24 hostname=192.168.200.130
25 port=3306
26 
27 [server2]
28 #candidate_master=1                                #註釋掉,後面解釋
29 #check_repl_delay=0                                 #註釋掉,後面解釋
30 hostname=192.168.200.144
31 port=3306
32 
33 [server3]
34 hostname=192.168.200.145
35 port=3306
36                                                                                                                                     

 ####解釋

引數:candidate_master=1
解釋:設定為候選master,如果設定該引數以後,發生主從切換以後會將此從庫提升為主庫,即使這個主庫不是叢集中事件最新的slave
引數:check_repl_delay=0
解釋:預設情況下如果一個slave落後master 100M的relay logs 的話,MHA將不會選擇該slave作為一個新的master,因為對於這個slave的恢復需要花費很長時間,通過設定check_repl_delay=0,MHA觸發切換在選擇一個新的master的時候將會忽略複製延時,這個引數對於設定了candidate_master=1的主機非常有用,因為這個候選主在切換的過程中一定是新的master

  5.3 配置ssh信任(3臺虛擬機器)

 1 #建立金鑰對
 2 [[email protected] ~]# ssh-keygen -t dsa -P "" -f ~/.ssh/id_dsa >/dev/null 2>&1
 3 
 4 #傳送MySQL-SlaveB 公鑰,包括自己
 5 [[email protected]  ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.130
 6 [[email protected]  ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.144
 7 [[email protected]  ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.145
 8 
 9 #傳送MySQL-SlaveA公鑰,包括自己
10 [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.130
11 [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.144
12 [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.145
13 
14 #傳送MySQL-Master公鑰,包括自己
15 [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.130
16 [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.144
17 [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected]192.168.200.145

  5.4 啟動測試

  5.4.1 ssh檢查測試

 1 [[email protected] ~]# masterha_check_ssh --conf=/etc/mha/mhal.cnf 
 2 Fri Nov 23 09:54:24 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
 3 Fri Nov 23 09:54:24 2018 - [info] Reading application default configuration from /etc/mha/mhal.cnf..
 4 Fri Nov 23 09:54:24 2018 - [info] Reading server configuration from /etc/mha/mhal.cnf..
 5 Fri Nov 23 09:54:24 2018 - [info] Starting SSH connection tests..
 6 Fri Nov 23 09:54:25 2018 - [debug] 
 7 Fri Nov 23 09:54:24 2018 - [debug]  Connecting via SSH from [email protected]192.168.200.130(192.168.200.130:22) to [email protected]192.168.200.144(192.168.200.144:22)..
 8 Address 192.168.200.130 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
 9 Fri Nov 23 09:54:24 2018 - [debug]   ok.
10 Fri Nov 23 09:54:24 2018 - [debug]  Connecting via SSH from [email protected]192.168.200.130(192.168.200.130:22) to [email protected]192.168.200.145(192.168.200.145:22)..
11 Address 192.168.200.130 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
12 Address 192.168.200.145 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
13 Fri Nov 23 09:54:25 2018 - [debug]   ok.
14 Fri Nov 23 09:54:26 2018 - [debug] 
15 Fri Nov 23 09:54:25 2018 - [debug]  Connecting via SSH from [email protected]192.168.200.144(192.168.200.144:22) to [email protected]192.168.200.130(192.168.200.130:22)..
16 Address 192.168.200.144 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
17 Address 192.168.200.130 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
18 Fri Nov 23 09:54:25 2018 - [debug]   ok.
19 Fri Nov 23 09:54:25 2018 - [debug]  Connecting via SSH from [email protected]192.168.200.144(192.168.200.144:22) to [email protected]192.168.200.145(192.168.200.145:22)..
20 Address 192.168.200.144 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
21 Address 192.168.200.145 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
22 Fri Nov 23 09:54:25 2018 - [debug]   ok.
23 Fri Nov 23 09:54:27 2018 - [debug] 
24 Fri Nov 23 09:54:25 2018 - [debug]  Connecting via SSH from [email protected]192.168.200.145(192.168.200.145:22) to [email protected]192.168.200.130(192.168.200.130:22)..
25 Address 192.168.200.145 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
26 Address 192.168.200.130 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
27 Fri Nov 23 09:54:26 2018 - [debug]   ok.
28 Fri Nov 23 09:54:26 2018 - [debug]  Connecting via SSH from [email protected]192.168.200.145(192.168.200.145:22) to [email protected]192.168.200.144(192.168.200.144:22)..
29 Address 192.168.200.145 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
30 Address 192.168.200.144 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
31 Fri Nov 23 09:54:26 2018 - [debug]   ok.
32 Fri Nov 23 09:54:27 2018 - [info] All SSH connection tests passed successfully.

  最後出現successfully表示成功

  5.4.2 主從複製檢測