LVS负载均衡集群之NAT模式


一、环境

4台虚拟机:1台Client、1台DirectorServer、2台RealServer。IP地址分别如下:

Client:192.168.1.250

DS:VIP:192.168.1.252,DIP:10.10.10.10

RealServer1:10.10.10.80 Gateway:10.10.10.10

RealServer2:10.10.10.81 Gateway:10.10.10.10


二、安装配置RealServer

RealServer1:

yum -y install httpd

chkconfig httpd on

echo "RealServer1" >> /var/www/html/index.html

sed -i '276a ServerName localhost:80' /etc/httpd/conf/httpd.conf

service httpd start


RealServer2:

yum -y install httpd

chkconfig httpd on

echo "RealServer2" >> /var/www/html/index.html

sed -i '276a ServerName localhost:80' /etc/httpd/conf/httpd.conf

service httpd start


三、安装配置DirectorServer

开启系统转发功能;配置文件:/etc/sysctl.conf(net.ipv4.ip_forward = 1);

yum -y install ipvsadm

ipvsadm -A -t 192.168.1.252:80 -s wlc

ipvsadm -a -t 192.168.1.252:80 -r 10.10.10.80 -m -w 1

ipvsadm -a -t 192.168.1.252:80 -r 10.10.10.81 -m -w 1

service ipvsadm save

ipvsadm -L -n


参数说明:

-A 添加集群服务;

-t TCP协议;

-s 指定调度算法;

-m 指定为NAT模式;

-w 权重;


四、Client访问测试


ab -c 10 -n 1000 http://192.168.1.252/index.html