Linux负载均衡LVS之NAT
Linux负载均衡LVS之NAT实验拓扑:
http://blog.运维网.com/attachment/201310/161656108.png
一.首先配置好后方的两台服务器
SERVER1
http://blog.运维网.com/attachment/201310/161657494.png
安装http服务器
http://blog.运维网.com/attachment/201310/161658220.png
SERVER2
http://blog.运维网.com/attachment/201310/161658154.png
安装http服务器
http://blog.运维网.com/attachment/201310/161659502.png
完成之后我们开始配置DIRECTOR
http://blog.运维网.com/attachment/201310/161659399.png
看一下我们的内核版本,是我刚升级过得。支持ipvs。
http://blog.运维网.com/attachment/201310/161700291.png
vim /boot/config-2.6.18-164.el5
http://blog.运维网.com/attachment/201310/161701553.png
打开数据包的转发功能,因为今天采用的是NAT。需要进行地址转换。
http://blog.运维网.com/attachment/201310/161702789.png
执行sysctl -p 让内核参数重新生效。
http://blog.运维网.com/attachment/201310/161702660.png
现在我们需要安装调用内核中ipvs的用户工具ipvsadm
http://blog.运维网.com/attachment/201310/161702162.png
下面开始写我们的转发规则了。可以参考man手册。
http://blog.运维网.com/attachment/201310/161703413.png
我们需要转发的是TCP的80端口的http服务。
下面我们开始写我们需要转发的real server了。
http://blog.运维网.com/attachment/201310/161703440.png
保存我们写出的规则
http://blog.运维网.com/attachment/201310/161704495.png
http://blog.运维网.com/attachment/201310/161704883.png
下面我们在我们的宿主机访问以下:
http://blog.运维网.com/attachment/201310/161704325.png
刷新一下看看
http://blog.运维网.com/attachment/201310/161704996.png
因为我们采用的rr轮询调度算法。所以每刷新一次都不一样。现在我们修改一下server2的权重为5,再看看访问有什么变化。
http://blog.运维网.com/attachment/201310/161704389.png
是不是发现还是没有什么变化。这是因为我们采用的是轮询调度(rr)和权重是没有关系的。
将轮询调度算法(rr)改为加权轮询调度算法(wrr)就会根据权重的大小,来各自给服务器分配任务。
http://blog.运维网.com/attachment/201310/161705370.png
再来访问你就会发现server2的访问次数是server1的五倍。
页:
[1]