中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

keepalived Mysql雙主熱備配置的示例分析

發布時間:2021-11-06 13:45:32 來源:億速云 閱讀:149 作者:小新 欄目:MySQL數據庫

這篇文章主要介紹keepalived Mysql雙主熱備配置的示例分析,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

基于keepalived雙主熱備:
一.環境:
OS:CentOS 6.5 X64
DB Version:Percona Mysql 5.7.15-9-log
路徑:/app/mysql57
數據文件路徑:/data/mysql57/data
DB1:192.168.213.4
DB2:192.168.213.5


二.安裝keepalived包(兩臺主機都需操作)
1.下載keepalived包
cd /usr/local/tools
wget http://www.keepalived.org/software/keepalived-1.2.23.tar.gz


2.安裝所需包
yum -y install openssl-devel


3.安裝keepalived
mkdir -pv /app/keepalived
cd /usr/local/tools
tar xf keepalived-1.2.23.tar.gz
cd keepalived-1.2.23
./configure --prefix=/app/keepalived/
make
make install


4.配置keepalived
cp /app/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /app/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
cp /app/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /app/keepalived/sbin/keepalived /usr/sbin/


db01 keepalived配置
cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
global_defs {
   router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0    !虛擬IP對應接口,也就是業務接口對應的網卡編號
    virtual_router_id 51
    priority 105    !權重
    advert_int 1
    nopreempt    !自己上線后不搶占當前 master 的位置,即使其權重比自己低
    virtual_ipaddress {
        192.168.213.100    !VIP
    }
    track_script {
        chk_mysql    !啟用頭部定義的檢查MySQL狀態的腳本
    }
}
virtual_server 192.168.213.100 3306 {
    delay_loop 3
    lb_algo rr
    lb_kind NAT
    persistence_timeout 60
    protocol TCP    sorry_server 192.168.213.5 3306    ! real_server 掛掉后臨時使用 sorry_server 頂上
    real_server 192.168.213.4 3306 {
        weight 1
        TCP_CHECK {
            connect_port    3306
            connect_timeout 3
        }
    }
}




db02 keepalived配置
[root@ORADB-213-5 ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
global_defs {
   router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0    !虛擬IP對應接口,也就是業務接口對應的網卡編號
    virtual_router_id 51
    priority 100    !權重
    advert_int 1
    nopreempt    !自己上線后不搶占當前 master 的位置,即使其權重比自己低
    virtual_ipaddress {
        192.168.213.100    !VIP
    }
    track_script {
        chk_mysql    !啟用頭部定義的檢查MySQL狀態的腳本
    }
}
virtual_server 192.168.213.100 3306 {
    delay_loop 3
    lb_algo rr
    lb_kind NAT
    persistence_timeout 60
    protocol TCP    sorry_server 192.168.213.4 3306    ! real_server 掛掉后臨時使用 sorry_server 頂上
    real_server 192.168.213.5 3306 {
        weight 1
        TCP_CHECK {
            connect_port    3306
            connect_timeout 3
        }
    }
}


5.兩臺DB啟動keepalived
/etc/init.d/keepalived start


查看VIP
[root@ORA11G-213-4 keepalived-1.2.23]# ip addr
1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c7:d5:27 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.4/24 brd 192.168.213.255 scope global eth0
    inet 192.168.213.100/32 scope global eth0
    inet6 fe80::20c:29ff:fec7:d527/64 scope link 
       valid_lft forever preferred_lft forever
  
測試
[root@ORA11G-213-4 keepalived-1.2.23]# mysql -unetdata -pnetdata -h 192.168.213.100
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2881
Server version: 5.7.15-9-log Source distribution


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


netdata@192.168.213.100 23:41:  [(none)]> system ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:C7:D5:27  
          inet addr:192.168.213.4  Bcast:192.168.213.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fec7:d527/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:156643 errors:0 dropped:0 overruns:0 frame:0
          TX packets:191173 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:39459924 (37.6 MiB)  TX bytes:31911844 (30.4 MiB)


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:17378 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17378 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1002566 (979.0 KiB)  TX bytes:1002566 (979.0 KiB)
 
停止掉db01
[root@ORA11G-213-4 keepalived-1.2.23]# /etc/init.d/mysql57 stop
Shutting down MySQL (Percona Server)............. SUCCESS! 


查看db02
[root@ORADB-213-5 ~]# ip addr
1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:63:54:39 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.5/24 brd 192.168.213.255 scope global eth0
    inet 192.168.213.100/32 scope global eth0
    inet6 fe80::20c:29ff:fe63:5439/64 scope link 
       valid_lft forever preferred_lft forever

以上是“keepalived Mysql雙主熱備配置的示例分析”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

墨脱县| 大悟县| 萨嘎县| 淮北市| 铅山县| 包头市| 华蓥市| 句容市| 大方县| 江都市| 大理市| 车致| 许昌县| 台南市| 会同县| 肃北| 神池县| 钟祥市| 陆丰市| 德昌县| 柳林县| 麦盖提县| 乌鲁木齐市| 射洪县| 汶川县| 平远县| 台州市| 武乡县| 新源县| 石棉县| 集安市| 南和县| 若羌县| 纳雍县| 运城市| 正阳县| 五寨县| 延津县| 沙田区| 四平市| 灵璧县|