MySQL5.7 集群配置的步驟
本次針對的MySQL版本為5.7,首先分別在A服務(wù)器和B服務(wù)器上安裝MySQL,可以通過yum安裝也可以通過wget下載直接編譯安裝。安裝方式可以多種多樣,但必須要確保安裝成功。
1.修改A服務(wù)器的my.cnf文件
vim /etc/my.cnf
并添加如下內(nèi)容:
server-id=1 auto_increment_offset=1 auto_increment_increment=2 gtid_mode=on enforce_gtid_consistency=on log-bin=mysql-bin
2.修改B服務(wù)器的my.cnf文件
vim /etc/my.cnf
并添加如下內(nèi)容:
server-id=2 auto_increment_offset=1 auto_increment_increment=2 gtid_mode=on enforce_gtid_consistency=on log-bin=mysql-bin
3.在A服務(wù)器上的MySQL創(chuàng)建B服務(wù)器訪問的復(fù)制用戶
create user B@'IP' identified by '密碼'; grant replication slave on *.* to B@'服務(wù)器IP';
4.在B服務(wù)器上的MySQL創(chuàng)建A服務(wù)器訪問的復(fù)制用戶
create user A@'IP' identified by '密碼'; grant replication slave on *.* to A@'密碼';
5.在B服務(wù)器上的MySQL執(zhí)行主從配置,進行A主B從
change master to master_host='IP', master_user='B', master_password='?T-p&clsr38i', master_port=3306, master_auto_position=1; start slave; show slave status;
6.在A服務(wù)器上的MySQL執(zhí)行主從配置,進行B主A從
change master to master_host='IP', master_user='A', master_password='?T-p&clsr38i', master_port=3306, master_auto_position=1; start slave; show slave status;
然后測試,在A服務(wù)器上的MySQL新建數(shù)據(jù)庫和對應(yīng)的數(shù)據(jù)表,B服務(wù)器上的MySQL會同步過來,確保數(shù)據(jù)庫和數(shù)據(jù)表一致。
7.Nginx配置
Nginx配置MySQL集群訪問URL,確保微服務(wù)應(yīng)用連接相同的URL。
Nginx中的MySQL配置,內(nèi)容如下:
stream { upstream mysql_proxy{ hash $remote_addr consistent; server A服務(wù)器IP:3306 weight=1 max_fails=3 fail_timeout=10s; server B服務(wù)器IP:3306 weight=1 max_fails=3 fail_timeout=10s; } server { listen 3306; # 數(shù)據(jù)庫服務(wù)器監(jiān)聽端口 proxy_connect_timeout 10s; proxy_timeout 300s; proxy_pass mysql_proxy; } }
特別注意:
生產(chǎn)環(huán)境不建議設(shè)置MySQL端口為3306或3389。
以上就是MySQL5.7 集群配置的步驟的詳細(xì)內(nèi)容,更多關(guān)于MySQL 集群配置的資料請關(guān)注本站其它相關(guān)文章!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。