mysql 雙機熱備註意事項

上一篇文章已經介紹過    主從複製,   本文對主從複製只是簡單描述,如對主從複製不清楚的,能夠先看上一篇文章   主從複製 html

一:介紹mysql

  mysql版本:5.7.20sql

  第一個主服服務器ip:192.168.71.139服務器

  第二個主服服務器ip:192.168.71.141ide

二:配置測試

  第一臺主服務器192.168.71.139ui

  1:修改/etc/mysql/my.cnf 文件,注意這裏的#是註釋,不要寫到配置文件中spa

server-id = 141                                                    #服務器id,不能重複,建議用ip後三位。
log-bin = mysql-bin
binlog-ignore-db = mysql,information_schema    #忽略寫入binlog日誌的庫
auto-increment-increment = 2                             #字段變化增量值
auto-increment-offset = 1                                    #初始字段ID爲1
slave-skip-errors = all                                          #忽略全部複製產生的錯誤3d

2:登錄mysql,建立容許其它服務器複製的帳號日誌

GRANT REPLICATION SLAVE ON *.* to 'mysql帳號'@'%' identified by '密碼';

3:使用show master status查詢狀態

 

第二臺主服務器192.168.71.139

  1:修改/etc/mysql/my.cnf 文件,此處的server-id = 139,其它不變。

  使用show master status查詢狀態

  

  此時,須要從新啓動兩臺服務器的mysql  

  

 

  在192.168.71.141執行同步語句

master_log_file 值來源於139服務器,執行show master status後的 File字段

master_log_file 值來源於139服務器,執行show master status後的 Position字段
change master to master_host=192.168.71.139’,master_user=’master2’,master_password=123456’,master_log_file=’mysql-bin.000002’,master_log_pos=154;

  在192.168.71.139執行同步語句

  master_log_file 值來源於141服務器,執行show master status後的 File字段

  master_log_file 值來源於141服務器,執行show master status後的 Position字段

change master to master_host=’192.168.71.141,master_user=’master1’,master_password=’123456’,master_log_file=’mysql-bin.000002’, master_log_pos=154;

到此爲此配置結束,重啓mysql,登錄mysql,使用show slave status\G檢查配置狀態,發現Slave_IO沒法啓動,Salve_IO_Running值爲no,出現以下提示

The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

經過日誌發現,master和slave的uuids重複了,由於這兩臺服務器是克隆的,因此須要修改/var/lib/mysql/auto.cnf

這裏修改我只修改最後一個字母,由於修改多了,我mysql都沒法啓動。修改完成,從新啓動mysql,再登錄mysql並執行show slave status\G,以下圖

 

三:測試

在任意一臺服務器執行以下sql

create table tab141(id int primary key);

create table tab139(id int primary key);

在139服務器執行以下sql

insert into tab139 values(1);

在141服務器執行以下sql

insert into tab141 values(2);

結果以下圖:

若是本文對你有幫助,你能夠點一下推薦,謝謝!

相關文章
相關標籤/搜索