lvs 一个网卡单个管理ip,多个跨网段VIP解决办法

说明:lvs的vip和realserver的rip是可以跨网段的

ifconfig输出如下:

[[email protected] scripts]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:50:56:84:86:FB  
          inet6 addr: fe80::250:56ff:fe84:86fb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7492562 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4443845 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:474201572 (452.2 MiB)  TX bytes:246936351 (235.4 MiB)

eth0.200  Link encap:Ethernet  HWaddr 00:50:56:84:86:FB  
          inet6 addr: fe80::250:56ff:fe84:86fb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:936 (936.0 b)

eth0.1016 Link encap:Ethernet  HWaddr 00:50:56:84:86:FB  
          inet addr:172.24.130.113  Bcast:172.24.130.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe84:86fb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7446938 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3145054 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:367240583 (350.2 MiB)  TX bytes:176803005 (168.6 MiB)

eth0.1025 Link encap:Ethernet  HWaddr 00:50:56:84:86:FB  
          inet6 addr: fe80::250:56ff:fe84:86fb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45600 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1298779 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2106209 (2.0 MiB)  TX bytes:70132410 (66.8 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1024962 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1024962 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:72580466 (69.2 MiB)  TX bytes:72580466 (69.2 MiB)

[[email protected] scripts]#

ip a输出如下:

[[email protected] scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
9: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
11: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet 172.24.130.113/24 brd 172.24.130.255 scope global eth0.1016
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
12: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
[[email protected] scripts]#

最终效果如下:

[[email protected] ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
9: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
11: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet 172.24.130.113/24 brd 172.24.130.255 scope global eth0.1016
    inet 172.24.130.5/32 scope global eth0.1016
    inet 172.24.130.6/32 scope global eth0.1016
    inet 172.24.130.7/32 scope global eth0.1016
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
12: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 00:50:56:84:86:fb brd ff:ff:ff:ff:ff:ff
    inet 172.24.25.5/32 scope global eth0.1025
    inet 172.24.25.6/32 scope global eth0.1025
    inet 172.24.25.7/32 scope global eth0.1025
    inet6 fe80::250:56ff:fe84:86fb/64 scope link 
       valid_lft forever preferred_lft forever
[[email protected] ~]#

keepalived配置文件如下:

[[email protected] ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
        notification_email {
        [email protected]
        }
        #notification_email_from [email protected]
        #smtp_server 127.0.0.1
        #smtp_connect_timeout 30
        router_id 980124
}
vrrp_sync_group VG_1 {
        group {
                VI_1
                VI_11
        }
}
vrrp_sync_group VG_2 {
        group {
                VI_2
                VI_21
        }
}
vrrp_sync_group VG_3 {
        group {
                VI_3
                VI_31
        }
}
vrrp_instance VI_1 {
        state MASTER
        interface eth0.1016  ##指定vrrp网卡
        virtual_router_id 50
        priority 150
        nopreempt # no seize,master must add
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 123456
        }
        virtual_ipaddress {
        172.24.130.5 dev eth0.1016
        }
        notify_master /etc/keepalived/scripts/state_master.sh
        notify_backup /etc/keepalived/scripts/state_backup.sh
        notify_fault  /etc/keepalived/scripts/state_fault.sh
}
vrrp_instance VI_11 {
        state MASTER
        interface eth0.1016  ##指定vrrp网卡
        virtual_router_id 150
        priority 150
        nopreempt # no seize,master must add
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 123456
        }
        virtual_ipaddress {
        172.24.25.5 dev eth0.1025
        }
        notify_master /etc/keepalived/scripts/state_master.sh
        notify_backup /etc/keepalived/scripts/state_backup.sh
        notify_fault  /etc/keepalived/scripts/state_fault.sh
}
virtual_server 172.24.130.5 53 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        persistence_timeout 50
        #sorry_server 127.0.0.1 53
        protocol UDP

        real_server 172.24.130.115 53 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        MISC_CHECK {
                misc_timeout 10
                #connect_timeout 3
                #nb_get_retry   3
                #retry   3
                #delay_before_retry 3
                misc_path "/usr/local/keepalived/UDP_CHECK.sh 172.24.130.115 53" 
                }
        }
        real_server 172.24.130.116 53 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        MISC_CHECK {
                misc_timeout 10
                #connect_timeout 3
                #nb_get_retry   3
                #retry   3
                #delay_before_retry 3
                misc_path "/usr/local/keepalived/UDP_CHECK.sh 172.24.130.116 53" 
                }
        }
}
virtual_server 172.24.25.5 53 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        persistence_timeout 50
        #sorry_server 127.0.0.1 53
        protocol UDP

        real_server 172.24.130.115 53 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        MISC_CHECK {
                misc_timeout 10
                #connect_timeout 3
                #nb_get_retry   3
                #retry   3
                #delay_before_retry 3
                misc_path "/usr/local/keepalived/UDP_CHECK.sh 172.24.130.115 53" 
                }
        }
        real_server 172.24.130.116 53 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        MISC_CHECK {
                misc_timeout 10
                #connect_timeout 3
                #nb_get_retry   3
                #retry   3
                #delay_before_retry 3
                misc_path "/usr/local/keepalived/UDP_CHECK.sh 172.24.130.116 53" 
                }
        }
}
vrrp_instance VI_2 {
        state  MASTER
        interface eth0.1016  ##指定vrrp网卡
        virtual_router_id 51
        priority 150
        nopreempt # no seize,master must add
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 123456
        }
        virtual_ipaddress {
        172.24.130.6 dev eth0.1016 
        }
        notify_master /etc/keepalived/scripts/state_master.sh
        notify_backup /etc/keepalived/scripts/state_backup.sh
        notify_fault  /etc/keepalived/scripts/state_fault.sh
}
vrrp_instance VI_21 {
        state  MASTER
        interface eth0.1016  ##指定vrrp网卡
        virtual_router_id 151
        priority 150
        nopreempt # no seize,master must add
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 123456
        }
        virtual_ipaddress {
        172.24.25.6 dev eth0.1025
        }
        notify_master /etc/keepalived/scripts/state_master.sh
        notify_backup /etc/keepalived/scripts/state_backup.sh
        notify_fault  /etc/keepalived/scripts/state_fault.sh
}
virtual_server 172.24.130.6 80 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        persistence_timeout 50
        #sorry_server 127.0.0.1 53
        protocol TCP

        real_server 172.24.130.117 80 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 80
                }
        }
        real_server 172.24.130.118 80 {
        weight 0
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 80
                }
        }
}
virtual_server 172.24.25.6 80 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        persistence_timeout 50
        #sorry_server 127.0.0.1 53
        protocol TCP

        real_server 172.24.130.117 80 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 80
                }
        }
        real_server 172.24.130.118 80 {
        weight 0
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 80
                }
        }
}
vrrp_instance VI_3 {
        state  MASTER
        interface eth0.1016  ##指定vrrp网卡
        virtual_router_id 52
        priority 150
        nopreempt # no seize,master must add
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 123456
        }
        virtual_ipaddress {
        172.24.130.7 dev eth0.1016 
        }
        notify_master /etc/keepalived/scripts/state_master.sh
        notify_backup /etc/keepalived/scripts/state_backup.sh
        notify_fault  /etc/keepalived/scripts/state_fault.sh
}
vrrp_instance VI_31 {
        state  MASTER
        interface eth0.1016  ##指定vrrp网卡
        virtual_router_id 152
        priority 150
        nopreempt # no seize,master must add
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 123456
        }
        virtual_ipaddress {
        172.24.25.7 dev eth0.1025
        }
        notify_master /etc/keepalived/scripts/state_master.sh
        notify_backup /etc/keepalived/scripts/state_backup.sh
        notify_fault  /etc/keepalived/scripts/state_fault.sh
}
virtual_server 172.24.130.7 10051 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        persistence_timeout 50
        #sorry_server 127.0.0.1 53
        protocol TCP

        real_server 1.1.1.1 10051 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 10051
                }
        }
        real_server 1.1.1.2 10051 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 10051
                }
        }
}
virtual_server 172.24.25.7 10051 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        persistence_timeout 50
        #sorry_server 127.0.0.1 53
        protocol TCP

        real_server 1.1.1.1 10051 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 10051
                }
        }
        real_server 1.1.1.2 10051 {
        weight 100
        #notify_up up.sh
        #notify_down down.sh
        TCP_CHECK {
                connect_timeout 3
                #nb_get_retry   3
                retry   3
                delay_before_retry 3
                connect_port 10051
                }
        }
}
[[email protected] ~]#

参考:https://github.com/acassen/keepalived/issues/445

时间: 2024-11-10 21:10:30

lvs 一个网卡单个管理ip,多个跨网段VIP解决办法的相关文章

烂泥:更换ESXI5.0管理网卡及管理IP地址

本文首发于烂泥行天下. 公司的服务器基本上都是在IDC机房里面的,为了更有效的利用服务器性能.所以有几台服务器,安装的是ESXI5.0做成虚拟化. 注意目前这些服务器都是双网卡的. 因为不是自己安装的ESXI,都是机房那边安装好,然后把ESXI管理IP以及密码告诉我.然后我远程连接管理虚拟机,所以机房那边,把这几台服务器的ESXI管理IP地址全部配置为公网IP. 这对于公司来说就是一种浪费,因为公网IP本来就是需要花钱购买的.所以就打算把这个IP地址更换为私网IP,节省的这个公网IP就可以做其他

如何把php项目部署到阿里云服务器window server2012__含公网ip访问时jquery/ajax失效解决办法

记一次蛋疼的折腾. 弄了一晚上最后发觉是360浏览器的问题,换个浏览器就好了.垃圾360用什么IE7文档模式.导致界面和功能失效. 建议大家测试的时候用firefox或者chrome. 项目部署到服务器后360浏览器兼容模式显示错误的解决办法:http://www.cnblogs.com/zj917/p/6697724.html -------------------------------------------------- 正文: 上篇博客说临时起意做了个有意思的聊天版,就想把它部署到阿里

HTTP中ip地址伪造的问题以及解决办法

在真实环境下,php获取客户端ip地址的方法通常有以下几种: (1):通过$_SERVER[ "HTTP_CLIENT_IP" ] (2):通过$_SERVER[ "HTTP_X_FORWARDED_FOR" ] (3):通过$_SERVER[ "REMOTE_ADDR" ] 这里需要注意的是:在php中的$_SERVER数组中以HTTP开头的值,都是由客户端(client)传递到服务端的,也就是说这一部分是可以进行伪造的.而$_SERVER[

关于用IOU虚拟机开始界面无法显示IP及ifconfig显示问题的解决办法

一.LINUX内相关操作 开启iou-web虚拟机.会发现作者制作的是Scientific Linux.登录信息,用户名root,密码cisco. 用root权限操作 网卡配置 1.初始化网卡相关文件 Rm /etc/udev/rules.d/70-persistent-net.rules Or Rm –f /etc/udev/rules.d/70-persistent-net.rules 然后init 6  重启 2.配置网卡IP及模式 Vi /etc/sysconfig/network-sc

一个Navi过程下多个DocumentCompleted事件问题的解决办法

7.16 Marked to Write.... 七月份马克的一篇文章了,今天才想起来把他写完,呵呵. 原本是七月份用来做微博爬虫的,后来发现新浪对机器人的检测不好绕过,连简单地访问都会被检测出来,后来还封掉了一个小号...我也没干啥呀. 这新浪,纯HTML访问不让也就算了,连OAuth2.0里很多接口都不能用了,这样子爬数据的难度可就大大加大了. 废话不多说---------------------------------------------------------------------

由Action传到页面的Date类型也是一个Json数组,因此没法正常显示日期,解决办法如下

原贴请参考: http://blog.csdn.net/btt2013/article/details/50155949 添加一个工具类: JsonDateValueProcessor.java package com.xbmu.utils; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import net.sf.json.JsonConfig; import net.sf.

elasticsearch,http://ip:9200访问不到的解决办法

现在解压elasticsearch之后,启动,通过http://localhost:9200可以访问的到,但是http://ip:9200访问不到,怎么办呢?带你解决,带你飞 修改elasticsearch-2.3.3\config\elasticsearch.yml文件 重启一下,你就可以好好的玩耍了,good luck !!!

VitualBox中linux系统ping ip能通域名不通的解决办法

linux本机的DNS配置信息是在:/etc/resolv.conf vi打开,修改为本机的dns服务器地址

1.Maven+SpringMVC+Eclipse软件安装配置,Maven报插件错误,Eclipse总是卡死的解决办法,导入一个maven工程后 一直显示importing maven project

 使用Maven+SpringMVC+Eclipse软件安装配置过程中的问题: 1.Eclipse总是卡死的解决办法: 一:内存不足所以会卡死,配置一下eclipse.ini修改这几个值就好了-XX:MaxPermSize=768m-Xms1024m-Xmx3072m搜索 二:修改window->preferences --- > JAVA->Edittor->Hovers,将右侧所有复选框清空. 2.因为eclipse上一次未正常关闭,导致启动卡死,错误日志为: [plain