lvs主要有三种类型,即nat模式,DR模式 ,遂道模式。在这里主要简单介绍下DR与nat模式。
1. LVS-DR模式
1.1 重点内容arptalbes
通过修改mac地址实现
集群节点必须在同一个物理网络中,不能跨越路由
rip可以使用公共地址
director仅处理入站请求,出站响应不再经过director
DR不支持端口帕映射
大多数系统支持real server
DR的director压力小于nat的director
1.2 环境lvs-servereth0:210.168.100.1vip:210.168.100.100 255.255.255.255real-server1eth0:210.168.100.2real-server2eth0:210.168.100.3
虚拟机网卡模式 vm0
1.3 lvs-server配置 配置vip及路由[root@master ~]# ifconfig eth0:0 210.168.100.100 netmask 255.255.255.255[root@master ~]# route add -host 210.168.100.100 dev eth0:0配置ipvsadm通过运行脚本ipvs.sh来配置
#!/bin/bash#author by hu#date 2013-11-16ipvsadm -Cipvsadm -At 210.168.100.100:80 -s rripvsadm -at 210.168.100.100:80 -r 210.168.100.2 -gipvsadm -at 210.168.100.100:80 -r 210.168.100.3 -gipvsadm
注:-g 表示DR直播路由模式;-m 表示nat模式;-i表示遂道模式。
运行脚本[root@master ~]# ./ipvs.shIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 210.168.100.100:http rr -> 210.168.100.2:http Route 1 0 0 -> 210.168.100.3:http Route 1 0 01.4 real-server配置这里以real-server1为例配置vip
[root@Nodes03 ~]# ifconfig lo:0 210.168.100.100 netmask 255.255.255.255[root@Nodes03 ~]# route add -host 210.168.100.100 dev lo:0
配置arp
通过脚本ipvsadm.sh来更改#!/bin/bash#author by hu#date 2013-11-16ipvsadm -Cipvsadm -At 210.168.100.1:80 -s rripvsadm -at 210.168.100.1:80 -r 192.168.100.2:80 -mipvsadm -at 210.168.100.1:80 -r 192.168.100.3:80 -mipvsadm
运行脚本
[root@master ~]# ./ipvsadm.shIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 210.168.100.1:http rr -> 192.168.100.2:http Masq 1 0 21 -> 192.168.100.3:http Masq 1 0 201.5 验证通过访问210.168.100.100,如果有显示并有不同的结果则正确2 NAT模式重点内容
所有集群节点在同一个节点当中
RIP是私有地址,用于集群节点之间进行通信
director 进行处理入站和出站请求
VIP网关要指向DIP
可以实现端口映射
director容易成为系统性能瓶颈
2.1 环境lvs-server eth0:210.168.100.1/25 eth1:192.168.100.1/25real-server1 eth0:192.168.100.2/25 gw 192.168.100.1real-server1 eth0:192.168.100.3/25 gw 192.168.100.1注:real-server的网关要指向lvs-server内网地址,否则数据将无法返回。2.2 ipvsadm配置通过执行脚本ipvsadm.sh配置
#!/bin/bash#author by hu#date 2013-11-16ipvsadm -Cipvsadm -At 210.168.100.1:80 -s rripvsadm -at 210.168.100.1:80 -r 192.168.100.2:80 -mipvsadm -at 210.168.100.1:80 -r 192.168.100.3:80 -mipvsadm运行脚本
[root@master ~]# ./ipvsadm.shIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 210.168.100.1:http rr -> 192.168.100.2:http Masq 1 0 21 -> 192.168.100.3:http Masq 1 0 202.3 验证
通过访问210.168.100.1,如果有显示并有不同的结果则正确