造价工程建设协会网站,手机建网站优帮云,大数据分析师,网站外链平台目录
1、基于 CentOS 7 构建 LVS-DR 群集。
2、配置nginx负载均衡。 1、基于 CentOS 7 构建 LVS-DR 群集。
1.部署LVS负载调度器
1安装配置工具
[rootnode6 ~]# yum install -y ipvsadm
2配置LVS虚拟IP#xff08;VIP地址#xff09;
[rootnode6 ~]# ifconfig ens…目录
1、基于 CentOS 7 构建 LVS-DR 群集。
2、配置nginx负载均衡。 1、基于 CentOS 7 构建 LVS-DR 群集。
1.部署LVS负载调度器
1安装配置工具
[rootnode6 ~]# yum install -y ipvsadm
2配置LVS虚拟IPVIP地址
[rootnode6 ~]# ifconfig ens33:200 192.168.111.200 netmask 255.255.255.255 up
3手工执行配置添加LVS服务并增加两台RS
[rootnode6 ~]# ipvsadm -A -t 192.168.111.200:80 -s rr
[rootnode6 ~]# ipvsadm -a -t 192.168.111.200:80 -r 192.168.111.7:80 -g
[rootnode6 ~]# ipvsadm -a -t 192.168.111.200:80 -r 192.168.111.8:80 -g
[rootnode6 ~]# ipvsadm -Ln # 显示内核中的虚拟服务规则
IP Virtual Server version 1.2.1 (size4096)
Prot LocalAddress:Port Scheduler Flags- RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.111.200:80 rr- 192.168.111.7:80 Route 1 0 0 - 192.168.111.8:80 Route 1 0 0 2.部署web服务器两台机器同时部署
1安装web服务器
[rootnode7 ~]# yum install -y httpd
2写网页文件
[rootnode7 ~]# echo web is hostname -I /var/www/html/index.html
[rootnode7 ~]# systemctl start httpd
3在客户端就行测试
[rootyx ~]# curl 192.168.111.7
web is 192.168.111.7
[rootyx ~]# curl 192.168.111.8
web is 192.168.111.8
4手工在RS端绑定VIP并且添加本机访问VIP的路由
[rootnode7 ~]# ifconfig lo:200 192.168.111.200 netmask 255.255.255.255 up
[rootnode7 ~]# route add -host 192.168.111.200 dev lo:200
[rootnode7 ~]# route -n # 查看路由
5手工在RS端抑制ARP响应调整内核参数关闭arp响应
echo 1 /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 /proc/sys/net/ipv4/conf/lo/arp_announce
echo 1 /proc/sys/net/ipv4/conf/ens33/arp_ignore
echo 2 /proc/sys/net/ipv4/conf/ens33/arp_announce另一种方法使用arptables实现抑制arp
[rootnode8 ~]# yum install -y arptables
[rootnode8 ~]# arptables -A INPUT -d 192.168.111.200 -j DROP
[rootnode8 ~]# arptables -A OUTPUT -s 192.168.111.200 -j mangle --mangle-ip-s 192.168.111.8
[rootnode8 ~]# arptables -L -n --line-number # 查看
# --line-number 显示行号
[rootnode8 ~]# arptables-save /etc/sysconfig/arptables
[rootnode8 ~]# systemctl enable --now arptables.service3.测试(在客户端进行测试)
[rootyx ~]# for ((i1;i6;i))docurl 192.168.111.200done
web is 192.168.111.8
web is 192.168.111.7
web is 192.168.111.8
web is 192.168.111.7
web is 192.168.111.8
web is 192.168.111.7
2、配置nginx负载均衡。
1.准备两台后端web服务器同时进行
# 把nginx的rpm包上传至服务器中然后进行安装
[rootnode7 ~]# yum install -y nginx
[rootnode7 ~]# echo web is hostname -I /usr/share/nginx/html/index.html
[rootnode7 ~]# systemctl start nginx2.负载均衡配置
[rootnode6 ~]# yum install -y nginx-1.22.0-1.el7.ngx.x86_64.rpm
[rootnode6 ~]# vim /etc/nginx/conf.d/vhost.conf
server {listen 80;server_name www.open.cn;location / {proxy_pass http://web_server;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}
}
upstream web_server {server 192.168.111.7;server 192.168.111.8;
}
[rootnode6 ~]# nginx -t
[rootnode6 ~]# systemctl start nginx3.测试
[rootyx ~]# vim /etc/hosts
192.168.111.6 www.open.cn
[rootyx ~]# for ((i1;i6;i)); do curl www.open.cn; done
web is 192.168.111.7
web is 192.168.111.8
web is 192.168.111.7
web is 192.168.111.7
web is 192.168.111.8
web is 192.168.111.7 或者在PC端修改主机域名C:\Windows\System32\drivers\etc/hosts 192.168.111.6 www.open.cn # 在浏览器上进行域名访问访问的内容刷新之后会进行不断的变化如下