环境
名称 | IP | 类型 |
---|---|---|
客户机 | 172.50.150.200 | CIP |
DR | 172.50.150.100 | VIP |
DR | 192.168.153.20 | DIP |
RS1 | 192.168.153.22 | RIP |
RS2 | 192.168.153.25 | RIP |
搭建HTTP负载均衡集群
1. 在Client上配置CIP,模拟公网地址
[root@Client ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NAME=eno16777736
DEVICE=eno16777736
ONBOOT=yes
IPADDR=172.50.150.200
NETMASK=255.255.255.0
GATEWAY=172.50.150.0
DNS=114.114.114.114
2. 在DR上配置DIP和VIP
配置VIP
[root@DR ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno2
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NAME=eno2
DEVICE=eno2
ONBOOT=yes
IPADDR=172.50.150.100
NETMASK=255.255.255.0
GATEWAY=172.50.150.200 //指向CIP
DNS1=114.114.114.114
[root@DR ~]# systemctl restart network
配置DIP
[root@DR ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NAME=eno16777736
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.153.20
NETMASK=255.255.255.0
GATEWAY=192.168.153.2
DNS1=114.114.114.114
3.在DR上开启IP转发,配置转发规则
开启转发功能
[root@DR ~]# vim /etc/sysctl.conf
[root@DR ~]# sysctl -p
net.ipv4.ip_forward = 1
配置规则
[root@DR ~]# yum -y install ipvsadm
[root@DR ~]# ipvsadm -A -t 172.50.150.100:80 -s rr
[root@DR ~]# ipvsadm -a -t 172.50.150.100:80 -r 192.168.153.22:80 -m
[root@DR ~]# ipvsadm -a -t 172.50.150.100:80 -r 192.168.153.25:80 -m
[root@DR ~]# ipvsadm -Sn > /etc/sysconf