项目背景:
利用lvs的DR技术实现我们公司的web集群架构!!!
实验环境:
vmware workstation 11
centos6.5的系统下
load balance:ip:192.168.0.32 vip:192.168.0.100 关闭iptables setenforce0
user:ip:192.168.1.39 关闭iptables setenforce0
real_server01:192.168.0.10 vip:192.168.0.100 关闭iptables setenforce0
real_server02:192.168.0.36 vip:192.168.0.100 关闭iptables setenforce0
SecureCRT (ssh远程连接软件)
架构图:
实验过程:
一、在load balance上面安装ipvsadm
yum install -y ipvs*
二、load balance上面执行下面的脚本
[root@Load_Balancer ~]# cat lvs02.sh
#!/bin/bash
#set ip_forward OFF for lvs-dr director (1 on, 0 off)
#(there is no forwarding in the conventional sense for LVS-DR)
cat /proc/sys/net/ipv4/ip_forward
echo "0" >/proc/sys/net/ipv4/ip_forward
#director is not gw for realservers: leave icmp redirects on
echo 'setting icmp redirects (1 on, 0 off) '
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
cat /proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
cat /proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects
cat /proc/sys/net/ipv4/conf/eth0/send_redirects
#add ethernet device and routing for VIP 192.168.0.100
/sbin/ifconfig eth0:0 192.168.0.100
#listing routing info for VIP 192.168.0.100
/bin/netstat -rn
#clear ipvsadm table
/sbin/ipvsadm -C
#installing LVS services with ipvsadm
#add telnet to VIP with round robin scheduling
/sbin/ipvsadm -A -t 192.168.0.100:80 -s rr
#forward telnet to realserver using direct routing with weight 1
/sbin/ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.10:80 -g -w 1
#forward telnet to realserver using direct routing with weight 1
#/sbin/ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.36:80 -g -w 1
#displaying ipvsadm settings
/sbin/ipvsadm
三、在real server01上面执行下面的脚本
[root@real_server01 ~]# cat real_server01v2.sh
#!/bin/bash
#showing routing table
/bin/netstat -rn
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
#install_realserver_vip
/sbin/ifconfig lo:0 192.168.0.100 broadcast 192.168.0.100 netmask 0xffffffff up
#ifconfig output
/sbin/ifconfig lo:0
/sbin/route add -host 192.168.0.100 dev lo:0
/bin/netstat -rn
四、在real server02上面执行下面的脚本
[root@real_server02 ~]# cat real_server02.sh-v2
#!/bin/bash
#showing routing table
/bin/netstat -rn
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
#install_realserver_vip
/sbin/ifconfig lo:0 192.168.0.100 broadcast 192.168.0.100 netmask 0xffffffff up
/sbin/ifconfig lo:0
/sbin/route add -host 192.168.0.100 dev lo:0
/bin/netstat -rn
五:测试 ,在user上浏览器里面输入vip 192.168.0.100
主机1 我的电脑上
主机二 虚拟机的user主机
你测试的时候也要在两个主机上测试
总结:VS/DR可以减轻负载均衡服务器的压力,应答消息有我们的实际的web集群应答!!!
知识在于分享!!!
谢谢大家!!!