vrrp_script高可用httpd&雙主httpd

 

vrrp_script高可用httpd

實驗拓撲:

HA01 192.168.150.137     MASTER

HA02 192.168.150.137     BACKUP

VIP 1921.168.150.131

實驗1:

通過touch一個文件來控制keepalived主機的優先級

HA01的配置腳本,并將此配置文件拷貝至HA02,修改MASTER –>BACKUP和優先級100–>98

! Configuration File or keepalived

global_defs {

   notification_email {

       root@localhost

    }

   notification_email_from kaadmin@void.com

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id node1

    vrrp_mcast_group4 224.0.0.18

}

vrrp_script chk_down {

    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"     條件判斷,當存在down文件時權重-5,此時權重值會為100-5=95<98,此臺主的會變成備的,VIP自然會漂移至HA02

    interval 2     腳本檢查了2秒一次

    weight -5

}

vrrp_instance VI_1 {

    state MASTER

    interface eno33554976

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass Iyd4q2Yg

    }

    virtual_ipaddress {

        192.168.150.131 dev eno33554976 label eno33554976:0

    }

    notify_master "/etc/keepalived/notify.sh master"

    notify_backup "/etc/keepalived/notify.sh backup"

    notify_fault "/etc/keepalived/notify.sh fault"

}

keepalived]# scp keepalived.conf

實驗結果

HA01 touch一個down文件,此時VIP已經漂移至HA02

[root@localhost keepalived]# pwd

/etc/keepalived

[root@localhost keepalived]# touch down

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 52716  bytes 20516695 (19.5 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 71277  bytes 22879699 (21.8 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1018  bytes 84838 (82.8 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1018  bytes 84838 (82.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

HA02狀態:

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 56220  bytes 19985917 (19.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 26414  bytes 2318563 (2.2 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 945  bytes 77031 (75.2 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 945  bytes 77031 (75.2 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

在HA01中將down文件刪除,VIP會漂移回來

[root@localhost keepalived]# rm down

rm:是否刪除普通空文件 "down"?y

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 52656  bytes 20511991 (19.5 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 71227  bytes 22874127 (21.8 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1016  bytes 84732 (82.7 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1016  bytes 84732 (82.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

HA02變成備的

root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 56306  bytes 19991827 (19.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 26450  bytes 2326141 (2.2 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 947  bytes 77137 (75.3 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 947  bytes 77137 (75.3 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

實驗2:

通過腳本檢測httpd服務,如果本機httpd服務停止,VIP漂移

HA01的配置腳本,并將此配置文件拷貝至HA02,修改MASTER –>BACKUP和優先級100–>98

將使用killall -0 httpd來檢測httpd服務是否停止,返回值為0則正常開啟

CentOS7最小安裝無此命令,需要yum安裝

[root@localhost keepalived]# yum -y install psmisc

已加載插件:fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirrors.163.com

 * extras: mirrors.cn99.com

 * updates: mirrors.163.com

正在解決依賴關系

–> 正在檢查事務

—> 軟件包 psmisc.x86_64.0.22.20-9.el7 將被 安裝

–> 解決依賴關系完成

依賴關系解決

=====================================================================================================

 Package               架構                  版本                          源                   大小

=====================================================================================================

正在安裝:

 psmisc                x86_64                22.20-9.el7                   base                140 k

事務概要

=====================================================================================================

安裝  1 軟件包

總下載量:140 k

安裝大小:479 k

Downloading packages:

psmisc-22.20-9.el7.x86_64.rpm                                                 | 140 kB  00:00:00     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在安裝    : psmisc-22.20-9.el7.x86_64                                                        1/1

  驗證中      : psmisc-22.20-9.el7.x86_64                                                        1/1

已安裝:

  psmisc.x86_64 0:22.20-9.el7                                                                       

完畢!

keepalived.conf配置文件

! Configuration File or keepalived

global_defs {

   notification_email {

       root@localhost

    }

   notification_email_from kaadmin@void.com

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id node1

    vrrp_mcast_group4 224.0.0.18

}

vrrp_script chk_down {

    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"

    interval 2

    weight -5

}

vrrp_script chk_httpd {

    script "killall -0 httpd"

    interval 2

    weight 5

}

vrrp_instance VI_1 {

    state MASTER

    interface eno33554976

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass Iyd4q2Yg

    }

    virtual_ipaddress {

        192.168.150.131 dev eno33554976 label eno33554976:0

    }

    track_script {

    chk_down

    chk_httpd

    }

    notify_master "/etc/keepalived/notify.sh master"

    notify_backup "/etc/keepalived/notify.sh backup"

    notify_fault "/etc/keepalived/notify.sh fault"

}

實驗結果:

HA01模擬關閉httpd服務,VIP漂移

[root@localhost keepalived]# killall httpd

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 55077  bytes 20859322 (19.8 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 73759  bytes 23175068 (22.1 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1066  bytes 89212 (87.1 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1066  bytes 89212 (87.1 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

此時HA02狀態

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 56220  bytes 19985917 (19.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 26414  bytes 2318563 (2.2 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 945  bytes 77031 (75.2 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 945  bytes 77031 (75.2 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

HA01開啟httpd服務,VIP還原回來

root@localhost keepalived]# systemctl start httpd.service

您在 /var/spool/mail/root 中有新郵件

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 55188  bytes 20868036 (19.9 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 73816  bytes 23181844 (22.1 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1066  bytes 89212 (87.1 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1066  bytes 89212 (87.1 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 55192  bytes 20868368 (19.9 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 73825  bytes 23183498 (22.1 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1068  bytes 89318 (87.2 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1068  bytes 89318 (87.2 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

此時HA02以備機存在

root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 56306  bytes 19991827 (19.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 26450  bytes 2326141 (2.2 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 947  bytes 77137 (75.3 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 947  bytes 77137 (75.3 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

雙主httpd

實驗拓撲:

HA01:192.168.150.137    為VIP192.168.150.131的主

HA02:192.168.150.140     為VIP192.168.150.132的主

HA01配置

! Configuration File or keepalived

global_defs {

   notification_email {

       root@localhost

    }

   notification_email_from kaadmin@void.com

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id node1

    vrrp_mcast_group4 224.0.0.18

}

vrrp_script chk_down {

    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"

    interval 2

    weight -5

}

vrrp_script chk_httpd {

    script "killall -0 httpd"

    interval 2

    weight 5

}

vrrp_instance VI_1 {     VIP31上此臺為MASTER

    state MASTER

    interface eno33554976

    virtual_router_id 51     router_id為51,要注意與下面的不同

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass Iyd4q2Yg

    }

    virtual_ipaddress {

        192.168.150.131 dev eno33554976 label eno33554976:0

    }

    track_script {

    chk_down

    }

    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 eno33554976

    virtual_router_id 52

    priority 98

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass Iyd4q2Yg

    }

    virtual_ipaddress {

        192.168.150.132 dev eno33554976 label eno33554976:1

    }

    track_script {

    chk_down

    }

    notify_master "/etc/keepalived/notify.sh master"

    notify_backup "/etc/keepalived/notify.sh backup"

    notify_fault "/etc/keepalived/notify.sh fault"

}

HA02配置

! Configuration File or keepalived

global_defs {

   notification_email {

       root@localhost

    }

   notification_email_from kaadmin@void.com

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id node1

    vrrp_mcast_group4 224.0.0.18

}

vrrp_script chk_down {

    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"

    interval 2

    weight -5

}

vrrp_script chk_httpd {

    script "killall -0 httpd"

    interval 2

    weight 5

}

vrrp_instance VI_1 {

    state BACKUP

    interface eno33554976

    virtual_router_id 51

    priority 98

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass Iyd4q2Yg

    }

    virtual_ipaddress {

        192.168.150.131 dev eno33554976 label eno33554976:0

    }

    track_script {

    chk_down

    }

    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 {     在VIP132上,此臺為主

    state MASTER

    interface eno33554976

    virtual_router_id 52     router_id要注意和上面不同

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass Iyd4q2Yg

    }

    virtual_ipaddress {     新的VIP

        192.168.150.132 dev eno33554976 label eno33554976:1

    }

    track_script {

    chk_down

    }

    notify_master "/etc/keepalived/notify.sh master"

    notify_backup "/etc/keepalived/notify.sh backup"

    notify_fault "/etc/keepalived/notify.sh fault"

}

實驗結果:

HA01 touch一個down文件模擬keepalived關閉,兩個VIP會同時在HA02上

[root@localhost keepalived]# touch down

您在 /var/spool/mail/root 中有新郵件

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 57086  bytes 21028080 (20.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 76016  bytes 23409317 (22.3 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1078  bytes 89848 (87.7 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1078  bytes 89848 (87.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

此時HA02狀態

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 60105  bytes 20410322 (19.4 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 28183  bytes 2536438 (2.4 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

eno33554976:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.132  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 977  bytes 78727 (76.8 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 977  bytes 78727 (76.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

HA01進行down文件刪除,VIP31會漂移回來

root@localhost keepalived]# rm down

rm:是否刪除普通空文件 "down"?y

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 57235  bytes 21038952 (20.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 76072  bytes 23416841 (22.3 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1080  bytes 89954 (87.8 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1080  bytes 89954 (87.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

此時的HA02只掛載VIP32

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 60144  bytes 20413106 (19.4 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 28253  bytes 2543988 (2.4 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.132  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 979  bytes 78833 (76.9 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 979  bytes 78833 (76.9 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

HA02 touch一個down文件之后VIP32會漂移至HA01

[root@localhost keepalived]# touch down

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 60190  bytes 20416786 (19.4 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 28282  bytes 2547988 (2.4 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 981  bytes 78939 (77.0 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 981  bytes 78939 (77.0 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

此時HA01狀態,為兩臺主的

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 57262  bytes 21040986 (20.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 76112  bytes 23420885 (22.3 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

eno33554976:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.132  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1082  bytes 90060 (87.9 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1082  bytes 90060 (87.9 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

HA02進行down文件刪除后VIP32恢復過來

[root@localhost keepalived]# rm down

rm:是否刪除普通空文件 "down"?y

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.140  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe85:df69  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

        RX packets 60306  bytes 20425478 (19.4 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 28336  bytes 2555354 (2.4 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.132  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:85:df:69  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 983  bytes 79045 (77.1 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 983  bytes 79045 (77.1 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

HA01也只掛載VIP31

[root@localhost keepalived]# ifconfig

eno33554976: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.137  netmask 255.255.255.0  broadcast 192.168.150.255

        inet6 fe80::20c:29ff:fe87:41fd  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

        RX packets 57308  bytes 21044312 (20.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 76162  bytes 23425957 (22.3 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554976:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.150.131  netmask 255.255.255.255  broadcast 0.0.0.0

        ether 00:0c:29:87:41:fd  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 1084  bytes 90166 (88.0 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1084  bytes 90166 (88.0 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

原創文章,作者:N23-蘇州-void,如若轉載,請注明出處:http://www.www58058.com/62915

(0)
N23-蘇州-voidN23-蘇州-void
上一篇 2016-12-06
下一篇 2016-12-07

相關推薦

  • 第一次發微博

    第一次申請微博,第一次發微博,覺得很難

    Linux干貨 2017-01-06
  • NoSQL之MongoDB

    分布式系統理論 1、 CAP: 分布式系統只能滿足其中兩個? Consistency :一致性 Availibility:可用性 Partitions Tolerance :分區容錯性 C,A : SQL 傳統的數據庫。 兩段機制。 C,P :悲觀枷鎖機制,分布式加鎖機制。加鎖機制與SQL不太一樣。 這里的C為最終一致性。 放棄C后的特例,既可以保證可用性,…

    2018-01-09
  • Ansible淺談

    ansible特性:         模塊化,調用特定的模塊,完成特定的任務;         基于Python語言實現,由Paramiko、PyYAML和Jinja2三個關鍵模塊;         部署簡單,agentless; &nbs…

    Linux干貨 2016-12-15
  • 管理分區和文件系統及掛載設備

    管理分區 列出塊設備 lsblk       分區工具fdisk fdisk -l /dev/sdX 查看硬盤分區信息 CentOS7: fdisk -l /dev/sda 默認開啟dos及扇區顯示模式    開啟dos及柱面顯示模式:fdisk -c=dos -u=cylinders -l /dev/sda…

    2017-08-26
  • bond的常見使用方式和問題

    bond的簡單建立于事項

    2017-09-09
  • 基于heartbeat v2 crm實現基于nfs的mysql高可用集群

    前言 因heartbeat v1內置的資源管理器haresource功能比較簡單,且不支持圖形化管理,所以heartbeat v2不再支持haresource,轉而使用更加強大的資源管理器crm進行集群管理。本文將講解如何基于heartbeat v2 crm實現基于nfs的mysql高可用集群。 高可用實現 實驗拓撲 實驗環境 node1:172.16.10…

    Linux干貨 2015-06-11

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-12-09 19:36

    如果再加上一些說明,是什么,為什么就更好了

欧美性久久久久