mysql雙主配置講義-創(chuàng)新互聯(lián)

下文內(nèi)容主要給大家?guī)?lái)mysql雙主配置講義,這里所講到的知識(shí),與書籍略有不同,都是創(chuàng)新互聯(lián)專業(yè)技術(shù)人員在與用戶接觸過程中,總結(jié)出來(lái)的,具有一定的經(jīng)驗(yàn)分享價(jià)值,希望給廣大讀者帶來(lái)幫助。

站在用戶的角度思考問題,與客戶深入溝通,找到永城網(wǎng)站設(shè)計(jì)與永城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國(guó)際域名空間、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋永城地區(qū)。

結(jié)尾2

1.數(shù)據(jù)庫(kù)架構(gòu)圖:
mysql雙主配置講義

2.安裝環(huán)境信息:
master1 172.16.90.13   CentOS 7.2  Keepalived讀  VIP:172.16.90.15
master2 172.16.90.14   CentOS 7.2  Keepalived讀  VIP:172.16.90.16

3.MySQL雙主配置

master1修改my.cnf,新增如下配置:

server-id=13
log-bin=mysql-bin
sync-binlog=1
binlog-checksum=none
binlog-format=mixed
auto-increment-increment=2
auto-increment-offset=1
log-slave-updates
slave-skip-errors=all

master2修改my.cnf,新增如下配置:

server-id=14
log-bin=mysql-bin
sync-binlog=1
binlog-checksum=none
binlog-format=mixed
auto-increment-increment=2
auto-increment-offset=1
log-slave-updates
slave-skip-errors=all

在master1中為mysql從庫(kù)賬戶授權(quán):

grant replication slave on . to 'sync'@'%' identified by 'syncpwd';
flush privileges;
show master status; #當(dāng)前主庫(kù)狀態(tài),即master1
show master status;
+------------------+----------+--------------+------------------+-------------------+
| File       | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 |    599 |        |          |          |
+------------------+----------+--------------+------------------+-------------------+

在master2中為mysql從庫(kù)賬戶授權(quán):

grant replication slave on . to 'sync'@'%' identified by 'syncpwd';
flush privileges;
show master status; #當(dāng)前主庫(kù)狀態(tài),即master2
show master status;
+------------------+----------+--------------+------------------+-------------------+
| File       | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |    468 |        |          |          |
+------------------+----------+--------------+------------------+-------------------+

在maste1中指定master2為主庫(kù):

stop slave;
change master to master_host='172.16.90.14',master_user='sync',master_password='syncpwd',master_log_file='mysql-bin.000002',master_log_pos=468;
flush privileges;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;
start slave;

在maste2中指定master1為主庫(kù):

stop slave;
change master to master_host='172.16.90.13',master_user='sync',master_password='syncpwd',master_log_file='mysql-bin.000004',master_log_pos=599;
flush privileges;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;
start slave;

MySQL雙主配置完成,驗(yàn)證配置成功:

show slave status\G #master1中顯示的信息
1. row
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.90.13
Master_User: sync
Master_Port: 3306
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
show slave status\G #master2中顯示的信息
1. row
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.90.14
Master_User: sync
Master_Port: 3306
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

4.Keepalived高可用配置

安裝:yum install -y keepalived
啟動(dòng):systemctl stop keepalived
說明:
當(dāng)兩臺(tái)云服務(wù)器都正常的時(shí)候
用戶寫數(shù)據(jù)默認(rèn)訪問服務(wù)器A,如果A有異常則訪問B服務(wù)器。
用戶讀數(shù)據(jù)默認(rèn)訪問服務(wù)器B,如果B有異常則訪問A服務(wù)器。

服務(wù)器A的寫數(shù)據(jù)初始權(quán)重為100,B為90
服務(wù)器A的讀數(shù)據(jù)初始權(quán)重為90,B為100
檢測(cè)進(jìn)程檢測(cè)到異常時(shí),會(huì)使得本機(jī)的權(quán)重下降20

服務(wù)器A

vrrp_script chk_master1 {
   script "/opt/context/keepalive_check/chk_mysql.sh"
   interval 2       
   weight -20 
}

vrrp_instance VI_MASTER1 {
   state MASTER
   interface eno16780032
   virtual_router_id 51
   priority 100
   mcast_src_ip 172.16.90.13
   advert_int 1
   authentication {
     auth_type PASS
     auth_pass 5678
   }
   virtual_ipaddress {
     172.16.90.15
   }

   track_script {
     chk_master1
   }
}

vrrp_instance VI_MASTER2 {
   state BACKUP
   interface eno16780032
   virtual_router_id 52
   priority 90
   mcast_src_ip 172.16.90.13
   advert_int 1
   authentication {
     auth_type PASS
     auth_pass 15678
   }
   virtual_ipaddress {
     172.16.90.16
   }
}

服務(wù)器B

vrrp_script chk_master2 {
   script "/opt/context/keepalive_check/chk_mysql.sh"
   interval 2
   weight -20
}

vrrp_instance VI_MASTER1 {
   state BACKUP
   interface eno16780032
   virtual_router_id 51
   priority 90
   mcast_src_ip 172.16.90.14
   advert_int 1
   authentication {
     auth_type PASS
     auth_pass 5678
   }
   virtual_ipaddress {
     172.16.90.15
   }
}

vrrp_instance VI_MASTER2 {
   state MASTER
   interface eno16780032
   virtual_router_id 52
   priority 100
   mcast_src_ip 172.16.90.14
   advert_int 1
   authentication {
     auth_type PASS
     auth_pass 15678
   }
   virtual_ipaddress {
     172.16.90.16
   }

   track_script {
     chk_master2
   }
}

檢測(cè)腳本

#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]; then
   systemctl stop keepalived

fi

對(duì)于以上關(guān)于mysql雙主配置講義,如果大家還有更多需要了解的可以持續(xù)關(guān)注我們創(chuàng)新互聯(lián)的行業(yè)推新,如需獲取專業(yè)解答,可在官網(wǎng)聯(lián)系售前售后的,希望該文章可給大家?guī)?lái)一定的知識(shí)更新。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

當(dāng)前名稱:mysql雙主配置講義-創(chuàng)新互聯(lián)
分享路徑:http://www.muchs.cn/article30/dpjppo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作網(wǎng)站導(dǎo)航、虛擬主機(jī)、微信小程序、全網(wǎng)營(yíng)銷推廣、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)