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
下一篇 2016-12-07

相关推荐

  • TCP连接的状态转移

    TCP是一个面向连接的传输层协议,因此不论哪一方需要传输数据,都需要在双方之间建立一条传输连接。 用TCP的三次握手与四次挥手来解释TCP的各个状态之间的会比较清晰。 一、TCP的三次握手: a)         单方主动发起连接: 1、  服务器端应用层的应用程序创建…

    2017-03-19
  • 8.10 shell scripts 作业

    1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 [root@CentOs6 bin]# systeminfo.sh        Hostname:&n…

    Linux干货 2016-08-12
  • 逻辑卷的创建、维护和迁移

    逻辑卷管理器(LVM)介绍: 1、允许对卷进行方便操作的抽象层,包括重新设定文件系统的大小 2、允许在多个物理设备间重新组织文件系统 (1)将设备指定为物理卷 (2)用一个或者多个物理卷来创建一个卷组 (3)物理卷是用固定大小的物理区域(Physical Extent,PE)来 定义的 (4)在物理卷上创建的逻辑卷 是由物理区域(PE)组成 (5)可以在逻辑…

    Linux干货 2017-12-10
  • Linux虚拟网络接口-Bonding 配置

    一、bonding 的定义     bonding是通过将同一设备的多个物理网卡绑定到一个虚拟网卡上,再对外提供连接。对于外端来说,多个物理网卡共享虚拟网卡的IP和mac地址,也就表现为一个网卡设备。通过bonding技术可以实现高可用或者负载均衡。     bonding有7种工作模式:&nbsp…

    Linux干货 2017-07-02
  • 0811:脚本练习

    系统信息获取脚本 1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 [root@centos7 scripts]#cat systeminfo.sh  #!/usr/bin/bash  server_ip…

    Linux干货 2016-08-22

评论列表(1条)

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

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