最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL雙主搭建+keepalived高可用的實(shí)現(xiàn)

 更新時(shí)間:2025年04月03日 11:05:12   作者:zongzizz  
本文主要介紹了MySQL雙主搭建+keepalived高可用的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

一、測(cè)試環(huán)境準(zhǔn)備

節(jié)點(diǎn)1節(jié)點(diǎn)2
IP地址192.168.101.77192.168.101.79
MySQL版本8.0.328.0.32

二、主從搭建

1.創(chuàng)建復(fù)制用戶

節(jié)點(diǎn)1執(zhí)行:

mysql> CREATE USER 'repl'@'%' IDENTIFIED  BY '123123';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
mysql> FLUSH PRIVILEGES;
mysql> show master status;

2.創(chuàng)建復(fù)制關(guān)系

節(jié)點(diǎn)2執(zhí)行

mysql> 
change master to    
master_host='192.168.101.77',    
MASTER_PORT=3306,    
master_user='repl',  
master_password='123123' ,  
MASTER_AUTO_POSITION=1;

3.開啟復(fù)制,確認(rèn)復(fù)制是否成功

開啟復(fù)制
mysql> start slave;
查看復(fù)制狀態(tài)(下面是正常狀態(tài))
root@localhost:(none)>show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 192.168.101.77
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000007
          Read_Master_Log_Pos: 197
               Relay_Log_File: localhost-relay-bin.000004
                Relay_Log_Pos: 413
        Relay_Master_Log_File: mysql-bin.000007
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 197
              Relay_Log_Space: 2098
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 1
                  Master_UUID: f6ca767b-2144-11ee-80e4-080027a4fdbc
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: f6ca767b-2144-11ee-80e4-080027a4fdbc:4-8
            Executed_Gtid_Set: f6ca767b-2144-11ee-80e4-080027a4fdbc:1-8
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set, 1 warning (0.00 sec)

可在節(jié)點(diǎn)1插入數(shù)據(jù),然后在節(jié)點(diǎn)2查詢數(shù)據(jù)是否同步,確定同步是否正常。

4.同步排錯(cuò)

報(bào)錯(cuò)1:

Last_IO_Error: error connecting to master 'repl@192.168.101.77:3306' - retry-time: 60 retries: 21 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.

解決方法:

ALTER USER 'repl'@'%' IDENTIFIED WITH mysql_native_password  BY '123123';

報(bào)錯(cuò)2:

Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Cannot replicate because the master purged required binary logs. Replicate the missing transactions from elsewhere, or provision a new slave from backup. Consider increasing the master's binary log expiration period. The GTID set sent by the slave is '75433121-6a95-11ef-8b71-080027123ed0:1-3', and the missing transactions are 'f6ca767b-2144-11ee-80e4-080027a4fdbc:1-3''

解決方法:

root@localhost:(none)>stop slave;
Query OK, 0 rows affected, 1 warning (0.11 sec)

root@localhost:(none)>reset master;
Query OK, 0 rows affected (0.10 sec)

root@localhost:(none)>reset slave;
Query OK, 0 rows affected, 1 warning (0.20 sec)

root@localhost:(none)>set @@GLOBAL.GTID_PURGED='f6ca767b-2144-11ee-80e4-080027a4fdbc:1-3';
Query OK, 0 rows affected (0.06 sec)

root@localhost:(none)>start slave;
Query OK, 0 rows affected, 1 warning (0.10 sec)

三、雙主配置

雙主配置也就是將上面的主從操作反向操作一遍。

1.創(chuàng)建復(fù)制用戶

mysql> CREATE USER 'repl1'@'%' IDENTIFIED  BY '123123';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl1'@'%';
mysql> FLUSH PRIVILEGES;
mysql> show master status;

2.創(chuàng)建復(fù)制關(guān)系

mysql>
change master to
master_host='192.168.101.79',
MASTER_PORT=3306,
master_user='repl',
master_password='123123' ,
MASTER_AUTO_POSITION=1; 

3.開啟復(fù)制,確認(rèn)復(fù)制是否成功

mysql> start slave;
mysql>show slave status \G;

4.雙主測(cè)試

節(jié)點(diǎn)1插入數(shù)據(jù),節(jié)點(diǎn)2查詢
節(jié)點(diǎn)2插入數(shù)據(jù),節(jié)點(diǎn)1查詢

四、keepalived配置

1.keepalived安裝、啟停操作

yum -y install keepalived
systemctl status keepalived
systemctl start keepalived
systemctl stop keepalived

2.keepalived配置文件

vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
    notification_email {
      acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
    notification_email_from Alexandre.Cassen@firewall.loc
   router_id MYCAT_HA # 定義名稱
}
vrrp_script chk_mycat_alive {
    script "/etc/keepalived/mysql_check.sh"    # 返回狀態(tài)碼為0表示正常,檢測(cè)腳本為true;返回狀態(tài)碼非0表示異常,檢測(cè)腳本為false
    interval 2                                 # 檢測(cè)腳本執(zhí)行的間隔,單位是秒
    weight 20
}
vrrp_instance VI_1 {
      state MASTER     #主節(jié)點(diǎn)為MASTER,備節(jié)點(diǎn)為BACKUP
      interface enp0s3    #根據(jù)實(shí)際網(wǎng)卡名配置
      virtual_router_id 88
      priority 100
      advert_int 1
      authentication {
         auth_type PASS
         auth_pass qwert
    }
    track_script {
        chk_mycat_alive            # 調(diào)用檢測(cè)腳本
    }
   virtual_ipaddress {
         192.168.101.199/24            # 定義虛擬ip(VIP)
    }
}

3.keepalived配置文件

服務(wù)狀態(tài)檢查腳本

cat /etc/keepalived/mysql_check.sh
#!/bin/bash
count=`ps -C mysqld --no-heading|wc -l`
time=$(date "+%Y-%m-%d %H:%M:%S")
if [ $count = 0 ]; then
    echo "$time : count=$count, mysql is not running..." >> /var/log/keepalived_check.log
    exit 1 # 返回1說(shuō)明腳本非正常執(zhí)行,mysql不在運(yùn)行中
else
    echo "$time : count=$count, mysql is running..." >> /var/log/keepalived_check.log
    exit 0 # 返回0說(shuō)明腳本正常執(zhí)行,mysql正在運(yùn)行中
    fi

4.keepalived配置成功

配置完成后可在其中一節(jié)點(diǎn)上看到虛擬地址,同網(wǎng)段也可以ping通虛擬地址,同時(shí)也可以通過(guò)虛擬地址連接上數(shù)據(jù)庫(kù)。

在這里插入圖片描述

在這里插入圖片描述

五、集群狀態(tài)測(cè)試

兩節(jié)點(diǎn)物理地址均可連接數(shù)據(jù)庫(kù),也可通過(guò)虛擬地址連接數(shù)據(jù)庫(kù),下面我們測(cè)試一下關(guān)閉一臺(tái)服務(wù)器(虛擬地址所服務(wù)器)測(cè)試是否還是可通過(guò)虛擬地址連接數(shù)據(jù)庫(kù)。

在這里插入圖片描述

節(jié)點(diǎn)2關(guān)機(jī)后虛擬地址跑到節(jié)點(diǎn)1上去了,測(cè)試用虛擬地址連接數(shù)據(jù)庫(kù)依然可以連接

在這里插入圖片描述

在這里插入圖片描述

重新啟動(dòng)節(jié)點(diǎn)2后,啟動(dòng)數(shù)據(jù)庫(kù)即可拉起雙主集群

到此這篇關(guān)于MySQL雙主搭建+keepalived高可用的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)MySQL雙主搭建+keepalived高可用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解MySQL集群搭建

    詳解MySQL集群搭建

    本文將搭建一個(gè)最簡(jiǎn)化的MySQL Cluster系統(tǒng),配置方法中的所有命令都是以root賬戶運(yùn)行。
    2015-09-09
  • MySQL+keepalived主主復(fù)制完整部署流程

    MySQL+keepalived主主復(fù)制完整部署流程

    MySQL主主復(fù)制結(jié)合Keepalived實(shí)現(xiàn)高可用性,是一種常見的數(shù)據(jù)庫(kù)架構(gòu)方案,這篇文章主要介紹了MySQL+keepalived主主復(fù)制的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-12-12
  • MySQL中如何開啟二進(jìn)制日志(Binlog)

    MySQL中如何開啟二進(jìn)制日志(Binlog)

    本文詳細(xì)介紹了如何在不同操作系統(tǒng)(Windows、Linux、Docker)下開啟MySQL的二進(jìn)制日志(Binlog),包括停止MySQL服務(wù)、編輯配置文件、創(chuàng)建日志文件目錄、啟動(dòng)服務(wù)以及驗(yàn)證Binlog是否開啟
    2025-03-03
  • MySQL徹底禁止用戶執(zhí)行KILL的解決方法

    MySQL徹底禁止用戶執(zhí)行KILL的解決方法

    在?MySQL?中,即使用戶只有?SELECT?權(quán)限,仍然可以執(zhí)行?SHOW?PROCESSLIST?和?KILL?命令,那么如何徹底禁止用戶執(zhí)行?KILL?本文給大家詳細(xì)介紹了MySQL徹底禁止用戶執(zhí)行KILL的解決方法,需要的朋友可以參考下
    2025-05-05
  • 深度解析MySQL啟動(dòng)時(shí)報(bào)“The server quit without updating PID file”錯(cuò)誤的原因

    深度解析MySQL啟動(dòng)時(shí)報(bào)“The server quit without up

    這篇文章主要介紹了MySQL啟動(dòng)時(shí)報(bào)“The server quit without updating PID file”錯(cuò)誤的原因,需要的朋友可以參考下
    2017-05-05
  • MySQL覆蓋索引和索引跳躍掃描方式

    MySQL覆蓋索引和索引跳躍掃描方式

    這篇文章主要介紹了MySQL覆蓋索引和索引跳躍掃描方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-05-05
  • Linux上通過(guò)binlog文件恢復(fù)mysql數(shù)據(jù)庫(kù)詳細(xì)步驟

    Linux上通過(guò)binlog文件恢復(fù)mysql數(shù)據(jù)庫(kù)詳細(xì)步驟

    binglog文件是服務(wù)器的二進(jìn)制日志記錄著該數(shù)據(jù)庫(kù)的所有增刪改的操作日志,接下來(lái)通過(guò)本文給大家介紹linux上通過(guò)binlog文件恢復(fù)mysql數(shù)據(jù)庫(kù)詳細(xì)步驟,非常不錯(cuò),需要的朋友參考下
    2016-08-08
  • mysql觸發(fā)器簡(jiǎn)介、創(chuàng)建觸發(fā)器及使用限制分析

    mysql觸發(fā)器簡(jiǎn)介、創(chuàng)建觸發(fā)器及使用限制分析

    這篇文章主要介紹了mysql觸發(fā)器簡(jiǎn)介、創(chuàng)建觸發(fā)器及使用限制,結(jié)合實(shí)例形式分析了mysql觸發(fā)器的功能、原理、創(chuàng)建、用法及操作注意事項(xiàng),需要的朋友可以參考下
    2019-12-12
  • mysql隨機(jī)查詢10條數(shù)據(jù)的三種方法

    mysql隨機(jī)查詢10條數(shù)據(jù)的三種方法

    本文主要介紹了mysql隨機(jī)查詢10條數(shù)據(jù)的三種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • Linux CentOS MySQL數(shù)據(jù)庫(kù)安裝配置教程

    Linux CentOS MySQL數(shù)據(jù)庫(kù)安裝配置教程

    這篇文章主要為大家詳細(xì)介紹了Linux CentOS MySQL數(shù)據(jù)庫(kù)的安裝配置教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05

最新評(píng)論

吉安县| 雅江县| 垦利县| 布尔津县| 广宁县| 凭祥市| 富源县| 获嘉县| 芒康县| 长治县| 乌海市| 永安市| 勃利县| 新余市| 夏津县| 麻江县| 延安市| 阳江市| 沂源县| 乐亭县| 灵台县| 华阴市| 咸丰县| 玉山县| 文化| 略阳县| 安阳县| 江山市| 琼海市| 敖汉旗| 惠州市| 丰原市| 沁阳市| 阜城县| 南雄市| 红桥区| 上思县| 安福县| 潮安县| 九龙城区| 井研县|