4 MySQL 5.7 高可用

來源:互聯網
上載者:User

標籤:mysql5.7 高可用 主從複製

MySQL 5.7主從複製


https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-howto.html
GTID(GlobalTransaction ID)是對於一個已提交事務的編號,並且是一個全域唯一的編號。GTID實際上是由UUID+TID組成的。其中UUID是一個MySQL執行個體的唯一標識。TID代表了該執行個體上已經提交的事務數量,並且隨著事務提交單調遞增。

設定gtid模式,在my.cnf裡面的mysqld選項卡裡面設定,設定完後,重啟mysql服務生效:

[mysqld]
gtid_mode=ON
log-slave-updates=ON
enforce-gtid-consistency=ON

mysql> change master to
master_host=‘主庫IP‘,
master_port=主庫連接埠,
master_user=‘repl‘,
master_password=‘repl密碼‘,
master_auto_position=1;
mysql> start slave;

PS:其中這裡有差別,以前非gtid的是用master_log_file=‘mysql-bin.000009‘,master_log_pos=154;而gtid就採用了master_auto_positon=1;來自動同步主庫的binlog了。
查看從庫複製狀態,是雙YES,而且Seconds_Behind_Master: 0:
Tell the slave to use the master with GTID based transactions as the replication data source, and to use GTID-based auto-positioning rather than file-based positioning. Issue a CHANGE MASTER TO statement on the slave, including the MASTER_AUTO_POSITION option in the statement to tell the slave that the master‘s transactions are identified by GTIDs.

查看備機資訊
1.主庫show slave hosts;

  1. SELECT * FROM information_schema.PROCESSLIST WHERE COMMAND = ‘Binlog Dump‘;
    查看同步狀態
    1.Show slave status\G
  2. SELECT SERVICE_STATE FROM performance_schema.replication_connection_status;

搭建級聯備庫

  1. 需設定log_slave_updates=1,使備庫產生binlog
  2. 備份資料庫並通過備份建立新資料庫
  3. 新資料庫與備庫同步
  4. 新資料庫改為與主庫同步
    reset slave;
    change master to
    master_host=‘主庫IP‘,
    master_port=主庫連接埠,
    master_user=‘repl‘,
    master_password=‘repl密碼‘,
    master_auto_position=1;

  5. su - mysql
    2.登入預設(3306)連接埠的執行個體
    source .profile
    mysql –uroot –p –h127.0.0.1 –P3306
    3.登入3307連接埠的執行個體
    source .p3307
    mysql –uroot –p –h127.0.0.1 –P3307

知識點整理:
1、.mysql_history檔案記錄mysql使用者執行的命令,存在安全隱患,需要進行軟串連處理。lns -l /dev/null $HOME/.mysql_history
2、mysql 如何搭建半同步和非同步備庫。
3、mysql環境安裝。注意修改/relay_log檔案夾的屬主,VIP配置。

4 MySQL 5.7 高可用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.