一、构建LVS-DR集群
1、主机规划
Node01:PC
Node02:LVS
Node03、Node04:Webserver
2、部署环境
2.1 在Node02上配置
2.1.1 安装ipvsadm管理软件按
[root@localhost ~]# yum install -y ipvsadm
2.1.2 配置VIP
[root@localhost ~]# ifconfig ens33:200 192.168.100.200 netmask 255.255.255.255[root@localhost ~]# ip ad
ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000inet 192.168.100.200/32 brd 192.168.100.255 scope global secondary ens33:200valid_lft forever preferred_lft forever
2.2 在Node03上配置
2.2.1 安装Apache服务
[root@localhost ~]# yum install -y httpd
2.2.2 编辑默认主页
[root@localhost ~]# echo "Web test page, ip is `hostname -I`." > /var/www/html/index.html[root@localhost ~]# systemctl start httpd.service
2.3 在Node04配置
2.3.1 安装Apache服务
[root@localhost ~]# yum install -y httpd
2.3.2 编辑默认主页
[root@localhost ~]# echo "Web test page, ip is `hostname -I`." > /var/www/html/index.html[root@localhost ~]# systemctl start httpd.service
2.4 在Node01上测试
[root@localhost ~]# curl 192.168.100.5
Web test page, ip is 192.168.100.5 .[root@localhost ~]# curl 192.168.100.6
Web test page, ip is 192.168.100.6 .
3、绑定VIP
3.1 在Node03上配置
[root@localhost ~]# ifconfig lo:200 192.168.100.200 netmask 255.255.255.255 up[root@localhost ~]# route add -host 192.168.100.200 dev lo
3.2 在Node04行配置
[root@localhost ~]# ifconfig lo:200 192.168.100.200 netmask 255.255.255.255 up[root@localhost ~]# route add -host 192.168.100.200 dev lo
4、ARP抑制
4.1 在Node03上配置
[root@localhost ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@localhost ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@localhost ~]# echo "1" > /proc/sys/net/ipv4/conf/ens33/arp_ignore
[root@localhost ~]# echo "2" > /proc/sys/net/ipv4/conf/ens33/arp_announce
4.2 在Node04行配置
[root@localhost ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@localhost ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@localhost ~]# echo "1" > /proc/sys/net/ipv4/conf/ens33/arp_ignore
[root@localhost ~]# echo "2" > /proc/sys/net/ipv4/conf/ens33/arp_announce
5、在LVS(Node02)上添加RS
[root@localhost ~]# ipvsadm -A -t 192.168.100.200:80 -s rr[root@localhost ~]# ipvsadm -a -t 192.168.100.200:80 -r 192.168.100.5:80 -g[root@localhost ~]# ipvsadm -a -t 192.168.100.200:80 -r 192.168.100.6:80 -g
6、在PC(Node01)上进行测试
[root@localhost ~]# for ((i=1;i<=6;i++)); do curl 192.168.100.200; doneWeb test page, ip is 192.168.100.6 .
Web test page, ip is 192.168.100.5 .
Web test page, ip is 192.168.100.6 .
Web test page, ip is 192.168.100.5 .
Web test page, ip is 192.168.100.6 .
Web test page, ip is 192.168.100.5 .
二、配置nginx负载均衡
1、部署环境
1.1 在Node03上配置
[root@localhost ~]# yum install -y httpd[root@localhost ~]# echo "Web test page, ip is `hostname -I`." > /var/www/html/index.html
1.2 在Node04上配置
[root@localhost ~]# yum install -y httpd[root@localhost ~]# echo "Web test page, ip is `hostname -I`." > /var/www/html/index.html
2、Node02 配置虚拟主机
2.1 编辑配置文件
[root@localhost ~]# cd /etc/nginx/conf.d/[root@localhost conf.d]# vim vhost.conf
server{listen 80;server_name www1.openlab.cn;location / {proxy_pass http://192.168.100.5;}
}server{listen 80;server_name www2.openlab.cn;location / {proxy_pass http://192.168.100.6;}
}
[root@localhost conf.d]# vim lb.conf
upstream www_pools {server 192.168.100.5:80 weight=1;server 192.168.100.6:80 weight=2;
}server {listen 80:server_name www.yunjisun.com;location / {proxy_pass http://www_server_pools;}
}
2.2 启动nginx
[root@localhost ~]# systemctl start nginx
3、PC端(Node01)测试
[root@localhost ~]# for ((i=1;i<=9;i++)); do curl http://www.yunjisuan.com; done