主頁 >  其他 > 作業5

作業5

2020-10-19 20:41:14 其他

1、如果主節點已經運行了一段時間,且有大量資料時,如何配置并啟動slave節點(寫出操作步驟)

  • 1、通過備份恢復資料至從服務器

    1、在主服務器完全備份
    mysqldump -A -F --single-transaction --master-data=1 >
    /backup/fullbackup.sql
    
    2、將備份的資料拷貝到新的從節點服務器相關目錄下
    
  • 2、復制起始位置為備份時,二進制日志檔案及其POS

    1、從節點服務器進行相關配置
    注意:先查看完全備份的二進制檔案的節點位置,從完全備份的位置之后開始復制
    
    2、在從節點進行完全備份恢復
    
    3、從節點啟動slave服務
    

2、當master服務器宕機,提升一個slave成為新的master(寫出操作步驟)

  • 1、找到哪個從節點的資料庫是最新,讓它成為新master

  • 2、新master修改組態檔,關閉read-only配置

    vim /etc/my.cnf.d/mariadb-server.cnf
    read-only=OFF
    
  • 3、清除舊的master復制資訊

    # 登錄MySQL
    set global read_only=off;
    stop slave;
    reset slave all;
    
  • 4、在新master上完全備份

    • mysqldump -A --single-transaction --master-data=1 -F >
      backup.sql
      
    • 分析舊的master 的二進制日志,將未同步到至新master的二進制日志匯出來,恢復到新master,盡可能 恢復資料

  • 5、其它所有 slave 重新還原資料庫,指向新的master

    • 注意:同步恢復資料時,暫時停用二進制檔案

      set sql_log_bin=off;
      

3、通過 MHA 0.58 搭建一個資料庫集群結構

MySQL8.0-基于MHA的MySQL高可用架構搭建

在這里插入圖片描述

(1)從宕機崩潰的master保存二進制日志事件(binlog events);

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

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

(4)應用從master保存的二進制日志事件(binlog events);

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

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

相關命令

# 檢查ssh連接
[root@centos771 ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf

# 檢查MySQL復制狀況
[root@centos771 ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf 

# 啟動MHA
[root@centos771 ~]# masterha_manager --conf=/etc/masterha/app1.cnf

# 檢測當前MHA運行狀態
[root@centos771 ~]# masterha_check_status --conf=/etc/masterha/app1.cnf 

# 啟動MHA
[root@centos771 ~]# masterha_manager --conf=/etc/masterha/app1.cnf

# 檢測master是否gangji
[root@centos771 ~]# masterha_master_monitor --conf=/etc/masterha/app1.cnf

# 手動切換master
[root@centos771 ~]# masterha_master_switch  --conf=/etc/masterha/app1.cnf --master_state=alive --new_master_host=10.0.0.80 --new_master_port=3306 --orig_master_is_new_slave --running_updates_limit=10000


注意:MHA目前不支持mariadb資料庫

實驗環境:虛擬機四臺

SQL檔案:hellodb.sql

  • master:centos80

    • ip:10.0.0.80

    • MySQL8.0

  • slave1(備用master):centos81

    • ip:10.0.0.81

    • MySQL8.0

  • slave2:centos82

    • ip:10.0.0.82

    • MySQL8.0

  • slave3(MHA):centos77

    • ip:10.0.0.77
    • MySQL8.0

前期準備

# 關閉防火墻,關閉selinux
[root@80 ~]# systemctl disable --now firewalld
[root@80 ~]# sed -ri '/^SELINUX=/s/(^SELINUX=)(.*)/\1disabled/' /etc/selinux/config

# 安裝MySQL8.0
[root@80 ~]# yum -y install mysql-server
[root@80 ~]# systemctl enable mysqld
[root@80 ~]# systemctl start mysqld

1 首先配置好,基于GTID的主從半同步復制(一主兩從)

master

[root@hah ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid

server_id=80
gtid_mode=ON
enforce_gtid_consistency=ON
log_bin
log_slave_updates=ON

[root@hah ~]# systemctl restart mysqld


slave1

[root@81 ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid

server_id=81
gtid_mode=ON
enforce_gtid_consistency=ON
log_bin
log_slave_updates=ON

[root@81 ~]# systemctl restart mysqld

slave2

[root@82 ~]# vim /etc/my.cnf.d/mysql-server.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid

server_id=82
gtid_mode=ON
enforce_gtid_consistency=ON
log_bin
log_slave_updates=ON

[root@82 ~]# systemctl restart mysqld

master

# 創建復制用戶并授權
mysql> create user centos@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.17 sec)

mysql> grant replication slave on *.* to 'centos'@'10.0.0.%';
Query OK, 0 rows affected (0.06 sec)

# 安裝插件
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.04 sec)

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.06 sec)

mysql> set global rpl_semi_sync_master_enabled=1;
Query OK, 0 rows affected (0.00 sec)

mysql> set global rpl_semi_sync_master_timeout=3000;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%rpl%';
+-------------------------------------------+------------+
| Variable_name                             | Value      |
+-------------------------------------------+------------+
| rpl_read_size                             | 8192       |
| rpl_semi_sync_master_enabled              | ON         |
| rpl_semi_sync_master_timeout              | 3000       |
| rpl_semi_sync_master_trace_level          | 32         |
| rpl_semi_sync_master_wait_for_slave_count | 1          |
| rpl_semi_sync_master_wait_no_slave        | ON         |
| rpl_semi_sync_master_wait_point           | AFTER_SYNC |
| rpl_semi_sync_slave_enabled               | OFF        |
| rpl_semi_sync_slave_trace_level           | 32         |
| rpl_stop_slave_timeout                    | 31536000   |
+-------------------------------------------+------------+
10 rows in set (0.01 sec)

slave1

# 復制執行緒
mysql> change master to master_host='10.0.0.80',master_user='centos',master_password='123456',master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

# 安裝插件
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.08 sec)

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.10 sec)

mysql> set global rpl_semi_sync_slave_enabled=1;
Query OK, 0 rows affected (0.00 sec)

# 啟動從執行緒
mysql> start slave;
Query OK, 0 rows affected (0.10 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.80
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: hah-bin.000003
          Read_Master_Log_Pos: 672
               Relay_Log_File: 81-relay-bin.000002
                Relay_Log_Pos: 882
        Relay_Master_Log_File: hah-bin.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: 672
              Relay_Log_Space: 1087
              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: 80
                  Master_UUID: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-2
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-2
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

slave2

mysql> change master to master_host='10.0.0.80',master_user='centos',master_password='123456',master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.01 sec)

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.10 sec)

mysql> set global rpl_semi_sync_slave_enabled=1;
Query OK, 0 rows affected (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.05 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.80
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: hah-bin.000003
          Read_Master_Log_Pos: 672
               Relay_Log_File: 82-relay-bin.000002
                Relay_Log_Pos: 882
        Relay_Master_Log_File: hah-bin.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: 672
              Relay_Log_Space: 1087
              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: 80
                  Master_UUID: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-2
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-2
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

測驗主從復制

# master
mysql> create database student;
Query OK, 1 row affected (0.02 sec)

# slave1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| student            |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

# slave2
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| student            |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

2 配置ssh免密登錄

1、生成ssh登錄密鑰

# MAH
[root@centos771 ~]# 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:aEKIhERoMc+c7LhcmHHfz04TtkXZ5mvexBq7y/g2QPE root@83
The key's randomart image is:
+---[RSA 2048]----+
|=*.              |
|+o*..      .o    |
|o..B.      ooo   |
|  B.. ..  ..oE   |
| + o..o.So.. .   |
|. o  o  + +.  o  |
| o       *  .+ o |
|        o . =o*  |
|         . .oO+. |
+----[SHA256]-----+
[root@centos771 ~]# ssh-copy-id 10.0.0.71


# 生成公鑰和私鑰發送到server1,2,3上,使之互相之間可以進行免密登錄
[root@centos771 ~]# scp -r .ssh 10.0.0.80:/root/
[root@centos771 ~]# scp -r .ssh 10.0.0.81:/root/
[root@centos771 ~]# scp -r .ssh 10.0.0.82:/root/

3 配置MHA

相關下載鏈接

  • https://github.com/yoshinorim/mha4mysql-node/releases/download/v0.58/mha4mysql-node-0.58-0.el7.centos.noarch.rpm
  • https://github.com/yoshinorim/mha4mysql-manager/releases/download/v0.58/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
  • https://github.com/yoshinorim/mha4mysql-manager/releases/download/v0.58/mha4mysql-manager-0.58.tar.gz
[root@centos771 ~]# yum -y install mha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@centos771 ~]# yum -y install mha4mysql-manager-0.58-0.el7.centos.noarch.rpm 

# 將mha4mysql-node發送到另外三臺主機
[root@centos771 ~]# rsync /data/mha4mysql-node-0.58-0.el7.centos.noarch.rpm 10.0.0.80:/root/
[root@centos771 ~]# rsync /data/mha4mysql-node-0.58-0.el7.centos.noarch.rpm 10.0.0.81:/root/
[root@centos771 ~]# rsync /data/mha4mysql-node-0.58-0.el7.centos.noarch.rpm 10.0.0.82:/root/

# master,slave1,slave2 安裝node

撰寫組態檔

[root@centos771 ~]# mkdir /etc/masterha/
[root@centos771 ~]# vim /etc/masterha/app.cnf
[server default]
manager_workdir=/etc/masterha
manager_log=/var/log/masterha.log
master_binlog_dir=/var/lib/mysql
user=root
password=123456
ping_interval=1
remote_workdir=/tmp
repl_password=123456
repl_user=centos
ssh_user=root

[server1]
hostname=10.0.0.80
port=3306

[server2]
hostname=10.0.0.81
port=3306
candidate_master=1
check_repl_delay=0

[server3]
hostname=10.0.0.82
port=3306
no_master=1

測驗連接

[root@centos771 ~]# masterha_check_ssh --conf=/etc/masterha/app.cnf
Thu Oct 15 17:17:59 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Oct 15 17:17:59 2020 - [info] Reading application default configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:17:59 2020 - [info] Reading server configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:17:59 2020 - [info] Starting SSH connection tests..
Thu Oct 15 17:18:00 2020 - [debug] 
Thu Oct 15 17:17:59 2020 - [debug]  Connecting via SSH from root@10.0.0.80(10.0.0.80:22) to root@10.0.0.81(10.0.0.81:22)..
Thu Oct 15 17:17:59 2020 - [debug]   ok.
Thu Oct 15 17:17:59 2020 - [debug]  Connecting via SSH from root@10.0.0.80(10.0.0.80:22) to root@10.0.0.82(10.0.0.82:22)..
Thu Oct 15 17:18:00 2020 - [debug]   ok.
Thu Oct 15 17:18:01 2020 - [debug] 
Thu Oct 15 17:17:59 2020 - [debug]  Connecting via SSH from root@10.0.0.81(10.0.0.81:22) to root@10.0.0.80(10.0.0.80:22)..
Thu Oct 15 17:18:00 2020 - [debug]   ok.
Thu Oct 15 17:18:00 2020 - [debug]  Connecting via SSH from root@10.0.0.81(10.0.0.81:22) to root@10.0.0.82(10.0.0.82:22)..
Thu Oct 15 17:18:01 2020 - [debug]   ok.
Thu Oct 15 17:18:01 2020 - [debug] 
Thu Oct 15 17:18:00 2020 - [debug]  Connecting via SSH from root@10.0.0.82(10.0.0.82:22) to root@10.0.0.80(10.0.0.80:22)..
Thu Oct 15 17:18:00 2020 - [debug]   ok.
Thu Oct 15 17:18:00 2020 - [debug]  Connecting via SSH from root@10.0.0.82(10.0.0.82:22) to root@10.0.0.81(10.0.0.81:22)..
Thu Oct 15 17:18:01 2020 - [debug]   ok.
Thu Oct 15 17:18:01 2020 - [info] All SSH connection tests passed successfully.

master

# 添加授權
mysql> create user root@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all on *.* to 'root'@'10.0.0.%';
Query OK, 0 rows affected (0.05 sec)

slave

#slave1
mysql> set global read_only=1;
Query OK, 0 rows affected (0.01 sec)

#slave2
mysql> set global read_only=1;
Query OK, 0 rows affected (0.01 sec)

檢查整個復制環境狀況(健康檢查)

[root@centos771 ~]# masterha_check_repl --conf=/etc/masterha/app.cnf
Thu Oct 15 17:27:13 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Oct 15 17:27:13 2020 - [info] Reading application default configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:27:13 2020 - [info] Reading server configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:27:13 2020 - [info] MHA::MasterMonitor version 0.58.
Thu Oct 15 17:27:18 2020 - [info] GTID failover mode = 1
Thu Oct 15 17:27:18 2020 - [info] Dead Servers:
Thu Oct 15 17:27:18 2020 - [info] Alive Servers:
Thu Oct 15 17:27:18 2020 - [info]   10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:27:18 2020 - [info]   10.0.0.81(10.0.0.81:3306)
Thu Oct 15 17:27:18 2020 - [info]   10.0.0.82(10.0.0.82:3306)
Thu Oct 15 17:27:18 2020 - [info] Alive Slaves:
Thu Oct 15 17:27:18 2020 - [info]   10.0.0.81(10.0.0.81:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:27:18 2020 - [info]     GTID ON
Thu Oct 15 17:27:18 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:27:18 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Thu Oct 15 17:27:18 2020 - [info]   10.0.0.82(10.0.0.82:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:27:18 2020 - [info]     GTID ON
Thu Oct 15 17:27:18 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:27:18 2020 - [info]     Not candidate for the new Master (no_master is set)
Thu Oct 15 17:27:18 2020 - [info] Current Alive Master: 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:27:18 2020 - [info] Checking slave configurations..
Thu Oct 15 17:27:18 2020 - [info] Checking replication filtering settings..
Thu Oct 15 17:27:18 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Thu Oct 15 17:27:18 2020 - [info]  Replication filtering check ok.
Thu Oct 15 17:27:18 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Thu Oct 15 17:27:18 2020 - [info] Checking SSH publickey authentication settings on the current master..
Thu Oct 15 17:27:19 2020 - [info] HealthCheck: SSH to 10.0.0.80 is reachable.
Thu Oct 15 17:27:19 2020 - [info] 
10.0.0.80(10.0.0.80:3306) (current master)
 +--10.0.0.81(10.0.0.81:3306)
 +--10.0.0.82(10.0.0.82:3306)

Thu Oct 15 17:27:19 2020 - [info] Checking replication health on 10.0.0.81..
Thu Oct 15 17:27:19 2020 - [info]  ok.
Thu Oct 15 17:27:19 2020 - [info] Checking replication health on 10.0.0.82..
Thu Oct 15 17:27:19 2020 - [info]  ok.
Thu Oct 15 17:27:19 2020 - [warning] master_ip_failover_script is not defined.
Thu Oct 15 17:27:19 2020 - [warning] shutdown_script is not defined.
Thu Oct 15 17:27:19 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

測驗

手動同步

(1)手動關閉server1(master)

[root@hah ~]# systemctl stop mysqld

(2)在server4(mha)上將master從server1手動同步到server1上

[root@centos771 ~]# masterha_master_switch --master_state=dead --conf=/etc/masterha/app.cnf --dead_master_ip=10.0.0.80 --dead_master_host=10.0.0.80 --dead_master_port=3306 --new_master_host=10.0.0.81 --new_master_port=3306

Thu Oct 15 17:31:29 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Oct 15 17:31:29 2020 - [info] Reading application default configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:31:29 2020 - [info] Reading server configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:31:29 2020 - [info] MHA::MasterFailover version 0.58.
Thu Oct 15 17:31:29 2020 - [info] Starting master failover.
Thu Oct 15 17:31:29 2020 - [info] 
Thu Oct 15 17:31:29 2020 - [info] * Phase 1: Configuration Check Phase..
Thu Oct 15 17:31:29 2020 - [info] 
Thu Oct 15 17:31:30 2020 - [info] GTID failover mode = 1
Thu Oct 15 17:31:30 2020 - [info] Dead Servers:
Thu Oct 15 17:31:30 2020 - [info]   10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:31:30 2020 - [info] Checking master reachability via MySQL(double check)...
Thu Oct 15 17:31:30 2020 - [info]  ok.
Thu Oct 15 17:31:30 2020 - [info] Alive Servers:
Thu Oct 15 17:31:30 2020 - [info]   10.0.0.81(10.0.0.81:3306)
Thu Oct 15 17:31:30 2020 - [info]   10.0.0.82(10.0.0.82:3306)
Thu Oct 15 17:31:30 2020 - [info] Alive Slaves:
Thu Oct 15 17:31:30 2020 - [info]   10.0.0.81(10.0.0.81:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:31:30 2020 - [info]     GTID ON
Thu Oct 15 17:31:30 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:31:30 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Thu Oct 15 17:31:30 2020 - [info]   10.0.0.82(10.0.0.82:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:31:30 2020 - [info]     GTID ON
Thu Oct 15 17:31:30 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:31:30 2020 - [info]     Not candidate for the new Master (no_master is set)
Master 10.0.0.80(10.0.0.80:3306) is dead. Proceed? (yes/NO): yes
Thu Oct 15 17:31:34 2020 - [info] Starting GTID based failover.
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] ** Phase 1: Configuration Check Phase completed.
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] * Phase 2: Dead Master Shutdown Phase..
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] HealthCheck: SSH to 10.0.0.80 is reachable.
Thu Oct 15 17:31:34 2020 - [error][/usr/share/perl5/vendor_perl/MHA/ManagerUtil.pm, ln122] Got error when getting node version. Error:
Thu Oct 15 17:31:34 2020 - [error][/usr/share/perl5/vendor_perl/MHA/ManagerUtil.pm, ln123] 
bash: apply_diff_relay_logs: command not found
Thu Oct 15 17:31:34 2020 - [warning] Failed to get MHA Node version from dead master. Guessing that SSH is NOT reachable.
Thu Oct 15 17:31:34 2020 - [info] Forcing shutdown so that applications never connect to the current master..
Thu Oct 15 17:31:34 2020 - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
Thu Oct 15 17:31:34 2020 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Thu Oct 15 17:31:34 2020 - [info] * Phase 2: Dead Master Shutdown Phase completed.
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] * Phase 3: Master Recovery Phase..
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] The latest binary log file/position on all slaves is hah-bin.000003:1372
Thu Oct 15 17:31:34 2020 - [info] Retrieved Gtid Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
Thu Oct 15 17:31:34 2020 - [info] Latest slaves (Slaves that received relay log files to the latest):
Thu Oct 15 17:31:34 2020 - [info]   10.0.0.81(10.0.0.81:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:31:34 2020 - [info]     GTID ON
Thu Oct 15 17:31:34 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:31:34 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Thu Oct 15 17:31:34 2020 - [info]   10.0.0.82(10.0.0.82:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:31:34 2020 - [info]     GTID ON
Thu Oct 15 17:31:34 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:31:34 2020 - [info]     Not candidate for the new Master (no_master is set)
Thu Oct 15 17:31:34 2020 - [info] The oldest binary log file/position on all slaves is hah-bin.000003:1372
Thu Oct 15 17:31:34 2020 - [info] Retrieved Gtid Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
Thu Oct 15 17:31:34 2020 - [info] Oldest slaves:
Thu Oct 15 17:31:34 2020 - [info]   10.0.0.81(10.0.0.81:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:31:34 2020 - [info]     GTID ON
Thu Oct 15 17:31:34 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:31:34 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Thu Oct 15 17:31:34 2020 - [info]   10.0.0.82(10.0.0.82:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:31:34 2020 - [info]     GTID ON
Thu Oct 15 17:31:34 2020 - [info]     Replicating from 10.0.0.80(10.0.0.80:3306)
Thu Oct 15 17:31:34 2020 - [info]     Not candidate for the new Master (no_master is set)
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] * Phase 3.3: Determining New Master Phase..
Thu Oct 15 17:31:34 2020 - [info] 
Thu Oct 15 17:31:34 2020 - [info] 10.0.0.81 can be new master.
Thu Oct 15 17:31:34 2020 - [info] New master is 10.0.0.81(10.0.0.81:3306)
Thu Oct 15 17:31:34 2020 - [info] Starting master failover..
Thu Oct 15 17:31:34 2020 - [info] 
From:
10.0.0.80(10.0.0.80:3306) (current master)
 +--10.0.0.81(10.0.0.81:3306)
 +--10.0.0.82(10.0.0.82:3306)

To:
10.0.0.81(10.0.0.81:3306) (new master)
 +--10.0.0.82(10.0.0.82:3306)

Starting master switch from 10.0.0.80(10.0.0.80:3306) to 10.0.0.81(10.0.0.81:3306)? (yes/NO): yes
Thu Oct 15 17:31:41 2020 - [info] New master decided manually is 10.0.0.81(10.0.0.81:3306)
Thu Oct 15 17:31:41 2020 - [info] 
Thu Oct 15 17:31:41 2020 - [info] * Phase 3.3: New Master Recovery Phase..
Thu Oct 15 17:31:41 2020 - [info] 
Thu Oct 15 17:31:41 2020 - [info]  Waiting all logs to be applied.. 
Thu Oct 15 17:31:41 2020 - [info]   done.
Thu Oct 15 17:31:41 2020 - [info] Getting new master's binlog name and position..
Thu Oct 15 17:31:41 2020 - [info]  81-bin.000002:1407
Thu Oct 15 17:31:41 2020 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='10.0.0.81', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='centos', MASTER_PASSWORD='xxx';
Thu Oct 15 17:31:41 2020 - [info] Master Recovery succeeded. File:Pos:Exec_Gtid_Set: 81-bin.000002, 1407, 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
Thu Oct 15 17:31:41 2020 - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
Thu Oct 15 17:31:41 2020 - [info] Setting read_only=0 on 10.0.0.81(10.0.0.81:3306)..
Thu Oct 15 17:31:41 2020 - [info]  ok.
Thu Oct 15 17:31:41 2020 - [info] ** Finished master recovery successfully.
Thu Oct 15 17:31:41 2020 - [info] * Phase 3: Master Recovery Phase completed.
Thu Oct 15 17:31:41 2020 - [info] 
Thu Oct 15 17:31:41 2020 - [info] * Phase 4: Slaves Recovery Phase..
Thu Oct 15 17:31:41 2020 - [info] 
Thu Oct 15 17:31:41 2020 - [info] 
Thu Oct 15 17:31:41 2020 - [info] * Phase 4.1: Starting Slaves in parallel..
Thu Oct 15 17:31:41 2020 - [info] 
Thu Oct 15 17:31:41 2020 - [info] -- Slave recovery on host 10.0.0.82(10.0.0.82:3306) started, pid: 17318. Check tmp log /etc/masterha/10.0.0.82_3306_20201015173129.log if it takes time..
Thu Oct 15 17:31:43 2020 - [info] 
Thu Oct 15 17:31:43 2020 - [info] Log messages from 10.0.0.82 ...
Thu Oct 15 17:31:43 2020 - [info] 
Thu Oct 15 17:31:41 2020 - [info]  Resetting slave 10.0.0.82(10.0.0.82:3306) and starting replication from the new master 10.0.0.81(10.0.0.81:3306)..
Thu Oct 15 17:31:42 2020 - [info]  Executed CHANGE MASTER.
Thu Oct 15 17:31:43 2020 - [info]  Slave started.
Thu Oct 15 17:31:43 2020 - [info]  gtid_wait(2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5) completed on 10.0.0.82(10.0.0.82:3306). Executed 0 events.
Thu Oct 15 17:31:43 2020 - [info] End of log messages from 10.0.0.82.
Thu Oct 15 17:31:43 2020 - [info] -- Slave on host 10.0.0.82(10.0.0.82:3306) started.
Thu Oct 15 17:31:43 2020 - [info] All new slave servers recovered successfully.
Thu Oct 15 17:31:43 2020 - [info] 
Thu Oct 15 17:31:43 2020 - [info] * Phase 5: New master cleanup phase..
Thu Oct 15 17:31:43 2020 - [info] 
Thu Oct 15 17:31:43 2020 - [info] Resetting slave info on the new master..
Thu Oct 15 17:31:44 2020 - [info]  10.0.0.81: Resetting slave info succeeded.
Thu Oct 15 17:31:44 2020 - [info] Master failover to 10.0.0.81(10.0.0.81:3306) completed successfully.
Thu Oct 15 17:31:44 2020 - [info] 

----- Failover Report -----

app: MySQL Master failover 10.0.0.80(10.0.0.80:3306) to 10.0.0.81(10.0.0.81:3306) succeeded

Master 10.0.0.80(10.0.0.80:3306) is down!

Check MHA Manager logs at centos771 for details.

Started manual(interactive) failover.
Selected 10.0.0.81(10.0.0.81:3306) as a new master.
10.0.0.81(10.0.0.81:3306): OK: Applying all logs succeeded.
10.0.0.82(10.0.0.82:3306): OK: Slave started, replicating from 10.0.0.81(10.0.0.81:3306)
10.0.0.81(10.0.0.81:3306): Resetting slave info succeeded.
Master failover to 10.0.0.81(10.0.0.81:3306) completed successfully.

(3)測驗在server1上查看slave狀態為空,server2上的master顯示是server2,說明手動轉換成功
server2:

mysql> show slave status\G
Empty set (0.00 sec)

server3:

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.81
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: 81-bin.000002
          Read_Master_Log_Pos: 1407
               Relay_Log_File: 82-relay-bin.000002
                Relay_Log_Pos: 407
        Relay_Master_Log_File: 81-bin.000002
             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: 1407
              Relay_Log_Space: 612
              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: 81
                  Master_UUID: 711d79aa-0eb8-11eb-b3dc-000c299dcf4d
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

(4)然后打開server1的mysqld,在sever1上重新添加master,查看slave的狀態,顯示master是server2,切換成功

[root@hah ~]# systemctl start mysqld 
mysql> change master to master_host='10.0.0.81',master_port=3306,master_auto_position=1,master_user='centos',master_password='123456';
Query OK, 0 rows affected, 2 warnings (0.20 sec)

mysql> start slave;
Query OK, 0 rows affected (0.03 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.81
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: 81-bin.000002
          Read_Master_Log_Pos: 1407
               Relay_Log_File: hah-relay-bin.000002
                Relay_Log_Pos: 407
        Relay_Master_Log_File: 81-bin.000002
             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: 1407
              Relay_Log_Space: 613
              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: 81
                  Master_UUID: 711d79aa-0eb8-11eb-b3dc-000c299dcf4d
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

兩個主備master都開啟

(1)首先洗掉server4的app1.failover.complete,否則再次轉換不能成功

[root@centos771 ~]# ll /etc/masterha/
total 4
-rw-r--r--. 1 root root 444 Oct 15 17:00 app.cnf
-rw-r--r--. 1 root root   0 Oct 15 17:31 app.failover.complete
[root@centos771 ~]# rm -rf /etc/masterha/app.failover.complete   

(2)手動切換新的master——>server1

[root@centos771 ~]# masterha_master_switch  --conf=/etc/masterha/app.cnf --master_state=alive --new_master_host=10.0.0.80 --new_master_port=3306 --orig_master_is_new_slave --running_updates_limit=10000

Thu Oct 15 17:40:52 2020 - [info] MHA::MasterRotate version 0.58.
Thu Oct 15 17:40:52 2020 - [info] Starting online master switch..
Thu Oct 15 17:40:52 2020 - [info] 
Thu Oct 15 17:40:52 2020 - [info] * Phase 1: Configuration Check Phase..
Thu Oct 15 17:40:52 2020 - [info] 
Thu Oct 15 17:40:52 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Oct 15 17:40:52 2020 - [info] Reading application default configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:40:52 2020 - [info] Reading server configuration from /etc/masterha/app.cnf..
Thu Oct 15 17:40:53 2020 - [info] GTID failover mode = 1
Thu Oct 15 17:40:53 2020 - [info] Current Alive Master: 10.0.0.81(10.0.0.81:3306)
Thu Oct 15 17:40:53 2020 - [info] Alive Slaves:
Thu Oct 15 17:40:53 2020 - [info]   10.0.0.80(10.0.0.80:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:40:53 2020 - [info]     GTID ON
Thu Oct 15 17:40:53 2020 - [info]     Replicating from 10.0.0.81(10.0.0.81:3306)
Thu Oct 15 17:40:53 2020 - [info]   10.0.0.82(10.0.0.82:3306)  Version=8.0.13 (oldest major version between slaves) log-bin:enabled
Thu Oct 15 17:40:53 2020 - [info]     GTID ON
Thu Oct 15 17:40:53 2020 - [info]     Replicating from 10.0.0.81(10.0.0.81:3306)
Thu Oct 15 17:40:53 2020 - [info]     Not candidate for the new Master (no_master is set)

It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 10.0.0.81(10.0.0.81:3306)? (YES/no): yes
Thu Oct 15 17:40:56 2020 - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
Thu Oct 15 17:40:56 2020 - [info]  ok.
Thu Oct 15 17:40:56 2020 - [info] Checking MHA is not monitoring or doing failover..
Thu Oct 15 17:40:56 2020 - [info] Checking replication health on 10.0.0.80..
Thu Oct 15 17:40:56 2020 - [info]  ok.
Thu Oct 15 17:40:56 2020 - [info] Checking replication health on 10.0.0.82..
Thu Oct 15 17:40:56 2020 - [info]  ok.
Thu Oct 15 17:40:56 2020 - [info] 10.0.0.80 can be new master.
Thu Oct 15 17:40:56 2020 - [info] 
From:
10.0.0.81(10.0.0.81:3306) (current master)
 +--10.0.0.80(10.0.0.80:3306)
 +--10.0.0.82(10.0.0.82:3306)

To:
10.0.0.80(10.0.0.80:3306) (new master)
 +--10.0.0.82(10.0.0.82:3306)
 +--10.0.0.81(10.0.0.81:3306)

Starting master switch from 10.0.0.81(10.0.0.81:3306) to 10.0.0.80(10.0.0.80:3306)? (yes/NO): yes
Thu Oct 15 17:40:59 2020 - [info] Checking whether 10.0.0.80(10.0.0.80:3306) is ok for the new master..
Thu Oct 15 17:40:59 2020 - [info]  ok.
Thu Oct 15 17:40:59 2020 - [info] 10.0.0.81(10.0.0.81:3306): SHOW SLAVE STATUS returned empty result. To check replication filtering rules, temporarily executing CHANGE MASTER to a dummy host.
Thu Oct 15 17:40:59 2020 - [info] 10.0.0.81(10.0.0.81:3306): Resetting slave pointing to the dummy host.
Thu Oct 15 17:40:59 2020 - [info] ** Phase 1: Configuration Check Phase completed.
Thu Oct 15 17:40:59 2020 - [info] 
Thu Oct 15 17:40:59 2020 - [info] * Phase 2: Rejecting updates Phase..
Thu Oct 15 17:40:59 2020 - [info] 
master_ip_online_change_script is not defined. If you do not disable writes on the current master manually, applications keep writing on the current master. Is it ok to proceed? (yes/NO): yes
Thu Oct 15 17:41:02 2020 - [info] Locking all tables on the orig master to reject updates from everybody (including root):
Thu Oct 15 17:41:02 2020 - [info] Executing FLUSH TABLES WITH READ LOCK..
Thu Oct 15 17:41:02 2020 - [info]  ok.
Thu Oct 15 17:41:02 2020 - [info] Orig master binlog:pos is 81-bin.000002:1407.
Thu Oct 15 17:41:02 2020 - [info]  Waiting to execute all relay logs on 10.0.0.80(10.0.0.80:3306)..
Thu Oct 15 17:41:02 2020 - [info]  master_pos_wait(81-bin.000002:1407) completed on 10.0.0.80(10.0.0.80:3306). Executed 0 events.
Thu Oct 15 17:41:02 2020 - [info]   done.
Thu Oct 15 17:41:02 2020 - [info] Getting new master's binlog name and position..
Thu Oct 15 17:41:02 2020 - [info]  hah-bin.000004:195
Thu Oct 15 17:41:02 2020 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='10.0.0.80', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='centos', MASTER_PASSWORD='xxx';
Thu Oct 15 17:41:02 2020 - [info] 
Thu Oct 15 17:41:02 2020 - [info] * Switching slaves in parallel..
Thu Oct 15 17:41:02 2020 - [info] 
Thu Oct 15 17:41:02 2020 - [info] -- Slave switch on host 10.0.0.82(10.0.0.82:3306) started, pid: 17333
Thu Oct 15 17:41:02 2020 - [info] 
Thu Oct 15 17:41:04 2020 - [info] Log messages from 10.0.0.82 ...
Thu Oct 15 17:41:04 2020 - [info] 
Thu Oct 15 17:41:02 2020 - [info]  Waiting to execute all relay logs on 10.0.0.82(10.0.0.82:3306)..
Thu Oct 15 17:41:02 2020 - [info]  master_pos_wait(81-bin.000002:1407) completed on 10.0.0.82(10.0.0.82:3306). Executed 0 events.
Thu Oct 15 17:41:02 2020 - [info]   done.
Thu Oct 15 17:41:02 2020 - [info]  Resetting slave 10.0.0.82(10.0.0.82:3306) and starting replication from the new master 10.0.0.80(10.0.0.80:3306)..
Thu Oct 15 17:41:02 2020 - [info]  Executed CHANGE MASTER.
Thu Oct 15 17:41:03 2020 - [info]  Slave started.
Thu Oct 15 17:41:04 2020 - [info] End of log messages from 10.0.0.82 ...
Thu Oct 15 17:41:04 2020 - [info] 
Thu Oct 15 17:41:04 2020 - [info] -- Slave switch on host 10.0.0.82(10.0.0.82:3306) succeeded.
Thu Oct 15 17:41:04 2020 - [info] Unlocking all tables on the orig master:
Thu Oct 15 17:41:04 2020 - [info] Executing UNLOCK TABLES..
Thu Oct 15 17:41:04 2020 - [info]  ok.
Thu Oct 15 17:41:04 2020 - [info] Starting orig master as a new slave..
Thu Oct 15 17:41:04 2020 - [info]  Resetting slave 10.0.0.81(10.0.0.81:3306) and starting replication from the new master 10.0.0.80(10.0.0.80:3306)..
Thu Oct 15 17:41:04 2020 - [info]  Executed CHANGE MASTER.
Thu Oct 15 17:41:05 2020 - [info]  Slave started.
Thu Oct 15 17:41:05 2020 - [info] All new slave servers switched successfully.
Thu Oct 15 17:41:05 2020 - [info] 
Thu Oct 15 17:41:05 2020 - [info] * Phase 5: New master cleanup phase..
Thu Oct 15 17:41:05 2020 - [info] 
Thu Oct 15 17:41:05 2020 - [info]  10.0.0.80: Resetting slave info succeeded.
Thu Oct 15 17:41:05 2020 - [info] Switching master to 10.0.0.80(10.0.0.80:3306) completed successfully.

(3)master測驗結果顯示如下(這次server2不用重新添加master)

mysql> show slave status\G
Empty set (0.00 sec)

server1:

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.80
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: hah-bin.000004
          Read_Master_Log_Pos: 195
               Relay_Log_File: 81-relay-bin.000002
                Relay_Log_Pos: 365
        Relay_Master_Log_File: hah-bin.000004
             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: 195
              Relay_Log_Space: 570
              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: 80
                  Master_UUID: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

server2

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.80
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: hah-bin.000004
          Read_Master_Log_Pos: 195
               Relay_Log_File: 82-relay-bin.000002
                Relay_Log_Pos: 365
        Relay_Master_Log_File: hah-bin.000004
             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: 195
              Relay_Log_Space: 570
              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: 80
                  Master_UUID: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

自動切換

(1)自動切換命令如下

[root@centos771 ~]# nohup masterha_manager --conf=/etc/masterha/app.cnf &> /dev/null & 
[1] 17335

[root@centos771 ~]# ps a
   PID TTY      STAT   TIME COMMAND
   602 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
 17044 pts/0    Ss     0:00 -bash
 17335 pts/0    S      0:00 perl /usr/bin/masterha_manager --conf=/etc/masterha/app.cnf
 17623 pts/0    R+     0:00 ps a

(2)然后手動關掉master

[root@hah ~]# systemctl stop mysqld

(3)然后會發現master轉到了server1上
server1的slave狀態為空

mysql> show slave status\G
Empty set (0.00 sec)

server2顯示master轉為server1

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.81
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: 81-bin.000002
          Read_Master_Log_Pos: 1407
               Relay_Log_File: 82-relay-bin.000002
                Relay_Log_Pos: 407
        Relay_Master_Log_File: 81-bin.000002
             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: 1407
              Relay_Log_Space: 612
              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: 81
                  Master_UUID: 711d79aa-0eb8-11eb-b3dc-000c299dcf4d
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

(4)master需要開啟mysqld,然后添加master

[root@hah ~]# systemctl start mysqld


mysql> change master to master_host='10.0.0.81',master_port=3306,master_auto_position=1,master_user='centos',master_password='123456';
Query OK, 0 rows affected, 2 warnings (0.10 sec)

(5)master查看slave的狀態,顯示master是server1,切換成功

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 10.0.0.81
                  Master_User: centos
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: 
          Read_Master_Log_Pos: 4
               Relay_Log_File: hah-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: 
             Slave_IO_Running: No
            Slave_SQL_Running: No
              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: 0
              Relay_Log_Space: 155
              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: NULL
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: 0
                  Master_UUID: 
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: 
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 2f33ae67-0eb8-11eb-b1ec-000c29f9b5e6:1-5
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

VIP的漂移

1.編輯組態檔

[root@centos771 ~]# vim /etc/masterha/app.cnf
# [server default]添加如下一行
master_ip_failover_script=/usr/local/bin/master_ip_failover

2.下載MHA工具包,解壓安裝包

[root@centos771 ~]# cd /data/
[root@centos771 data]# wget https://github.com/yoshinorim/mha4mysql-manager/releases/download/v0.58/mha4mysql-manager-0.58.tar.gz
[root@centos771 data]# tar zxf mha4mysql-manager-0.58.tar.gz

# 查找腳本
[root@centos771 data]# find / -name "master_ip*"
/data/mha4mysql-manager-0.58/tests/t/master_ip_failover
/data/mha4mysql-manager-0.58/tests/t/master_ip_failover_blank
/data/mha4mysql-manager-0.58/samples/scripts/master_ip_failover
/data/mha4mysql-manager-0.58/samples/scripts/master_ip_online_change

3.在 /usr/local/bin添加1個檔案,并給1個檔案添加執行權限

[root@centos771 data]# cd mha4mysql-manager-0.58/samples/scripts/
[root@centos771 scripts]# cp master_ip_
master_ip_failover       master_ip_online_change  
[root@centos771 scripts]# cp master_ip_failover /usr/local/bin/
[root@centos771 scripts]# cd /usr/local/bin
[root@centos771 bin]# ls
master_ip_failover

[root@centos771 bin]# vim master_ip_failover
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
my (
$command, $ssh_user, $orig_master_host, $orig_master_ip,
$orig_master_port, $new_master_host, $new_master_ip, $new_master_port
);
my $vip = '10.0.0.100/24';#設定Virtual IP
my $gateway = '10.0.0.254';#網關Gateway IP
my $interface = 'ens33';    #指定VIP所在網卡
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig $interface:$key $vip;/sbin/arping -I
$interface -c 3 -s $vip $gateway >/dev/null 2>&1";
my $ssh_stop_vip = "/sbin/ifconfig $interface:$key down";
GetOptions(
'command=s' => \$command,
'ssh_user=s' => \$ssh_user,
'orig_master_host=s' => \$orig_master_host,
'orig_master_ip=s' => \$orig_master_ip,
'orig_master_port=i' => \$orig_master_port,
'new_master_host=s' => \$new_master_host,
'new_master_ip=s' => \$new_master_ip,
'new_master_port=i' => \$new_master_port,
);
exit &main();
sub main {
print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";
if ( $command eq "stop" || $command eq "stopssh" ) {

my $exit_code = 1;
eval {
print "Disabling the VIP on old master: $orig_master_host \n";
&stop_vip();
$exit_code = 0;
};
if ($@) {
warn "Got Error: $@\n";
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "start" ) {

my $exit_code = 10;
eval {
print "Enabling the VIP - $vip on the new master - $new_master_host \n";
&start_vip();
$exit_code = 0;
};
if ($@) {
warn $@;
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "status" ) {
print "Checking the Status of the script.. OK \n";
`ssh $ssh_user\@$orig_master_host \" $ssh_start_vip \"`;
exit 0;
}
else {
&usage();
exit 1;
}
}

sub start_vip() {
`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}

sub stop_vip() {
`ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
}
sub usage {
print
"Usage: master_ip_failover --command=start|stop|stopssh|status --
orig_master_host=host --orig_master_ip=ip --orig_master_port=port --
new_master_host=host --new_master_ip=ip --new_master_port=port\n";
}
[root@mha-manager ~]#chmod +x /usr/local/bin/master_ip_failover

4.在現在的master上(server1),添加VIP

[root@81 data]# ip addr add 10.0.0.100/24 dev ens33
[root@81 data]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:85:98:b8 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.81/8 brd 10.255.255.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 10.0.0.100/24 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe85:98b8/64 scope link 
       valid_lft forever preferred_lft forever

測驗:自動轉換

# 檢查MHA的ssh
[root@771 data]# masterha_check_ssh --conf=/etc/masterha/app.cnf

# 檢查MHA環境
[root@771 data]# masterha_check_repl --conf=/etc/masterha/app.cnf

# 啟動MHA
[root@771 data]# masterha_manager --conf=/etc/masterha/app.cnf &> /dev/null &
[2] 2226
[root@771 data]# masterha_check_status --conf=/etc/masterha/app.cnf
app (pid:2160) is running(0:PING_OK), master:10.0.0.81
[2]+  Exit 1                  masterha_manager --conf=/etc/masterha/app.cnf &>/dev/null
# master停止服務
[root@80 data]# systemctl stop mysqld
查看VIP漂移到server1上
# 查看slave1的IP
[root@81 data]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:02:89:3c brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.81/8 brd 10.255.255.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 10.0.0.100/24 brd 10.0.0.255 scope global ens33:1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe02:893c/64 scope link 
       valid_lft forever preferred_lft forever

4、實戰案例:Percona XtraDB Cluster(PXC 5.7)

注意:pxc目前支持最高的OS版本是centos7

1 環境準備

四臺虛擬機

  • pxc1:10.0.0.71
  • pxc2:10.0.0.72
  • pxc3:10.0.0.73
  • pxc4:10.0.0.74

**關閉防火墻和SELinux,保證時間同步 **

注意:如果已經安裝MySQL,必須卸載

2 安裝 Percona XtraDB Cluster 5.7

# 此處使用清華大學yum源,官方源太慢了
[root@71 ~]# cat > /etc/yum.repos.d/pxc.repo << EOF
[percona]
name=percona_repo
baseurl =https://mirrors.tuna.tsinghua.edu.cn/percona/release/\$releasever/RPMS/\$basearch
enabled = 1
gpgcheck = 0
EOF


[root@71 data]# scp /etc/yum.repos.d/pxc.repo 10.0.0.72:/etc/yum.repos.d/
[root@71 data]# scp /etc/yum.repos.d/pxc.repo 10.0.0.73:/etc/yum.repos.d/
[root@71 data]# scp /etc/yum.repos.d/pxc.repo 10.0.0.74:/etc/yum.repos.d/

#在三個節點都安裝好PXC 5.7 
[root@71 data]# yum -y install Percona-XtraDB-Cluster-57
[root@72 data]# yum -y install Percona-XtraDB-Cluster-57
[root@73 data]# yum -y install Percona-XtraDB-Cluster-57
[root@74 data]# yum -y install Percona-XtraDB-Cluster-57

3 在各個節點上分別配置mysql及集群組態檔

/etc/my.cnf為主組態檔,當前版本中,其余的組態檔都放在/etc/percona-xtradb-cluster.conf.d目 錄里,包括mysqld.cnf,mysqld_safe.cnf,wsrep.cnf 三個檔案

pxc1

# 主組態檔不需要修改
[root@71 data]# cat /etc/my.cnf | grep -v "^#"
!includedir /etc/my.cnf.d/
!includedir /etc/percona-xtradb-cluster.conf.d/
[root@71 data]# ls /etc/my.cnf.
my.cnf.d/   my.cnf.old  
[root@71 data]# ls /etc/my.cnf.d/


[root@71 data]# ls /etc/percona-xtradb-cluster.conf.d/
mysqld.cnf  mysqld_safe.cnf  wsrep.cnf

# 下面組態檔不需要修改
[root@71 data]# cat /etc/percona-xtradb-cluster.conf.d/mysqld.cnf | grep -v "^#"
[client]
socket=/var/lib/mysql/mysql.sock

[mysqld]
server-id=71	 # 建議各個節點不同,使用IP
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin		 # 建議啟用,非必須項
log_slave_updates
expire_logs_days=7

symbolic-links=0

# 下面組態檔不需要修改
[root@71 data]# cat /etc/percona-xtradb-cluster.conf.d/mysqld_safe.cnf | grep -v "^#"

[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket   = /var/lib/mysql/mysql.sock
nice     = 0

# PXC的組態檔必須修改
[root@71 data]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf 
[root@71 data]# cat /etc/percona-xtradb-cluster.conf.d/wsrep.cnf | grep -v "^#"
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

wsrep_cluster_address=gcomm://10.0.0.71,10.0.0.72,10.0.0.73	 #三個節點的IP

binlog_format=ROW

default_storage_engine=InnoDB

wsrep_slave_threads= 8

wsrep_log_conflicts

innodb_autoinc_lock_mode=2

wsrep_node_address=10.0.0.71	 #取消注釋,各個節點,指定自已的IP
wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxc-cluster-node-1	#各個節點,指定自已節點名稱

pxc_strict_mode=ENFORCING

wsrep_sst_method=xtrabackup-v2

wsrep_sst_auth="sstuser:s3cretPass"	 #取消本行注釋

pxc2

[root@72 ~]# cat  /etc/percona-xtradb-cluster.conf.d/mysqld.cnf | grep -v "^#"
[client]
socket=/var/lib/mysql/mysql.sock

[mysqld]
server-id=72
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7

symbolic-links=0


[root@72 ~]# cat  /etc/percona-xtradb-cluster.conf.d/wsrep.cnf | grep -v "^#"
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

wsrep_cluster_address=gcomm://10.0.0.71,10.0.0.72,10.0.0.73

binlog_format=ROW

default_storage_engine=InnoDB

wsrep_slave_threads= 8

wsrep_log_conflicts

innodb_autoinc_lock_mode=2

wsrep_node_address=10.0.0.72
wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxc-cluster-node-2

pxc_strict_mode=ENFORCING

wsrep_sst_method=xtrabackup-v2

wsrep_sst_auth="sstuser:s3cretPass"

pxc3

[root@73 ~]# cat  /etc/percona-xtradb-cluster.conf.d/mysqld.cnf | grep -v "^#"
[client]
socket=/var/lib/mysql/mysql.sock

[mysqld]
server-id=73
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7

symbolic-links=0


[root@73 ~]# cat  /etc/percona-xtradb-cluster.conf.d/wsrep.cnf | grep -v "^#"
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

wsrep_cluster_address=gcomm://10.0.0.71,10.0.0.72,10.0.0.73

binlog_format=ROW

default_storage_engine=InnoDB

wsrep_slave_threads= 8

wsrep_log_conflicts

innodb_autoinc_lock_mode=2

wsrep_node_address=10.0.0.73
wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxc-cluster-node-3

pxc_strict_mode=ENFORCING

wsrep_sst_method=xtrabackup-v2

wsrep_sst_auth="sstuser:s3cretPass"		# 注意此處的用戶名,密碼

4 啟動PXC集群中第一個節點

[root@71 data]# ss -ntul
Netid  State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
tcp    LISTEN     0      128                 *:22                              *:*                  
tcp    LISTEN     0      128              [::]:22                           [::]:*                  

#啟動第一個節點
[root@71 data]# systemctl start mysql@bootstrap.service
[root@71 data]# ss -ntul
Netid  State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
tcp    LISTEN     0      128                 *:22                              *:*                  
tcp    LISTEN     0      128                 *:4567                            *:*                  
tcp    LISTEN     0      80               [::]:3306                         [::]:*                  
tcp    LISTEN     0      128              [::]:22                           [::]:*           


#查看root密碼
[root@71 data]# awk -F'root@localhost: ' '/temporary password/{print $2}' /var/log/mysqld.log 
0-4l.wwY*u_A

# 修改密碼
[root@71 data]# mysql -uroot -p0-4l.wwY*u_A
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.31-34-57-log

Copyright (c) 2009-2020 Percona LLC and/or its affiliates
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,authentication_string from mysql.user;
+---------------+-----------+-------------------------------------------+
| user          | host      | authentication_string                     |
+---------------+-----------+-------------------------------------------+
| root          | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)

#創建相關用戶并授權:此處的用戶和密碼跟組態檔一致
mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO
    -> 'sstuser'@'localhost'  IDENTIFIED BY 's3cretPass';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select user,host,authentication_string from mysql.user;
+---------------+-----------+-------------------------------------------+
| user          | host      | authentication_string                     |
+---------------+-----------+-------------------------------------------+
| root          | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| sstuser       | localhost | *1D3B4419453D37D70EC48955E49473559FF4778E |
+---------------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)

# 查看相關變數

mysql> show variables like 'wsrep%'\G
*************************** 1. row ***************************
Variable_name: wsrep_OSU_method
        Value: TOI
*************************** 2. row ***************************
Variable_name: wsrep_RSU_commit_timeout
        Value: 5000
*************************** 3. row ***************************
Variable_name: wsrep_auto_increment_control
        Value: ON
*************************** 4. row ***************************
Variable_name: wsrep_causal_reads
        Value: OFF
*************************** 5. row ***************************
Variable_name: wsrep_certification_rules
        Value: strict
*************************** 6. row ***************************
Variable_name: wsrep_certify_nonPK
        Value: ON
*************************** 7. row ***************************
Variable_name: wsrep_cluster_address
        Value: gcomm://10.0.0.71,10.0.0.72,10.0.0.73
*************************** 8. row ***************************
Variable_name: wsrep_cluster_name
        Value: pxc-cluster
*************************** 9. row ***************************
Variable_name: wsrep_convert_LOCK_to_trx
        Value: OFF
*************************** 10. row ***************************
Variable_name: wsrep_data_home_dir
        Value: /var/lib/mysql/
*************************** 11. row ***************************
Variable_name: wsrep_dbug_option
        Value: 
*************************** 12. row ***************************
Variable_name: wsrep_debug
        Value: OFF
*************************** 13. row ***************************
Variable_name: wsrep_desync
        Value: OFF
*************************** 14. row ***************************
Variable_name: wsrep_dirty_reads
        Value: OFF
*************************** 15. row ***************************
Variable_name: wsrep_drupal_282555_workaround
        Value: OFF
*************************** 16. row ***************************
Variable_name: wsrep_forced_binlog_format
        Value: NONE
*************************** 17. row ***************************
Variable_name: wsrep_load_data_splitting
        Value: ON
*************************** 18. row ***************************
Variable_name: wsrep_log_conflicts
        Value: ON
*************************** 19. row ***************************
Variable_name: wsrep_max_ws_rows
        Value: 0
*************************** 20. row ***************************
Variable_name: wsrep_max_ws_size
        Value: 2147483647
*************************** 21. row ***************************
Variable_name: wsrep_node_address
        Value: 10.0.0.71
*************************** 22. row ***************************
Variable_name: wsrep_node_incoming_address
        Value: AUTO
*************************** 23. row ***************************
Variable_name: wsrep_node_name
        Value: pxc-cluster-node-1
*************************** 24. row ***************************
Variable_name: wsrep_notify_cmd
        Value: 
*************************** 25. row ***************************
Variable_name: wsrep_on
        Value: ON
*************************** 26. row ***************************
Variable_name: wsrep_preordered
        Value: OFF
*************************** 27. row ***************************
Variable_name: wsrep_provider
        Value: /usr/lib64/galera3/libgalera_smm.so
*************************** 28. row ***************************
Variable_name: wsrep_provider_options
        Value: base_dir = /var/lib/mysql/; base_host = 10.0.0.71; base_port = 4567; cert.log_conflicts = no; cert.optimistic_pa = yes; debug = no; evs.auto_evict = 0; evs.causal_keepalive_period = PT1S; evs.debug_log_mask = 0x1; evs.delay_margin = PT1S; evs.delayed_keep_period = PT30S; evs.inactive_check_period = PT0.5S; evs.inactive_timeout = PT15S; evs.info_log_mask = 0; evs.install_timeout = PT7.5S; evs.join_retrans_period = PT1S; evs.keepalive_period = PT1S; evs.max_install_timeouts = 3; evs.send_window = 10; evs.stats_report_period = PT1M; evs.suspect_timeout = PT5S; evs.use_aggregate = true; evs.user_send_window = 4; evs.version = 0; evs.view_forget_timeout = P1D; gcache.dir = /var/lib/mysql/; gcache.freeze_purge_at_seqno = -1; gcache.keep_pages_count = 0; gcache.keep_pages_size = 0; gcache.mem_size = 0; gcache.name = /var/lib/mysql//galera.cache; gcache.page_size = 128M; gcache.recover = no; gcache.size = 128M; gcomm.thread_prio = ; gcs.fc_debug = 0; gcs.fc_factor = 1; gcs.fc_limit = 100; gcs.fc_master_slave = no; gc
*************************** 29. row ***************************
Variable_name: wsrep_recover
        Value: OFF
*************************** 30. row ***************************
Variable_name: wsrep_reject_queries
        Value: NONE
*************************** 31. row ***************************
Variable_name: wsrep_replicate_myisam
        Value: OFF
*************************** 32. row ***************************
Variable_name: wsrep_restart_slave
        Value: OFF
*************************** 33. row ***************************
Variable_name: wsrep_retry_autocommit
        Value: 1
*************************** 34. row ***************************
Variable_name: wsrep_slave_FK_checks
        Value: ON
*************************** 35. row ***************************
Variable_name: wsrep_slave_UK_checks
        Value: OFF
*************************** 36. row ***************************
Variable_name: wsrep_slave_threads
        Value: 8
*************************** 37. row ***************************
Variable_name: wsrep_sst_auth
        Value: ********
*************************** 38. row ***************************
Variable_name: wsrep_sst_donor
        Value: 
*************************** 39. row ***************************
Variable_name: wsrep_sst_donor_rejects_queries
        Value: OFF
*************************** 40. row ***************************
Variable_name: wsrep_sst_method
        Value: xtrabackup-v2
*************************** 41. row ***************************
Variable_name: wsrep_sst_receive_address
        Value: AUTO
*************************** 42. row ***************************
Variable_name: wsrep_start_position
        Value: 00000000-0000-0000-0000-000000000000:-1
*************************** 43. row ***************************
Variable_name: wsrep_sync_wait
        Value: 0
43 rows in set (0.01 sec)
#查看相關狀態變數
mysql> show status like 'wsrep%'\G
*************************** 1. row ***************************
Variable_name: wsrep_local_state_uuid
        Value: 19eed63b-0fb0-11eb-97c4-4f01a0c74176
*************************** 2. row ***************************
Variable_name: wsrep_protocol_version
        Value: 9
*************************** 3. row ***************************
Variable_name: wsrep_last_applied
        Value: 2
*************************** 4. row ***************************
Variable_name: wsrep_last_committed
        Value: 2
*************************** 5. row ***************************
Variable_name: wsrep_replicated
        Value: 2
*************************** 6. row ***************************
Variable_name: wsrep_replicated_bytes
        Value: 544
*************************** 7. row ***************************
Variable_name: wsrep_repl_keys
        Value: 2
*************************** 8. row ***************************
Variable_name: wsrep_repl_keys_bytes
        Value: 64
*************************** 9. row ***************************
Variable_name: wsrep_repl_data_bytes
        Value: 348
*************************** 10. row ***************************
Variable_name: wsrep_repl_other_bytes
        Value: 0
*************************** 11. row ***************************
Variable_name: wsrep_received
        Value: 2
*************************** 12. row ***************************
Variable_name: wsrep_received_bytes
        Value: 151
*************************** 13. row ***************************
Variable_name: wsrep_local_commits
        Value: 0
*************************** 14. row ***************************
Variable_name: wsrep_local_cert_failures
        Value: 0
*************************** 15. row ***************************
Variable_name: wsrep_local_replays
        Value: 0
*************************** 16. row ***************************
Variable_name: wsrep_local_send_queue
        Value: 0
*************************** 17. row ***************************
Variable_name: wsrep_local_send_queue_max
        Value: 1
*************************** 18. row ***************************
Variable_name: wsrep_local_send_queue_min
        Value: 0
*************************** 19. row ***************************
Variable_name: wsrep_local_send_queue_avg
        Value: 0.000000
*************************** 20. row ***************************
Variable_name: wsrep_local_recv_queue
        Value: 0
*************************** 21. row ***************************
Variable_name: wsrep_local_recv_queue_max
        Value: 2
*************************** 22. row ***************************
Variable_name: wsrep_local_recv_queue_min
        Value: 0
*************************** 23. row ***************************
Variable_name: wsrep_local_recv_queue_avg
        Value: 0.500000
*************************** 24. row ***************************
Variable_name: wsrep_local_cached_downto
        Value: 1
*************************** 25. row ***************************
Variable_name: wsrep_flow_control_paused_ns
        Value: 0
*************************** 26. row ***************************
Variable_name: wsrep_flow_control_paused
        Value: 0.000000
*************************** 27. row ***************************
Variable_name: wsrep_flow_control_sent
        Value: 0
*************************** 28. row ***************************
Variable_name: wsrep_flow_control_recv
        Value: 0
*************************** 29. row ***************************
Variable_name: wsrep_flow_control_interval
        Value: [ 100, 100 ]
*************************** 30. row ***************************
Variable_name: wsrep_flow_control_interval_low
        Value: 100
*************************** 31. row ***************************
Variable_name: wsrep_flow_control_interval_high
        Value: 100
*************************** 32. row ***************************
Variable_name: wsrep_flow_control_status
        Value: OFF
*************************** 33. row ***************************
Variable_name: wsrep_cert_deps_distance
        Value: 1.000000
*************************** 34. row ***************************
Variable_name: wsrep_apply_oooe
        Value: 0.000000
*************************** 35. row ***************************
Variable_name: wsrep_apply_oool
        Value: 0.000000
*************************** 36. row ***************************
Variable_name: wsrep_apply_window
        Value: 1.000000
*************************** 37. row ***************************
Variable_name: wsrep_commit_oooe
        Value: 0.000000
*************************** 38. row ***************************
Variable_name: wsrep_commit_oool
        Value: 0.000000
*************************** 39. row ***************************
Variable_name: wsrep_commit_window
        Value: 1.000000
*************************** 40. row ***************************
Variable_name: wsrep_local_state
        Value: 4
*************************** 41. row ***************************
Variable_name: wsrep_local_state_comment
        Value: Synced
*************************** 42. row ***************************
Variable_name: wsrep_cert_index_size
        Value: 1
*************************** 43. row ***************************
Variable_name: wsrep_cert_bucket_count
        Value: 22
*************************** 44. row ***************************
Variable_name: wsrep_gcache_pool_size
        Value: 1944
*************************** 45. row ***************************
Variable_name: wsrep_causal_reads
        Value: 0
*************************** 46. row ***************************
Variable_name: wsrep_cert_interval
        Value: 0.000000
*************************** 47. row ***************************
Variable_name: wsrep_open_transactions
        Value: 0
*************************** 48. row ***************************
Variable_name: wsrep_open_connections
        Value: 0
*************************** 49. row ***************************
Variable_name: wsrep_ist_receive_status
        Value: 
*************************** 50. row ***************************
Variable_name: wsrep_ist_receive_seqno_start
        Value: 0
*************************** 51. row ***************************
Variable_name: wsrep_ist_receive_seqno_current
        Value: 0
*************************** 52. row ***************************
Variable_name: wsrep_ist_receive_seqno_end
        Value: 0
*************************** 53. row ***************************
Variable_name: wsrep_incoming_addresses
        Value: 10.0.0.71:3306
*************************** 54. row ***************************
Variable_name: wsrep_cluster_weight
        Value: 1
*************************** 55. row ***************************
Variable_name: wsrep_desync_count
        Value: 0
*************************** 56. row ***************************
Variable_name: wsrep_evs_delayed
        Value: 
*************************** 57. row ***************************
Variable_name: wsrep_evs_evict_list
        Value: 
*************************** 58. row ***************************
Variable_name: wsrep_evs_repl_latency
        Value: 0/0/0/0/0
*************************** 59. row ***************************
Variable_name: wsrep_evs_state
        Value: OPERATIONAL
*************************** 60. row ***************************
Variable_name: wsrep_gcomm_uuid
        Value: 19ec9903-0fb0-11eb-956e-3e998fb96c10
*************************** 61. row ***************************
Variable_name: wsrep_cluster_conf_id
        Value: 1
*************************** 62. row ***************************
Variable_name: wsrep_cluster_size
        Value: 1
*************************** 63. row ***************************
Variable_name: wsrep_cluster_state_uuid
        Value: 19eed63b-0fb0-11eb-97c4-4f01a0c74176
*************************** 64. row ***************************
Variable_name: wsrep_cluster_status
        Value: Primary
*************************** 65. row ***************************
Variable_name: wsrep_connected
        Value: ON
*************************** 66. row ***************************
Variable_name: wsrep_local_bf_aborts
        Value: 0
*************************** 67. row ***************************
Variable_name: wsrep_local_index
        Value: 0
*************************** 68. row ***************************
Variable_name: wsrep_provider_name
        Value: Galera
*************************** 69. row ***************************
Variable_name: wsrep_provider_vendor
        Value: Codership Oy <info@codership.com>
*************************** 70. row ***************************
Variable_name: wsrep_provider_version
        Value: 3.45(ra60e019)
*************************** 71. row ***************************
Variable_name: wsrep_ready
        Value: ON
71 rows in set (0.00 sec)
#重點關注下面內容
mysql> show status like 'wsrep%';
+----------------------------------+--------------------------------------+
| Variable_name                    | Value                                |
+----------------------------------+--------------------------------------+
| wsrep_local_state_uuid           | 19eed63b-0fb0-11eb-97c4-4f01a0c74176 |
.............
.............
| wsrep_local_state                | 4                                    |
| wsrep_local_state_comment        | Synced                               |
.............
| wsrep_cluster_size               | 1                                    |
| wsrep_cluster_state_uuid         | 19eed63b-0fb0-11eb-97c4-4f01a0c74176 |
| wsrep_cluster_status             | Primary                              |
| wsrep_connected                  | ON                                   |
..............
| wsrep_ready                      | ON                                   |
+----------------------------------+--------------------------------------+
71 rows in set (0.00 sec)

說明:

  • wsrep_cluster_size表示,該Galera集群中只有一個節點
  • wsrep_local_state_comment 狀態為Synced(4),表示資料已同步完成(因為是第一個引導節點,無數 據需要同步), 如果狀態是Joiner, 意味著 SST 沒有完成. 只有所有節點狀態是Synced,才可以加新節點
  • wsrep_cluster_status為Primary,且已經完全連接并準備好

5 啟動PXC集群中其它所有節點

pxc2

[root@72 ~]# ss -ntul
Netid  State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
tcp    LISTEN     0      128                 *:22                              *:*                  
tcp    LISTEN     0      128              [::]:22                           [::]:*                  
[root@72 ~]# systemctl start mysql
[root@72 ~]# ss -ntulp
Netid  State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
tcp    LISTEN     0      128                 *:22                              *:*                   users:(("sshd",pid=804,fd=3))
tcp    LISTEN     0      128                 *:4567                            *:*                   users:(("mysqld",pid=2029,fd=11))
tcp    LISTEN     0      80               [::]:3306                         [::]:*                   users:(("mysqld",pid=2029,fd=34))
tcp    LISTEN     0      128              [::]:22                           [::]:*                   users:(("sshd",pid=804,fd=4))

pxc3

[root@73 ~]# ss -ntul
Netid  State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
tcp    LISTEN     0      128                 *:22                              *:*                  
tcp    LISTEN     0      128              [::]:22                           [::]:*                  
[root@73 ~]# systemctl start mysql

[root@73 ~]# ss -ntulp
Netid  State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
tcp    LISTEN     0      128                 *:22                              *:*                   users:(("sshd",pid=808,fd=3))
tcp    LISTEN     0      128                 *:4567                            *:*                   users:(("mysqld",pid=1954,fd=11))
tcp    LISTEN     0      128              [::]:22                           [::]:*                   users:(("sshd",pid=808,fd=4))
tcp    LISTEN     0      80               [::]:3306                         [::]:*                   users:(("mysqld",pid=1954,fd=34))

6 查看集群狀態,驗證集群是否成功

pxc1

mysql> show variables like 'wsrep_node_name';
+-----------------+--------------------+
| Variable_name   | Value              |
+-----------------+--------------------+
| wsrep_node_name | pxc-cluster-node-1 |
+-----------------+--------------------+
1 row in set (0.00 sec)

mysql> show variables like 'wsrep_node_address';
+--------------------+-----------+
| Variable_name      | Value     |
+--------------------+-----------+
| wsrep_node_address | 10.0.0.71 |
+--------------------+-----------+
1 row in set (0.00 sec)

mysql> show variables like 'wsrep_on';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wsrep_on      | ON    |
+---------------+-------+
1 row in set (0.00 sec)


mysql> SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+
1 row in set (0.00 sec)

7 測驗

#在任意節點創建資料庫
# pxc1
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)

# pxc2
# 注意:登錄密碼為pxc1修改的密碼
[root@72 ~]# mysql -uroot -p123456;history -c
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision 7359e4f, WSREP version 31.45, wsrep_31.45

Copyright (c) 2009-2020 Percona LLC and/or its affiliates
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)


# pxc3
[root@72 ~]# mysql -uroot -p123456;history -c
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision 7359e4f, WSREP version 31.45, wsrep_31.45

Copyright (c) 2009-2020 Percona LLC and/or its affiliates
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
#利用Xshell軟體,同時在三個節點資料庫創建資料庫,在其中一個節點成功

# pxc2
mysql> create database db2;
ERROR 1007 (HY000): Can't create database 'db2'; database exists
mysql> 

# pxc1
mysql> create database db2;
Query OK, 1 row affected (0.01 sec)

# pxc3
mysql> create database db2;
ERROR 1007 (HY000): Can't create database 'db2'; database exists

8 在PXC集群中加入節點

一個節點加入到Galera集群有兩種情況:新節點加入集群、暫時離組的成員再次加入集群

1)新節點加入Galera集群

? 新節點加入集群時,需要從當前集群中選擇一個Donor節點來同步資料,也就是所謂的 state_snapshot_tranfer(SST)程序,SST同步資料的方式由選項wsrep_sst_method決定,一般選擇的 是xtrabackup, 必須注意,新節點加入Galera時,會洗掉新節點上所有已有資料,再通過xtrabackup(假設使用的是該 方式)從Donor處完整備份所有資料進行恢復,所以,如果資料量很大,新節點加入程序會很慢,而且, 在一個新節點成為Synced狀態之前,不要同時加入其它新節點,否則很容易將集群壓垮, 如果是這種情況,可以考慮使用wsrep_sst_method=rsync來做增量同步,既然是增量同步,最好保證 新節點上已經有一部分資料基礎,否則和全量同步沒什么區別,且這樣會對Donor節點加上全域read only鎖,

2)舊節點加入Galera集群

? 如果舊節點加入Galera集群,說明這個節點在之前已經在Galera集群中呆過,有一部分資料基礎,缺少 的只是它離開集群時的資料,這時加入集群時,會采用IST(incremental snapshot transfer)傳輸機制, 即使用增量傳輸, 但注意,這部分增量傳輸的資料源是Donor上快取在GCache檔案中的,這個檔案有大小限制,如果缺 失的資料范圍超過已快取的內容,則自動轉為SST傳輸,如果舊節點上的資料和Donor上的資料不匹配 (例如這個節點離組后人為修改了一點資料),則自動轉為SST傳輸,

#在PXC集群中再加一臺新的主機PXC4:10.0.0.37

[root@74 ~]# cat /etc/percona-xtradb-cluster.conf.d/mysqld.cnf | grep -v "^#"
[client]
socket=/var/lib/mysql/mysql.sock

[mysqld]
server-id=74
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7

symbolic-links=0
[root@74 ~]# cat /etc/percona-xtradb-cluster.conf.d/wsrep.cnf | grep -v "^#"
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

wsrep_cluster_address=gcomm://10.0.0.71,10.0.0.72,10.0.0.73,10.0.0.74

binlog_format=ROW

default_storage_engine=InnoDB

wsrep_slave_threads= 8

wsrep_log_conflicts

innodb_autoinc_lock_mode=2

wsrep_node_address=10.0.0.74
wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxc-cluster-node-4

pxc_strict_mode=ENFORCING

wsrep_sst_method=xtrabackup-v2

wsrep_sst_auth="sstuser:s3cretPass"
# 啟動服務
[root@74 ~]# systemctl restart mysql
[root@74 ~]# ss -ntulp
Netid  State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
tcp    LISTEN     0      128                 *:22                              *:*                   users:(("sshd",pid=807,fd=3))
tcp    LISTEN     0      128                 *:4567                            *:*                   users:(("mysqld",pid=15095,fd=11))
tcp    LISTEN     0      128              [::]:22                           [::]:*                   users:(("sshd",pid=807,fd=4))
tcp    LISTEN     0      80               [::]:3306                         [::]:*                   users:(("mysqld",pid=15095,fd=35))


# 登錄資料庫
[root@74 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision 7359e4f, WSREP version 31.45, wsrep_31.45

Copyright (c) 2009-2020 Percona LLC and/or its affiliates
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 4     |
+--------------------+-------+
1 row in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| db2                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.00 sec)
# 將其它節點的組態檔加以修改
# pxc3
[root@73 ~]# sed -ri '/^wsrep_cluster_address/s#(.*)#\1,10.0.0.74#' /etc/percona-xtradb-cluster.conf.d/wsrep.cnf 
[root@73 ~]# cat  /etc/percona-xtradb-cluster.conf.d/wsrep.cnf | grep -v "^#"
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

wsrep_cluster_address=gcomm://10.0.0.71,10.0.0.72,10.0.0.73,10.0.0.74

binlog_format=ROW

default_storage_engine=InnoDB

wsrep_slave_threads= 8

wsrep_log_conflicts

innodb_autoinc_lock_mode=2

wsrep_node_address=10.0.0.73
wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxc-cluster-node-3

pxc_strict_mode=ENFORCING

wsrep_sst_method=xtrabackup-v2

wsrep_sst_auth="sstuser:s3cretPass"




# pxc2
[root@72 ~]# sed -ri '/^wsrep_cluster_address/s#(.*)#\1,10.0.0.74#' /etc/percona-xtradb-cluster.conf.d/wsrep.cnf

# pxc1
[root@71 data]# sed -ri '/^wsrep_cluster_address/s#(.*)#\1,10.0.0.74#' /etc/percona-xtradb-cluster.conf.d/wsrep.cnf

9 在PXC集群中修復故障節點

#在任意節點停止服務

# pxc3
[root@73 ~]# systemctl stop mysql

# pxc2
mysql> show status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+
1 row in set (0.01 sec)

# pxc1
mysql> show status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+
1 row in set (0.00 sec)


# 創建資料庫
# pxc4
mysql> create database db3;
Query OK, 1 row affected (0.00 sec)

# pxc2
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| db2                |
| db3                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
7 rows in set (0.00 sec)


# pxc3開啟服務
[root@73 ~]# systemctl start mysql
[root@73 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision 7359e4f, WSREP version 31.45, wsrep_31.45

Copyright (c) 2009-2020 Percona LLC and/or its affiliates
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| db2                |
| db3                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
7 rows in set (0.00 sec)

# 資料已同步

5、通過 ansible 部署二進制 mysql 8

實驗環境準備

虛擬機IP
centos8110.0.0.81ansible服務器主控端
centos8210.0.0.82遠程主機1
centos8310.0.0.83遠程主機2

前期準備

1、關閉防火墻:systemctl disable --now firewalld
2、關閉selinux安全機制: sed -ri 's/(^SELINUX=).*/\1disabled/' /etc/selinux/config
3、重啟生效:init 6

1、安裝ansible

使用EPEL源的rpm包安裝

# 使用阿里云鏡像站的eple源:https://developer.aliyun.com/mirror/epel?spm=a2c6h.13651102.0.0.3e221b11pyj3r4
# 1、如果之前配置了epel源,則先備份;如果沒有就跳過這步
[root@81 ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup

[root@81 ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

# 2. 下載新repo 到/etc/yum.repos.d/
1)安裝 epel 配置包
[root@81 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

2)將 repo 配置中的地址替換為阿里云鏡像站地址
[root@81 ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@81 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*


# 安裝ansible
[root@81 ~]# yum -y install ansible
[root@81 ~]# ansible --version
ansible 2.9.14
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

2、修改ansible組態檔

# /etc/ansible/ansible.cfg
[root@81 data]# vim /etc/ansible/ansible.cfg 
[defaults]
host_key_checking = False	# 解開注釋
# /etc/ansible/hosts
# 直接設定ssh連接,用戶名,密碼,執行yaml腳本就不需要加 -k 
[root@81 data]# vim /etc/ansible/hosts
[webservser]
10.0.0.81  ansible_connection=local
10.0.0.82  ansible_connection=ssh   ansible_user=root  ansible_password=123456
10.0.0.83  ansible_connection=ssh   ansible_user=root  ansible_password=123456

3、準備mysql相關檔案

# my.cnf 組態檔
[root@81 data]# cat my.cnf 
[mysqld]
# 指定資料庫資料存放路徑
datadir=/data/mysql

# 指定套間字路徑
socket=/data/mysql/mysql.sock

# 設定日志檔案路徑
log-error=/data/mysql/mysqld.log

#關閉DNS反向決議
skip_name_resolve=on
port=3306
#pid-file=/tmp/mysql.pid

[client]
port=3306
# 指定套間字路徑
socket=/data/mysql/mysql.sock
# passwd.sh 修改mysql密碼
[root@81 data]# vim passwd.sh
pwd=`awk '/temporary password/{print $NF}' /data/mysql/mysqld.log`
mysqladmin -uroot -p"$pwd" password 12345678

4、編輯yaml腳本

[root@81 data]# vim install_mysql.yml 
- hosts: all 
  remote_user: root
  gather_facts: no
  vars:
  - path: https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.17-x86_64-minimal.tar.xz
  
  tasks:
    - name: "關閉初次訪問提示詢問"
      shell: sed -i "s/^.*StrictHostKeyChecking.*$/   StrictHostKeyChecking no/g" /etc/ssh/ssh_config
    - name: "洗掉ssh檔案"
      file: path=/root/.ssh/ state=absent
    - name: "生成公鑰私鑰對"
      shell: ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa
    - name: "洗掉臨時ssh目錄"
      file: path=/tmp/ssh/ state=absent
      run_once: true
    - name: "從各宿主機將公鑰拷貝到本機"
      fetch: src=/root/.ssh/id_rsa.pub dest=/tmp/ssh/
    - name: "將各個公鑰合并成一個檔案"
      shell: find /tmp/ssh/* -type f -exec sh -c 'cat {}>>/tmp/ssh/authorized_keys.log' \;
      run_once: true
    - name: "將合成的公鑰進行分發"
      copy: src=/tmp/ssh/authorized_keys.log dest=/root/.ssh/authorized_keys mode=0600
      tags:
        - install ssh  

    - name: "安裝依賴庫"
      yum: name=libaio,ncurses-compat-libs
    - name: "創建組"
      group: name=mysql gid=306
    - name: "創建用戶"
      user: name=mysql uid=306 group=mysql shell=/sbin/nologin system=yes create_home=no home=/data/mysql
    - name: "創建資料檔案"
      file: path=/data/mysql state=directory owner=mysql group=mysql recurse=yes
    - name: "下載wget"
      yum: name=wget state=latest
    - name: "下載mysql8.0二進制安裝包"
      shell: wget -P /data/ {{ path }}
    - name: "解壓縮包到指定目錄:/use/local/"
      shell: find /data/ -name "*8.0*" | awk -F"/" "{print $3}" | xargs -I {} tar xf {} -C /usr/local/  
    - name: "創建MySQL軟連接"
      shell: find /usr/local/ -maxdepth 1 -type d -name "mysql*" -exec ln -s {} /usr/local/mysql \;
    - name: "修改連接權限"
      file: dest=/usr/local/mysql owner=root group=root recurse=yes state=directory
    
    - name: "修改MySQL組態檔"
      copy: src=/data/my.cnf  dest=/etc/ backup=yes
    - name: "初始化資料庫"
      shell: chdir=/usr/local/mysql bin/mysqld --initialize --datadir=/data/mysql --user=mysql

    - name: "將mysql添加到服務"
      copy: src=/usr/local/mysql/support-files/mysql.server dest=/etc/init.d/mysqld
    - name: "設定開機自啟"
      shell: chkconfig --add mysqld;chkconfig mysqld on
    - name: "創建mysql運行軟連接"
      shell: ln -s /usr/local/mysql/bin/* /usr/bin/
	- name: secure script
      script: /data/passwd.sh
      tags: script
    
    - name: "啟動mysql服務"
      service: name=mysqld state=started

5、執行腳本

[root@81 data]# ansible-playbook install_mysql.yml
[root@81 ~]# ansible-playbook /data/install_mysql.yml 

PLAY [all] *****************************************************************************************

TASK [關閉初次訪問提示詢問] **********************************************************************************
[WARNING]: Consider using the replace, lineinfile or template module rather than running 'sed'.  If
you need to use command because replace, lineinfile or template is insufficient you can add 'warn:
false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this
message.
changed: [10.0.0.81]
changed: [10.0.0.82]
changed: [10.0.0.83]

TASK [洗掉ssh檔案] *************************************************************************************
changed: [10.0.0.81]
ok: [10.0.0.82]
ok: [10.0.0.83]

TASK [生成公鑰私鑰對] *************************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.82]
changed: [10.0.0.83]

TASK [洗掉臨時ssh目錄] ***********************************************************************************
ok: [10.0.0.81]

TASK [從各宿主機將公鑰拷貝到本機] *******************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [將各個公鑰合并成一個檔案] ********************************************************************************
changed: [10.0.0.81]

TASK [將合成的公鑰進行分發] **********************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.82]
changed: [10.0.0.83]

TASK [安裝依賴庫] ***************************************************************************************
changed: [10.0.0.83]
changed: [10.0.0.81]
changed: [10.0.0.82]

TASK [創建組] *****************************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.82]
changed: [10.0.0.83]

TASK [創建用戶] ****************************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.82]
changed: [10.0.0.83]

TASK [創建資料檔案] **************************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [下載wget] **************************************************************************************
ok: [10.0.0.81]
ok: [10.0.0.82]
ok: [10.0.0.83]

TASK [下載mysql8.0二進制安裝包] ****************************************************************************
[WARNING]: Consider using the get_url or uri module rather than running 'wget'.  If you need to use
command because get_url or uri is insufficient you can add 'warn: false' to this command task or
set 'command_warnings=False' in ansible.cfg to get rid of this message.
changed: [10.0.0.83]
changed: [10.0.0.81]
changed: [10.0.0.82]

TASK [解壓縮包到指定目錄:/use/local/] ***********************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [創建MySQL軟連接] **********************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [修改連接權限] **************************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [修改MySQL組態檔] *********************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [初始化資料庫] **************************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [將mysql添加到服務] *********************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [設定開機自啟] **************************************************************************************
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [創建mysql運行軟連接] ********************************************************************************
[WARNING]: Consider using the file module with state=link rather than running 'ln'.  If you need to
use command because file is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.
changed: [10.0.0.81]
changed: [10.0.0.83]
changed: [10.0.0.82]

TASK [啟動mysql服務] ***********************************************************************************
changed: [10.0.0.82]
changed: [10.0.0.83]
changed: [10.0.0.81]

PLAY RECAP *****************************************************************************************
10.0.0.81                  : ok=22   changed=20   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
10.0.0.82                  : ok=20   changed=18   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
10.0.0.83                  : ok=20   changed=18   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/180751.html

標籤:其他

上一篇:5年Java開發,面試4大廠(阿里、拼多多、位元組、美團)后,我總結出大廠高頻面試真題及決議

下一篇:阿里架構師:天天高并發,達不到百萬以上并發都不叫高并發!!

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more