P1作为负载调度器
增加一块网卡
P2P3作为realserver也分别增加一枚网卡
1、配置好IP并测试
2、配置时间同步
服务器端
[root@localhost ~]# vim /etc/chrony.conf
server 192.168.226.130 iburst
allow 192.168.226.0/24
local stratum 10
[root@localhost ~]# systemctl restart chronyd
客户端
[root@localhost ~]# vim /etc/chrony.conf
server 192.168.226.130 iburst
[root@localhost ~]# systemctl restart chronyd
[root@localhost ~]# chronyc sources
3、负载调度器
1)开启路由转发功能
永久开启
[root@localhost ~]# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
生效
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
4、准备rs环境
本地rpm包
[root@localhost ~]# ls
nginx-1.10.0-1.el7.ngx.x86_64.rpm
[root@localhost ~]# yum install nginx-1.10.0-1.el7.ngx.x86_64.rpm -y
[root@localhost ~]# cd /usr/share/nginx/html/
[root@localhost html]# ls
50x.html index.html
[root@localhost html]# mv index.html{,.bak}
[root@localhost html]# echo "web1 test page" > index.html
开启服务
[root@localhost html]# systemctl enable --now nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
本地测试
[root@localhost html]# curl localhost
web1 test page
rs2,rs3:
[root@localhost html]# echo "web2 test page" > index.html
[root@localhost html]# echo "web3 test page" > index.html
5、lvs-nat负载配置
1)安装ipvsadm
yum install -y ipvsadm
2)配置
ipvsadm -A -t 192.168.226.130:80 -s rr
ipvsadm -a -t 192.168.226.130:80 -r 192.168.226.131:80 -m
ipvsadm -a -t 192.168.226.130:80 -r 192.168.226.132:80 -m
查看
[root@localhost ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.226.130:http rr
-> 192.168.226.131:http Masq 1 0 0
-> 192.168.226.132:http Masq 1 0 0
3)测试