一 LVS-NAT實驗前的準備
操作系統:CentOS 6.7 64位
配置防火墻,iptables –F 清理防火墻規則或者關閉iptables
關閉SELINUX, setenforce 0 #立即生效(實際是寬容模式)
Director ip:172.16.2.1 VIP:192.168.1.8
RS1 ip:172.16.2.2
RS2 ip:172.16.2.3
二 LVS-NAT模型實現
1.Real Server配置
RS1:
a) 安裝好Nginx
b) echo "<h1>This is Real Server 1 </h1>" > /usr/local/nginx/html/index.html #添加網頁內容
c) route add default gw 172.16.2.1 #設置默認網關為Director的DIP
d) service nginx start #啟動nginx服務
RS2
a) 安裝好Nginx
b) echo "<h1>This is Real Server 2 </h1>" > /usr/local/nginx/html/index.html #添加網頁內容
c) route add default gw 172.16.2.1 #設置默認網關為Director的DIP
d) service nginx start #啟動nginx服務
2. Director配置
a) [root@localhost ~]# curl http://172.16.2.2 #可以正常訪問RS1
<h1>This is Real Server 1 </h1>
[root@localhost ~]# curl http://172.16.2.3 #可以正常訪問RS1
<h1>This is Real Server 2 </h1>
b) yum -y install ipvsadm #安裝ipvsadm工具
c) 打開路由轉發功能
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1 #把0修改成1
sysctl –p #立即生效
d) 建立集群服務.
ipvsadm -A -t 192.168.1.8:80 -s rr #建立集群服務并選擇RR的調度算法
e) 在集群服務中添加RS
ipvsadm -a -t 192.168.1.8:80 -r 172.16.2.2 –m
ipvsadm -a -t 192.168.1.8:80 -r 172.16.2.3 –m
f) 查看ipvs 規則是否添加成功
ipvsadm -L –n
3. 測試結果
三 LVS-DR實驗前的準備
操作系統:CentOS 6.7 64位
配置防火墻,iptables –F 清理防火墻規則或者關閉iptables
關閉SELINUX, setenforce 0 #立即生效(實際是寬容模式)
Director ip:192.168.1.8 VIP:192.168.1.4
RS1 ip:192.168.1.5 lo:0:vip:192.168.1.4
RS2 ip:192.168.1.7 lo:0:vip:192.168.1.4
1. Real Server配置
RS1:
a) #修改內核參數,若要永久生效請修改配置文件
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
b) 安裝好Nginx
echo "<h1>This is Real Server 1 </h1>" > /usr/local/nginx/html/index.html #添加網頁內容
c) ifconfig lo:0 192.168.1.4/32 broadcast 192.168.1.4 up #配置VIP到lo:0
d) route add -host 192.168.1.4 dev lo:0 #設置路由到192.168.1.4 的走lo:0接口
e) service nginx start #啟動nginx服務
RS2:
a) #修改內核參數,若要永久生效請修改配置文件
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
b)安裝好Nginx
echo "<h1>This is Real Server 1 </h1>" > /usr/local/nginx/html/index.html #添加網頁內容
c) ifconfig lo:0 192.168.1.4/32 broadcast 192.168.1.4 up #配置VIP到lo:0
d) route add -host 192.168.1.4 dev lo:0 #設置路由到192.168.1.4 的走lo:0接口
e) service nginx start #啟動nginx服務
2. Director配置
a) ifconfig eth0:0 192.168.1.4/32 broadcast 192.168.1.4 up #配置VIP到eth0:0 接口
b) route add -host 192.168.1.4 dev eth0:0 #設置路由到192.168.1.4 的走eth0:0接口
c) 建立集群服務.
ipvsadm -A -t 192.168.1.4:80 -s rr #建立集群服務并選擇RR的調度算法
d) 在集群服務中添加RS
ipvsadm -a -t 192.168.1.4:80 -r 192.168.1.5 –g
ipvsadm -a -t 192.168.1.4:80 -r 192.168.1.7 –g
e) 查看ipvs 規則是否添加成功
3. 測試結果
原創文章,作者:liangkai,如若轉載,請注明出處:http://www.www58058.com/62676