真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Keepalived1.4.0應(yīng)用在MySQL5.7.19上實(shí)現(xiàn)主備高可用

本文主要給大家介紹Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用,文章內(nèi)容都是筆者用心摘選和編輯的,具有一定的針對(duì)性,對(duì)大家的參考意義還是比較大的,下面跟筆者一起了解下Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用吧。

創(chuàng)新互聯(lián)堅(jiān)實(shí)的技術(shù)研發(fā)基礎(chǔ)贏得了行業(yè)內(nèi)的良好口碑,公司成立十余年來,為上千多家企業(yè)提供過網(wǎng)站建設(shè)、軟件開發(fā)、搜索引擎優(yōu)化技術(shù)、互聯(lián)網(wǎng)大數(shù)據(jù)整合營(yíng)銷服務(wù),多年的技術(shù)服務(wù)成功經(jīng)驗(yàn)、眾多的客戶使我們能懂得更多,做得更好。"讓您的網(wǎng)站跑起來"是我們一直追求的目標(biāo)!

1、基本環(huán)境

JDK 1.8_171
MySQL 5.7.19
CentOS 7.4
Keepalived 1.4.0
DB1:192.168.200.180
DB2:192.168.200.181
VIP: 192.168.200.99
Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用

2、下載安裝Keepalived

2.1、keepalived下載
下載地址:wget http://www.keepalived.org/software/keepalived-1.4.0.tar.gz 
2.2、keepalived安裝

2臺(tái)均按照此種方式進(jìn)行安裝

yum install gcc gcc-c++ make openssl openssl-devel net-snmp-devel psmisc ipvsadm libnfnetlink-devel popt popt-devel popt-static openssl-devel kernel-devel libnl libnl-devel -y    # 安裝依賴

cd /usr/local/src
tar -zvxf keepalived-1.4.0.tar.gz    # 解壓
cd keepalived-1.4.0
./configure --prefix=/usr/local/keepalived --enable-snmp    # 編譯
make && make install    # 安裝
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/    # 拷貝配置
ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
ln -s /usr/local/keepalived/sbin/keepalived /sbin/keepalived
2.3、Keepalived配置

DB1上面的配置:

[root@mysql01 keepalived-1.4.0]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak
[root@mysql01 keepalived-1.4.0]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     nvidiacheng@163.com
   }
   notification_email_from nvidiacheng@163.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id Node_Master
}

vrrp_instance VI_1 {
    state BACKUP          # 可配置master和backup模式,為了防止腦裂現(xiàn)象,主備均需要設(shè)置為backup模式,master模式會(huì)搶占VIP
    interface ens33      # 網(wǎng)卡名
    virtual_router_id 43     # VRRP組名,兩個(gè)節(jié)點(diǎn)的設(shè)置必須一樣,以指明各個(gè)節(jié)點(diǎn)屬于同一VRRP組
    priority 100      # 權(quán)重,主節(jié)點(diǎn)要大于備節(jié)點(diǎn)
    unicast_src_ip  192.168.200.180     # 本地IP地址
    unicast_peer {
                  192.168.200.181     # 對(duì)端IP地址,此地址一定不能忘記
                 }
    nopreempt            # 配合backup,防止切換后,主庫服務(wù)恢復(fù)正常后,IP漂移過來
    advert_int 1          # 組播信息發(fā)送間隔,兩個(gè)節(jié)點(diǎn)設(shè)置必須一樣
    authentication {     # 設(shè)置驗(yàn)證信息,兩個(gè)節(jié)點(diǎn)必須一致
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {   
        192.168.200.99      # VIP地址
    }
}
virtual_server 192.168.200.99 3306 {
    delay_loop 6
    lb_algo wrr          
    lb_kind DR           
    persistence_timeout 50
    protocol TCP

    real_server 192.168.200.180 3306 {
      weight 1
      notify_down /etc/keepalived/mysql.sh 
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3 
      delay_before_retry 3
      connect_port 3306 
        }
    }
}

 
DB2上面配置

[root@mysql02 keepalived-1.4.0]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak
[root@mysql02 keepalived-1.4.0]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived
  global_defs {
      notification_email {
      nvidiacheng@163.com
      }
      notification_email_from nvidiacheng@163.com
      smtp_server 127.0.0.1
      smtp_connect_timeout 30
      router_id Node_backup
     }
 vrrp_instance VI_1 {
      state BACKUP
      interface ens33
      virtual_router_id 43
      priority 90                  
      unicast_src_ip  192.168.200.181
      unicast_peer {
                  192.168.200.180
                   }
      advert_int 1
      authentication {
      auth_type PASS
      auth_pass 1111
      }
      virtual_ipaddress {
      192.168.200.99
      }
      }
 virtual_server 192.168.200.99 3306 {
      delay_loop 2                 
      lb_algo wrr                  
      lb_kind DR                  
      persistence_timeout 60 
      protocol TCP 

      real_server 192.168.200.181 3306{
      weight 1
      notify_down /etc/keepalived/mysql.sh
      echo '3' >  /etc/keepalived/t.log
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3     
      delay_before_retry 3
      connect_port 3306 
      }
      }
}

mysql.sh腳本配置內(nèi)容(2臺(tái)一樣):

[root@mysql01 keepalived]# vim /etc/keepalived/mysql.sh
#!/bin/bash
run_status=`service keepalived status|grep running|wc -l`
pro_status=`ps -ef |grep keepalived|grep -v grep |wc -l`

service keepalived stop

if [ ${run_status} != 0 ] || [ ${pro_status} != 0 ]
then
   pkill keepalived
fi

給mysql.sh賦可執(zhí)行權(quán)限

[root@mysql01 keepalived]# chmod +x mysql.sh

都配置好后啟動(dòng)keepalived進(jìn)行測(cè)試:

service keepalived start   # 啟動(dòng)Keepalived
service keepalived restart   # 重啟Keepalived
service keepalived stop   # 停止Keepalived
service keepalived status   # 查看Keepalived運(yùn)行狀態(tài)
ps aux | grep keepalived   # 查看Keepalived進(jìn)程

Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用

3.3、測(cè)試Keepalived

2臺(tái)均啟動(dòng)Keepalived后,分別查看網(wǎng)卡
Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用
Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用
從上圖可以看出,VIP地址在主節(jié)點(diǎn)
 
使用Navicat工具分別連接2個(gè)節(jié)點(diǎn)和VIP節(jié)點(diǎn)
Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用
這個(gè)時(shí)候我們將節(jié)點(diǎn)1的MySQL停止,模擬主節(jié)點(diǎn)數(shù)據(jù)庫故障來測(cè)試VIP是否會(huì)漂移到備節(jié)點(diǎn)
Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用
如上圖,主節(jié)點(diǎn)MySQL停止后,Keepalived進(jìn)程也結(jié)束了,VIP地址不見了
 
查看備節(jié)點(diǎn)的網(wǎng)卡,發(fā)現(xiàn)VIP已經(jīng)漂移過來了
Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用
 
用Navicat打開VIP,可以正常訪問,主節(jié)點(diǎn)無法打開
Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用
重新啟動(dòng)主節(jié)點(diǎn)MySQL服務(wù)和Keepalived服務(wù),在停止備節(jié)點(diǎn)測(cè)試(略過)

看完以上關(guān)于Keepalived1.4.0應(yīng)用在MySQL 5.7.19上實(shí)現(xiàn)主備高可用,很多讀者朋友肯定多少有一定的了解,如需獲取更多的行業(yè)知識(shí)信息 ,可以持續(xù)關(guān)注我們的行業(yè)資訊欄目的。


分享名稱:Keepalived1.4.0應(yīng)用在MySQL5.7.19上實(shí)現(xiàn)主備高可用
標(biāo)題URL:http://weahome.cn/article/jsijie.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部