首页 > 代码库 > 使用ipvsadm实现DR模型的负载均衡集群

使用ipvsadm实现DR模型的负载均衡集群

负载均衡之LB-DR模型

主机规划

node1:eth0-->172.17.2.129/22

 lo:0-->172.17.2.140/32

node2:eth0-->172.17.2.130/22

 lo:0-->172.17.2.140/32

direc:eth0-->172.17.2.132/22

      ech0:0-->172.17.2.140/32


实验准备:

1.配置IP

node1~2:

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 


yum -y install net-tools

ip addr add 172.17.2.140/32 dev lo:0 

route add -host 172.17.2.140 dev lo

2.启动服务

yum install -y httpd

systemctl start httpd

node1:

echo <h1>node1</h1> >/var/www/html/index.html

node2:

echo <h1>node2</h1> >/var/www/html/index.html


ipvsadm安装配置

director:

yum -y install net-tools

ip addr add 172.17.2.140/32 eth0:0

route add -host 172.17.2.140 dev eth0

yum install -y ipvsadm

ipvsadm -A -t 172.17.2.140:80 -s rr

ipvsadm -a -t 172.17.2.140:80 -r 172.17.2.129:80 -g

ipvsadm -a -t 172.17.2.140:80 -r 172.17.2.130:80 -g


查看负载均衡效果

~]# ipvsadm -L -n

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  172.17.2.140:80 rr

  -> 172.17.2.129:80              Route   1      0          3         

  -> 172.17.2.130:80              Route   1      0          2  


[root@localhost ~]# curl 172.17.2.140

<h1>node1</h1>

[root@localhost ~]# curl 172.17.2.140

<h1>node2</h1>

[root@localhost ~]# curl 172.17.2.140

<h1>node1</h1>

[root@localhost ~]# curl 172.17.2.140

<h1>node2</h1>

[root@localhost ~]# curl 172.17.2.140

<h1>node1</h1>


通过以上的设置,可以查看到内容在不同节点之前的切换


本文出自 “梦想人生” 博客,请务必保留此出处http://hzde0128.blog.51cto.com/918211/1914482

使用ipvsadm实现DR模型的负载均衡集群