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=1auto_increment_offset=1auto_increment_increment=2gtid_mode=onenforce_gtid_consistency=onlog-bin=mysql-bin2.修改B服務(wù)器的my.cnf文件
vim /etc/my.cnf
并添加如下內(nèi)容:
server-id=2auto_increment_offset=1auto_increment_increment=2gtid_mode=onenforce_gtid_consistency=onlog-bin=mysql-bin3.在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í)行主從配置,進(jìn)行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í)行主從配置,進(jìn)行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)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. 詳解MySQL批量入庫的幾種方式2. SQL 嵌套查詢的具體使用3. 掌握SQL Server實(shí)戰(zhàn)教程之SQL Server的安裝指南4. MySQL 性能、監(jiān)控與災(zāi)難恢復(fù)5. ORACLE中常用的幾種正則表達(dá)式小結(jié)6. Mybatis常見注解有哪些(總結(jié))7. MySQL 語句大全:創(chuàng)建、授權(quán)、查詢、修改8. 如何手動刪除 SQL Server 2000 默認(rèn)實(shí)例、命名實(shí)例或虛擬實(shí)例9. PyCharm MySQL可視化Database配置過程圖解10. MySQL/MariaDB 如何實(shí)現(xiàn)數(shù)據(jù)透視表的示例代碼
