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

相关推荐

  • Linux系统程序包管理之RPM

    rpm包概述 RPM 是 Red at Package Manager 的缩写,本意是Red Hat 软件包管理,顾名思义是Red Hat 贡献出来的软件包管理工具;在Fedora 、Redhat、Mandriva、SuSE、YellowDog等主流发行版本,以及在这些版本基础上二次开发出来的发行版采用。 RPM包里面都包含什么?里面包含可执行的二进制程序,…

    Linux干货 2016-08-24
  • 文本处理工具sed、vim

    文本处理工具sed、vim 一、sed的使用 1、sed的概念 sed简单地说sed是一种行处理工具。 sed 是一种流性的行编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space ),接着用sed 命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末…

    Linux干货 2016-08-11
  • 学习笔记–文本处理工具

    Linux下有很多文本处理工具,本文将介绍几款比较常用的文本处理工具,比如对文本查看的工具:cat和less,文本截取工具:head和tail,按列抽取文本工具:cut,按关键字查询文本工具:grep,下面将具体介绍各种工具的使用。 1、文本查看命令cat 用法: cat [OPTION]… [FILE]… cat命令一次性…

    Linux干货 2016-08-07
  • 每天一个Linux命令

        程序管理:      程序的组成部分:二进制程序文件,库文件,配置文件,帮助文件。                      二进制和库文件可执行,库文件不能独立执行,只能被调用时执…

    Linux干货 2017-04-08
  • linux的发展形成杂谈

    纵观linux的发展,可以看得出Linux是那个时代的产物,是操作系统群雄并起时候的真名天子。从1945年第一台计算机发明开始,人民就开始产生了对操作的系统的需求,首先是单个命令的输入,然后是单批次工作的产生,之后就是多批次流程的产生,然后就是多任务多批次流程,人民一直一直不懈的努力研发一个真正意义上的操作系统。 终于,在70年代,大神级的人物KenThom…

    Linux干货 2016-10-31
  • 使用NFS共享网页文件

    上图为我们要搭建的网络拓扑图 本次实验目的:使用NFS文件服务来实现wordpress共享 实验环境: 需要三台虚拟机:         分别是:192.168.26.188(服务器端)          &n…

    2017-05-01

评论列表(1条)

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

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