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.178linux.com/62915

(0)
N23-苏州-voidN23-苏州-void
上一篇 2016-12-06 21:14
下一篇 2016-12-07 11:03

相关推荐

  • ubuntu kylin虚拟机安装KVM

    1.确定物理机CPU是否支持虚拟化    查看方法1:计算机->属性->处理器(Inter(R) Core(TM) i5-2450M),然后去网上查看自己的电脑CPU是否支持虚拟化,    地址http://ark.intel.com/zh-cn/找到自己CPU的信息,虚拟化技术后是否显示为yes,如果是n…

    Linux干货 2016-10-15
  • 马哥教育网络班22期+第三周课程练习

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [xw@localhost ~]$ who | cut -d' ' -f1 | uniq xw root 2、取出最后登录到当前系统的用户的相关信息。 [xw…

    Linux干货 2016-09-01
  • varnish

    缓存 缓存之所以能够生效是程序的运行具有局部性特征: 时间局部性:一个数据被访问过之后,可能很快会被再次访问到; 空间局部性:一个数据被访问时,其周边的数据也有可能被访问到 缓存的是热区数据 时效性: 缓存空间耗尽:LRU,最近最少使用; 过期:缓存清理 缓存命中率:hit/(hit+miss) 页面命中率:基于页面数量进行衡量 字节命中率:基于页面的体积进…

    Linux干货 2017-07-03
  • 数组和变量之间的关系及如何灵活运用数组

    什么是数组?数组:存储多个元素的连续的内存空间,相当于多个变量的集合什么是变量? 变量即是存储单个元素的内存空间 如果整个数组只有一个名字;数组名是数组的标识;也是数组所指向的存储多个元素的连续的内存空间开始地址的标识;数组索引定义从 0 开始(第一个数组元素);到 N 结束引用某个数组元素时,数组名+【索引】格式:${ARRAY_NAM…

    Linux干货 2017-05-22
  • keepalive配置文件详解

    第一部分:全局定义块 1、email通知。作用:有故障,发邮件报警。 2、Lvs负载均衡器标识(lvs_id)。在一个网络内,它应该是唯一的。 3、花括号“{}”。用来分隔定义块,因此必须成对出现。如果写漏了,keepalived运行时,不会得到预期的结果。由于定义块内存在嵌套关系,因此很容易遗漏结尾处的花括号,这点要特别注意。 global_defs{ n…

    2017-09-17
  • 中文man安装手册

      首先需要确认的是有没有安装中文支持,如果没有请安装:#yum groupinstall -y "Chinese Support" 现在下载安装包: wget http://manpages-zh.googlecode.com/files/manpages-zh-1.5.1.tar.gz  (这个wget是直接网页下…

    系统运维 2016-01-13

评论列表(1条)

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

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