MySQL5.7 集群配置的步驟
本次針對的MySQL版本為5.7,首先分別在A服務器和B服務器上安裝MySQL,可以通過yum安裝也可以通過wget下載直接編譯安裝。安裝方式可以多種多樣,但必須要確保安裝成功。
1.修改A服務器的my.cnf文件vim /etc/my.cnf
并添加如下內容:
server-id=1auto_increment_offset=1auto_increment_increment=2gtid_mode=onenforce_gtid_consistency=onlog-bin=mysql-bin2.修改B服務器的my.cnf文件
vim /etc/my.cnf
并添加如下內容:
server-id=2auto_increment_offset=1auto_increment_increment=2gtid_mode=onenforce_gtid_consistency=onlog-bin=mysql-bin3.在A服務器上的MySQL創建B服務器訪問的復制用戶
create user B@’IP’ identified by ’密碼’;grant replication slave on *.* to B@’服務器IP’;4.在B服務器上的MySQL創建A服務器訪問的復制用戶
create user A@’IP’ identified by ’密碼’;grant replication slave on *.* to A@’密碼’;5.在B服務器上的MySQL執行主從配置,進行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服務器上的MySQL執行主從配置,進行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服務器上的MySQL新建數據庫和對應的數據表,B服務器上的MySQL會同步過來,確保數據庫和數據表一致。
7.Nginx配置Nginx配置MySQL集群訪問URL,確保微服務應用連接相同的URL。Nginx中的MySQL配置,內容如下:
stream { upstream mysql_proxy{ hash $remote_addr consistent; server A服務器IP:3306 weight=1 max_fails=3 fail_timeout=10s; server B服務器IP:3306 weight=1 max_fails=3 fail_timeout=10s; } server { listen 3306; # 數據庫服務器監聽端口 proxy_connect_timeout 10s; proxy_timeout 300s; proxy_pass mysql_proxy; }}特別注意:
生產環境不建議設置MySQL端口為3306或3389。
以上就是MySQL5.7 集群配置的步驟的詳細內容,更多關于MySQL 集群配置的資料請關注好吧啦網其它相關文章!
相關文章:
