欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL5.7 集群配置的步驟

 更新時間:2021年03月04日 11:50:29   作者:youcong  
這篇文章主要介紹了MySQL5.7 集群配置的步驟,幫助大家更好的理解和學(xué)習(xí)使用MySQL,感興趣的朋友可以了解下

本次針對的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í)行主從配置,進(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)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論