RHEL 6.5----LVS(DR)
主机名 | IP | 所需软件 |
master | eth0==>192.168.30.140(Nat) eth0:1==>192.168.17.130(Nat) | ipvsadm |
node-1 | eth0==>192.168.17.131 | httpd |
node-2 | eth0==>192.168.17.132 |
在master上安装及开启ipvsadm
[root@master ~]# yum install -y ipvsadm [root@master ~]# cd /etc/sysconfig/network-scripts/ [root@master network-scripts]# cp ifcfg-eth0 ifcfg-eth:1 [root@master network-scripts]# vim ifcfg-eth0:1 #只需修改绿色部分三处,其他不要动 DEVICE=eth0:1 TYPE=Ethernet UUID=a186cc9d-8d79-4027-a180-a1b17d884a7b ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none HWADDR=00:0C:29:4D:47:50 IPADDR=192.168.30.130 PREFIX=24 GATEWAY=192.168.30.2 DNS1=119.29.29.29 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System eth0:1" 重启网络服务 [root@master ~]# service network restart Shutting down interface eth0: Device state: 3 (disconnected) [ OK ] Shutting down interface eth1: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Active connection state: activated Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1 [ OK ] [root@master ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:4D:47:50 inet addr:192.168.30.140 Bcast:192.168.30.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe4d:4750/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:81 errors:0 dropped:0 overruns:0 frame:0 TX packets:105 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:8687 (8.4 KiB) TX bytes:8194 (8.0 KiB) eth0:1 Link encap:Ethernet HWaddr 00:0C:29:4D:47:50 #MAC地址一定要与eth0的一样 inet addr:192.168.30.130 Bcast:192.168.30.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
添加规则
确保这里是0 [root@master ~]# sysctl -p net.ipv4.ip_forward = 0 .......... 添加规则 [root@master ~]# ipvsadm -A -t 192.168.30.130:80 -s rr [root@master ~]# ipvsadm -a -t 192.168.30.130:80 -r 192.168.30.131 -g [root@master ~]# ipvsadm -a -t 192.168.30.130:80 -r 192.168.30.132 -g [root@master ~]# 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.30.130:80 rr -> 192.168.30.131:80 Route 1 0 0 -> 192.168.30.132:80 Route 1 0 0 保存规则 [root@master ~]# /etc/init.d/ipvsadm save ipvsadm: Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
在realserver(node-1和node-2)上
生成ifcfg-lo:1文件 [root@node-1 ~]# cd /etc/sysconfig/network-scripts/ [root@node-1 network-scripts]# cp ifcfg-lo ifcfg-lo:1 [root@node-1 network-scripts]# vim ifcfg-lo:1 DEVICE=lo:1 IPADDR=192.168.30.130 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
关闭ARP转发
[root@node-1 ~]# vim /etc/sysctl.conf #末未添加 net.ipv4.conf.eth0.arp_ignore = 1 net.ipv4.conf.eth0.arp_announce = 2 [root@node-1 ~]# sysctl -p #使立即生效 net.ipv4.ip_forward = 0 ..... net.ipv4.conf.eth0.arp_ignore = 1 net.ipv4.conf.eth0.arp_announce = 2
修改网关
[root@node-1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 GATEWAY=192.168.30.2 #网关修改为指向外网出口的路由器IP
创建测试页面
[root@node-1 ~]# echo "<h1>This is the node-1 Web-Server:192.168.17.131</h1>" > /var/www/html/index.html
在node-2上
[root@node-2 ~]# cd /etc/sysconfig/network-scripts/ [root@node-2 network-scripts]# cp ifcfg-lo ifcfg-lo:1 [root@node-2 network-scripts]# vim ifcfg-lo:1 DEVICE=lo:1 IPADDR=192.168.30.130 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@node-2 ~]# service network restart Shutting down interface eth0: Device state: 3 (disconnected) [ OK ] Shutting down interface eth1: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Active connection state: activated Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/3 [ OK ] [root@node-2 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:2F:84:4D inet addr:192.168.30.132 Bcast:192.168.30.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:fe2f:844d/64 Scope:Link ................... lo:1 Link encap:Local Loopback inet addr:192.168.30.130 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:16436 Metric:1
关闭ARP转发通node-1操作一样;
创建测试页面
[root@node-2 ~]# echo "<h1>This is the node-2 Web-Server:192.168.17.132</h1>" > /var/www/html/index.html [root@node-2 ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
物理机使用浏览器访问测试