- 服务器以及软件规划:
linux服务器 :3台
系统版本 : centos 6.5 x86_64(1台是lvs 调度器,安装lvs调度软件,2台是RS服务器,运行web服务)
2.IP地址规划:
LVS Server: eth0:0 VIP:192.168.1.222/24 eth0 DIP:192.168.1.134/24 RS1: RS2: eth0 192.168.1.135/24 eth0 192.168.1.136/24 lo:0 192.168.1.222/32 lo:0 192.168.1.222/32
下边开始部署安装LVS负载均衡的DR模式。
一、在LB上配置VIP,安装ipvsadm管理软件。
- 在调度器上,配置VIP和DIP,由于DIP已经配置好,只需配置VIP。
[[email protected] ~]# ifconfig eth0:0 192.168.1.222 netmask 255.255.255.0 up [[email protected] ~]# ifconfig eth0:0 eth0:0 Link encap:Ethernet HWaddr 00:0C:29:78:6B:94 inet addr:192.168.1.222 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
2.yum安装ipvsadm管理软件。
[[email protected] ~]# yum install -y ipvsadm [[email protected] ~]# ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn [[email protected] ~]# lsmod | grep ip_vs ip_vs 125220 0 libcrc32c 1246 1 ip_vs ipv6 317340 142 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
二、分别在两台后端RS上安装apache,抑制arp,配置VIP地址。
- 看下是否安装了apache,没有安装的话,yum安装一下httpd。
[[email protected] ~]# rpm -qa | grep httpd
[[email protected] ~]#
[[email protected] ~]# yum install -y httpd
安装完成之后,检查下是否安装成功。
[[email protected] ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-47.el6.centos.x86_64
httpd-2.2.15-47.el6.centos.x86_64
启动httpd服务。
[[email protected] ~]# /etc/init.d/httpd start
成功启动之后,写一个页面到相应目录下。
[[email protected] ~]# echo "<h1>RS1<h1>" >/var/www/html/index.html
访问一下,看看页面是否可以正常,有时候打不开,很有可能是防火墙或者selinux影响的。
同样上述步骤,配置下RS2,此处省略,访问rs2看网页,出现RS2即可,如下图所示。
2.在rs1和rs2上,做arp抑制,然后再配置VIP。
RS1上,抑制ARP,在lo网卡上,添加VIP
[[email protected] ]# echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore [[email protected] ]# echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce [[email protected] ]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore [[email protected] ]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce [[email protected] ~]# ifconfig lo:0 192.168.1.222 netmask 255.255.255.255 up [[email protected] ~]# ifconfig lo:0 lo:0 Link encap:Local Loopback inet addr:192.168.1.222 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:16436 Metric:1
RS2上,抑制ARP,配置VIP,在lo网卡上,添加VIP
[[email protected] ]# echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
[[email protected] ]# echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
[[email protected] ]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
[[email protected] ]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
[email protected] ~]# ifconfig lo:0 192.168.1.222 broadcast 192.168.1.222 255.255.255.255 up
[[email protected] ~]# ifconfig lo:0
lo:0 Link encap:Local Loopback
inet addr:192.168.1.222 Mask:255.255.255.255
UP LOOPBACK RUNNING MTU:16436 Metric:1
三、在调度器上配置lvs。
[[email protected] ~]# ipvsadm -C [[email protected] ~]# ipvsadm --set 30 5 60 [[email protected] ~]# ipvsadm -A -t 192.168.1.222:80 -s wrr [[email protected] ~]# ipvsadm -a -t 192.168.1.222:80 -r 192.168.1.135:80 -g -w 1 [[email protected] ~]# ipvsadm -a -t 192.168.1.222:80 -r 192.168.1.136:80 -g -w 1 [[email protected] ~]# 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.222:80 wrr -> 192.168.1.135:80 Route 1 0 0 -> 192.168.1.136:80 Route 1 0 0
[[email protected] ~]# 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.222:80 wrr -> 192.168.1.135:80 Route 1 0 1 -> 192.168.1.136:80 Route 1 0 1
安装lvs负载均衡的DR模式实验,到此结束,谢谢大家。