一、环境说明
主机名 |
IP |
系统 |
IP类型 |
角色 |
s1 |
192.168.80.128 |
CentOS 7 |
DIP |
Director |
s1 |
192.168.0.133 |
CentOS 7 |
VIP |
Director |
s2 |
192.168.80.129 |
CentOS 7 |
RIP |
Real Server |
s3 |
192.168.80.130 |
CentOS 7 |
RIP |
Real Server |
二、环境准备
- Director
$ yum install -y ipvsadm
# 开启ipv4转发
$ echo 1 > /proc/sys/net/ipv4/ip_forward
- Real Server
$ yum install -y nginx
$ systemctl start nginx
# 将默认网关指向DIP
$ route del default
$ route add default gateway 192.168.80.128
- s2
$ echo "<h1>s2 real sever</h1>" > /usr/share/nginx/html/index.html
- s3
$ echo "<h1>s3 real server</h1>" > /usr/share/nginx/html/index.html
三、配置ipvs-nat
$ ipvsadm -A -t 192.168.0.133:80 -s rr
$ ipvsadm -a -t 192.168.0.133:80 -r 192.168.80.129 -m
$ ipvsadm -a -t 192.168.0.133:80 -r 192.168.80.130 -m
四、结果
五、配置总结
- DIP应该和RIP处于同一个网段
- Real Server 默认网关应指向DIP
- Director 应开启ipv4转发