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

相关推荐

  • 2016 10 19 第5天作业

    20161019第5天作业 软链接和硬链接的区别 硬链接 ①硬链接文件不能跨分区创建 ②一个硬链接文件的删除不影响其他链接的访问 ③链接文件指向的源文件被删除后,链接文件还能正常访问源文件的数据 ④硬链接的文件类型是 –  普通文件 ⑤硬链接和源文件的属性(大小,权限,时间戳,Inode号)相同 ⑥硬链接不能对目录创建 ⑦创建硬链接会增…

    Linux干货 2016-10-20
  • 马哥教育网络班第19期+第8周课程练习

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 网桥:一种网路装置,负责网路桥接,将网络的多个网段在数据链路层连接起来。 集线器:将多条以太网线或光纤集合连接在同一段物理介质下的装置。工作在物理层。 二层交换机:工作在数据链路层,交换机内部的CPU会在每个端口成功连接时,通过将MAC地址和端口对应,形成一张MAC表。在今后的通…

    Linux干货 2016-08-22
  • 集中管理利器-puppet快速入门-下

    Puppet配置 1.    文件管理 file 文件服务器写法: /etc/puppet/ fileserver.conf 定义 [files] path /tmp/files  ## puppet数据存放目录 =è后面远程备份实战会用到 allow *.example.com 实战1: 备份master机…

    Linux干货 2015-05-07
  • Linux运维学习历程-第四天-Linux的使用帮助和快捷键

    本章内容     命令存放位置     命令帮助      help     man帮助     其它帮助        命令历史     快捷键 一、命令存放位置   &nbsp…

    Linux干货 2016-08-03
  • sed命令使用

    一、sed简介    sed是一种在线编辑器,一次处理一行内容。处理时,把当前处理的行存储在历史缓冲区,传给“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非使用重定向存储输出。sed主要用来自动编辑一个或…

    Linux干货 2016-08-12
  • Week1: Linux 初步

    1. 描述计算机的组成及其功能 一个完整的计算机系统由硬件系统和软件系统两大部分组成 冯诺依曼体系下的计算机五大部件 CPU:运算器、控制器、寄存器、缓存(一二三级缓存)) 存储器:内存 RAM(Random-Access Memory) Input:输入指令、提供数据 Output: 输出数据加工后的结果 要点:计算机中的信息(程序和数据)以二进制方式表示…

    Linux干货 2016-12-04

评论列表(1条)

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

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