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

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

keepalived雙主以及nginx+keepalived實(shí)現(xiàn)高可用

系統(tǒng)運(yùn)維

一、keepalive實(shí)現(xiàn)雙主:
1.1實(shí)驗準(zhǔn)備
2臺主機(jī)地址分別為:172.20.10.9,172.20.10.10,
vip1為172.20.10.10,vip2為172.20.10.11
1.2通知腳本:

成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),合山企業(yè)網(wǎng)站建設(shè),合山品牌網(wǎng)站建設(shè),網(wǎng)站定制,合山網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,合山網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
[root@node5 /]# vim /etc/keepalived/notify.sh 
#!/bin/bash
contact=\'root@localhost\'
notify() {
    local mailsubject=$(hostname) to be $1, vip floating
    local mailbody=$(date +\'%F %T\'): vrrp transition, $(hostname) changed to be $1
    echo $mailbody | mail -s $mailsubject $contact
}
case $1 in
master)
    notify master
    ;;
backup) 
    notify backup
    ;;   
fault)  notify fault
    ;;  
*)
   echo Usage: $(basename $0) {master|backup|fault}
   exit 1
   ;;
esac

1.3配置node5為vip1地址的主節(jié)點(diǎn),vip2地址的備節(jié)點(diǎn)

[root@node5 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
      root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id node5
   vrrp_mcast_group4 224.0.100.19
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.10.10/28 dev ens33 label ens33:0
    }
   notify_master /etc/keepalived/notify.sh master
   notify_backup /etc/keepalived/notify.sh backup
   notify_fault /etc/keepalived/notify.sh fault
}
vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 52
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.10.11/28 dev ens33 label ens33:1
    }
   notify_master /etc/keepalived/notify.sh master
   notify_backup /etc/keepalived/notify.sh backup
   notify_fault /etc/keepalived/notify.sh fault
}

1.4配置node6為vip1地址的備節(jié)點(diǎn),vip2地址的主節(jié)點(diǎn)

[root@node6 ~]# vim /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
      root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id node5
   vrrp_mcast_group4 224.0.100.19
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.10.10/28 dev ens33 label ens33:0
    }
   notify_master /etc/keepalived/notify.sh master
   notify_backup /etc/keepalived/notify.sh backup
   notify_fault /etc/keepalived/notify.sh fault
}
vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.10.11/28 dev ens33 label ens33:1
    }
   notify_master /etc/keepalived/notify.sh master
   notify_backup /etc/keepalived/notify.sh backup
   notify_fault /etc/keepalived/notify.sh fault
}

1.5驗證:
(1)先開啟node6節(jié)點(diǎn)的keepalived服務(wù),查看IP地址,狀態(tài):
2個VIP地址都在node6節(jié)點(diǎn)上:

(2)再開啟node5節(jié)點(diǎn)keepalived服務(wù),查看IP地址和狀態(tài):
VIP1地址已經(jīng)飄到了node5節(jié)點(diǎn)上了


二,Nginx+Keepalived實(shí)現(xiàn)站點(diǎn)高可用
2.1實(shí)驗準(zhǔn)備:
2臺主機(jī):node5地址為172.20.10.9,node6的節(jié)點(diǎn)為172.20.10.8
vip地址為172.20.10.10
2.2nginx配置
(1)node5節(jié)點(diǎn)

[root@node5 ~]# yum install nginx -y
[root@node5 /]# vim /usr/share/nginx/html/index.html 
node5 web page
[root@node5 ~]# systemctl  start nginx

(2)node6節(jié)點(diǎn)

[root@node6 /]# yum install -y  nginx
[root@node6 /]# vim /usr/share/nginx/html/index.html 
node6 web page
[root@node6 ~]# systemctl  start nginx

2.3配置node5為vip的主節(jié)點(diǎn),配置檢查nginx的監(jiān)控腳本:

[root@node5 /]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
      root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id node5
   vrrp_mcast_group4 224.0.100.19
}
vrrp_script chk_nginx {
    script /usr/bin/killall -0 nginx &&  exit 0 || exit 1 
    interval 1
    weight -5
    fall 2
    rise 1
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.10.10/28 dev ens33 label ens33:0
    }
    track_script {
        chk_nginx
    }
    track_interface {
        ens33
    }
   notify_master /etc/keepalived/notify.sh master
   notify_backup /etc/keepalived/notify.sh backup
   notify_fault /etc/keepalived/notify.sh fault
}
[root@node5 keepalived]# systemctl  start   keepalived

2.4配置node6為vip的備節(jié)點(diǎn),配置檢查nginx的監(jiān)控腳本:

[root@node6 /]# vim /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
global_defs {
   notification_email {
      root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id node5
   vrrp_mcast_group4 224.0.100.19
}
vrrp_script chk_nginx {
    script /usr/bin/killall -0 nginx &&  exit 0 || exit 1 
    interval 1
    weight -5
    fall 2
    rise 1
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.10.10/28 dev ens33 label ens33:0
    }
    track_script {
        chk_nginx
    }
    track_interface {
        ens33
    }
   notify_master /etc/keepalived/notify.sh master
   notify_backup /etc/keepalived/notify.sh backup
   notify_fault /etc/keepalived/notify.sh fault
}
[root@node6 html]# systemctl  start   keepalived

3.驗證:
3.1當(dāng)服務(wù)都正常時,vip地址在node5節(jié)點(diǎn)上,測試訪問172.20.10.10的情況:


3.2當(dāng)down掉node5節(jié)點(diǎn)上nginx服務(wù)時,觀察vip地址和其訪問情況:
vip地址飄到node6節(jié)點(diǎn)上,curl172.20.10.10,則訪問的時node6節(jié)點(diǎn)


3.3當(dāng)恢復(fù)node5節(jié)點(diǎn)上nginx服務(wù)時,vip地址飄到node5節(jié)點(diǎn)上,訪問172.20.10.10則是node5上nginx


當(dāng)前名稱:keepalived雙主以及nginx+keepalived實(shí)現(xiàn)高可用
鏈接分享:http://weahome.cn/article/cjiepd.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部