• LVS集群-DR模式


    同上个实验一样,还是准备三台机器

    分发器(sishen_63):eth0 192.168.1.63

    RealServer1sishen_64)

    RealServer2sishen_65)

    首先配置网卡eth0

    [root@sishen_63 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0
    TYPE=Ethernet
    UUID=2720a3a8-031a-484e-8d10-6856a76a1922
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=none
    HWADDR=00:0c:29:c2:28:31
    DEFROUTE=yes
    PEERROUTES=yes
    IPV4_FAILURE_FATAL=yes
    IPV6INIT=no
    NAME="System eth0"
    IPADDR=192.168.1.63
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    USERCTL=no

    生成eth0:1配置文件,直接cp eth0 –> eth0:1,见如下步骤

    [root@sishen_63 ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
    [root@sishen_63 ~]# vim !$
    vim /etc/sysconfig/network-scripts/ifcfg-eth0:1
    [root@sishen_63 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:1
    [root@sishen_63 ~]# service network restart

    然后修改绿色标注部分,最后重启网络;

    配置vim eth0:1

    DEVICE=eth0:1
    TYPE=Ethernet
    UUID=2720a3a8-031a-484e-8d10-6856a76a1922
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=none
    HWADDR=00:0c:29:c2:28:31
    DEFROUTE=yes
    PEERROUTES=yes
    IPV4_FAILURE_FATAL=yes
    IPV6INIT=no
    NAME="System eth0:1"
    IPADDR=192.168.1.6

    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    USERCTL=no

    注意:黄色标注部分不需要更改!

    [root@sishen_63 ~]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0C:29:C2:28:31 
               inet addr:192.168.1.63  Bcast:192.168.1.255  Mask:255.255.255.0
               inet6 addr: fe80::20c:29ff:fec2:2831/64 Scope:Link
               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
               RX packets:201 errors:0 dropped:0 overruns:0 frame:0
               TX packets:214 errors:0 dropped:0 overruns:0 carrier:0
               collisions:0 txqueuelen:1000
               RX bytes:25196 (24.6 KiB)  TX bytes:17442 (17.0 KiB)

    eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:C2:28:31 
              inet addr:192.168.1.6  Bcast:192.168.1.255  Mask:255.255.255.0
               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

    安装LVS工具

    [root@sishen_63 ~]# rpm -ivh /mnt/cdrom/Packages/ipvsadm-1.26-2.el6.x86_64.rpm

    配置LVS-DR规则

    在分发器(sishen_63)上:

    [root@sishen_63 ~]# ipvsadm -A -t 192.168.1.6:80 -s rr
    [root@sishen_63 ~]# ipvsadm -a -t 192.168.1.6:80 -r 192.168.1.64 -g
    [root@sishen_63 ~]# ipvsadm -a -t 192.168.1.6:80 -r 192.168.1.65 -g
    [root@sishen_63 ~]# ipvsadm -L -n
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
       -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  192.168.1.6:80 rr
       -> 192.168.1.64:80              Route   1      0          0        
       -> 192.168.1.65:80              Route   1      0          0        
    [root@sishen_63 ~]# /etc/init.d/ipvsadm save
    ipvsadm: Saving IPVS table to /etc/sysconfig/ipvsadm:      [  OK  ]

    在RealServer1(sishen_64)上

    [root@sishen_64 ~]# cd /etc/sysconfig/network-scripts/
    [root@sishen_64 network-scripts]# cp ifcfg-lo ifcfg-lo:1      #生成回环口配置文件
    [root@sishen_64 network-scripts]# vim ifcfg-lo:1

    DEVICE=lo:1
    IPADDR=192.168.1.63
    NETMASK=255.255.255.255

    # If you're having problems with gated making 127.0.0.0/8 a martian,
    # you can change this to something else (255.255.255.255, for example)
    ONBOOT=yes
    NAME=loopback

    将复制后的ifcfg-lo:1修改为图中绿色标注的内容;

    [root@sishen_64 network-scripts]# service network restart

    [root@sishen_64 network-scripts]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0C:29:11:5A:8C 
              inet addr:192.168.1.74  Bcast:192.168.1.255  Mask:255.255.255.0
               inet6 addr: fe80::20c:29ff:fe11:5a8c/64 Scope:Link
               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
               RX packets:93 errors:0 dropped:0 overruns:0 frame:0
               TX packets:111 errors:0 dropped:0 overruns:0 carrier:0
               collisions:0 txqueuelen:1000
               RX bytes:12005 (11.7 KiB)  TX bytes:8338 (8.1 KiB)

    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:32 errors:0 dropped:0 overruns:0 frame:0
               TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
               collisions:0 txqueuelen:0
               RX bytes:2212 (2.1 KiB)  TX bytes:2212 (2.1 KiB)

    lo:1      Link encap:Local Loopback 
               inet addr:192.168.1.63  Mask:255.255.255.0
               UP LOOPBACK RUNNING  MTU:16436  Metric:1

    关闭ARP转发

    临时生效:

    [root@sishen_64 ~]# echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
    [root@sishen_64 ~]# echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce

    永久生效需要在/etc/sysctl.conf文件末尾添加如下内容:

    [root@sishen_64 ~]# vim /etc/sysctl.conf

    net.ipv4.conf.eth0.arp_ignore = 1
    net.ipv4.conf.eth0.arp_announce = 2

    注意:至于这两个参数的值意味着什么意思,我暂时还没搞得太清楚,不敢确定,所以这里没有写,希望各路大侠给予指点^_^!

    [root@sishen_64 ~]# sysctl –p

    查看并确保网关指向公网

    [root@sishen_64 ~]# grep 'GATEWAY' /etc/sysconfig/network-scripts/ifcfg-eth0
    GATEWAY=192.168.1.1

    开启web服务并创建测试页面

    [root@sishen_64 ~]# service httpd start
    Starting httpd:                                            [  OK  ]

    [root@sishen_64 ~]# echo "sishen_64" > /var/www/html/index.html

    本地测试可以正常访问

    [root@sishen_64 ~]# elinks 192.168.1.65 --dump
        sishen_65


      在RealServer2(sishen_65)上:

    [root@sishen_65 network-scripts]# cp ifcfg-lo ifcfg-lo:1
    [root@sishen_65 network-scripts]# vim ifcfg-lo:1

    DEVICE=lo:1
    IPADDR=192.168.1.63
    NETMASK=255.255.255.255

    # If you're having problems with gated making 127.0.0.0/8 a martian,
    # you can change this to something else (255.255.255.255, for example)
    ONBOOT=yes
    NAME=loopback


    [root@sishen_65 network-scripts]# service network restart

    [root@sishen_65 ~]# cd /etc/sysconfig/network-scripts/

    [root@sishen_65 network-scripts]# ifconfig

    eth0      Link encap:Ethernet  HWaddr 00:0C:29:A9:43:61 
               inet addr:192.168.1.65  Bcast:192.168.1.255  Mask:255.255.255.0
               inet6 addr: fe80::20c:29ff:fea9:4361/64 Scope:Link
               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
               RX packets:420 errors:0 dropped:0 overruns:0 frame:0
               TX packets:416 errors:0 dropped:0 overruns:0 carrier:0
               collisions:0 txqueuelen:1000
               RX bytes:55468 (54.1 KiB)  TX bytes:37696 (36.8 KiB)

    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:16 errors:0 dropped:0 overruns:0 frame:0
               TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
               collisions:0 txqueuelen:0
               RX bytes:960 (960.0 b)  TX bytes:960 (960.0 b)

    lo:1      Link encap:Local Loopback 
               inet addr:192.168.1.63  Mask:255.255.255.255
               UP LOOPBACK RUNNING  MTU:16436  Metric:1

    关闭ARP转发

    在/etc/sysctl.conf 文件末尾添加以下两行内容

    [root@sishen_65 ~]# vim /etc/sysctl.conf

    net.ipv4.conf.eth0.arp_ignore = 1
    net.ipv4.conf.eth0.arp_announce = 2

    [root@sishen_65 ~]# sysctl -p

    开启web服务并创建测试页

    [root@sishen_65 ~]# echo "sishen_65" > /var/www/html/index.html
    [root@sishen_65 ~]# service httpd start
    Starting httpd:                                            [  OK  ]
    [root@sishen_65 ~]# yum install -y elinks

    本地测试web服务

    [root@sishen_65 ~]# elinks 192.168.1.65 --dump
        sishen_65

    确保机器之间相互可以ping通,然后宿主机也可以ping通三台机器,(注意:这里不可以在分发器(sishen_63)上测试),用宿主机浏览器测试

    image

    遇到的问题就是

    无论怎么刷新,都刷不出sishen_64,相互之间都是通的,防火墙什么的都关闭了,服务也都启动了,但就是不通。在随后的博客中解决吧,也希望有知道原因的大神请赐教:1255560195@qq.com,谢谢^_^

  • 相关阅读:
    用MySQL的注意事项
    在win下mysql备份恢复命令概述
    SQL查询结果集对注入的影响与利用
    DIV CSS完美兼容IE6/IE7/FF的通用方法
    使用css实现透视的效果
    ASP.NET几个性能优化的方法
    ASP.NET实现页面传值的几种方法
    ASP.NET配置文件Web.config 详细解释
    黑客域名劫持攻击详细步骤
    FCKeditor的几点修改小结
  • 原文地址:https://www.cnblogs.com/zd520pyx1314/p/7887475.html
Copyright © 2020-2023  润新知